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

Compare commits

..

2 Commits

Author SHA1 Message Date
T00thpick1
f3eb7fb17b Fix this 2013-06-25 18:23:27 -04:00
T00thpick1
39d6030e3e Try this jjacobson 2013-06-25 16:56:55 -04:00
596 changed files with 12751 additions and 17443 deletions

View File

@@ -7,100 +7,7 @@ Key:
! Change ! Change
- Removal - Removal
Version 1.4.08-dev Version 1.4.06-dev
+ Added the possibility to gain experience when using Fishing "Shake"
+ Added config options to disable various sound effects
+ Smelting now works with custom ores - add smelting XP value to blocks.yml, or it will default to 1/10th of normal XP.
+ Added automatic cleanup of backups folder.
+ Added bypass permission for finding Fishing traps
= Fixed bug with toggle commands not properly displaying the success message.
= Fixed IllegalArgumentException caused by an empty Fishing treasure category
= Fixed bug with Salvage not reading the config value for the anvil material.
= Fixed exploit where you could receive smelting XP for improper items
= Fixed bug where the Unbreaking enchantment was ignored when using "Super Breaker" or "Giga Drill Breaker"
= Fixed bug which prevented players from gaining Acrobatics XP when the setting 'Prevent_XP_After_Teleport' was set to false
= Fixed McMMOPlayerDisarmEvent reporting the skill level of the defending player, not the attacking player.
= Fixed bug where arrow retrieval was not properly detecting entities that already existed in the tracker
! Updated localization files
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 horses to the "Shake" ability
+ Added ability to summon horses via "Call of the Wild" using apples
+ Added XP gain to Taming for horses
+ Added new permission nodes to allow more control over Taming and "Call of the Wild"
+ Added new experience.yml config file! Moved all experience related settings from config.yml to experience.yml
+ Added support for EXPONENTIAL formula curves to experience.yml
+ Added new /mcconvert command to convert players levels and experience from one formula curve to another.
+ Added snow to Excavation blocks
+ Added new experience curve option. Cumulative curve, calculates experience needed for next level using power level.
+ Added extra settings to config.yml for "Call of the Wild" (Taming)
+ Added a 5 second cooldown after teleporting before Acrobatics XP can be earned. Plus a config option to disable
+ Added new API methods to ExperienceAPI to get a players rank on the leaderboards
+ Added new McMMOPlayerDeathPenaltyEvent, fired when a player dies and would lose levels
+ Added new McMMOPlayerLevelChangeEvent, fired when a players level changes
+ Added new McMMOPlayerLevelDownEvent, fired when a player loses levels
+ 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 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.
= Fixed bug which allowed players to bypass fishing's exploit prevention
= Fixed bug where FakeEntityDamageByEntityEvent wasn't being fired
= Fixed bug with "Skull Splitter" not finding the locale string
= Fixed issue where locale strings could cause the scoreboard header to be longer than 16 characters.
= Fixed a bug with "Beast Lore" when the entity had no owner but was tamed.
= Fixed a bug where AbilityDeactivateEvent would throw an error if the player logged out before his ability ran out.
= Fixed a bug where LevelUpEvent would be called for an offline player.
= Fixed a bug where teleport location was never reset if warmup was set to 0 for "Chimaera Wing".
= Fixed a bug where the "Dodge" DamageModifier wasn't being read from advanced.yml
= 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 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 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 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 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.
! Nerfed Fishing "Master Angler" (removed skill level based bonus) and also made the modifiers configurable
! 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 Swords "Counter Attack" ability from passive to active. Blocking is required to activate.
! Hardcore modes can now be toggled for each skill individually
! Vampirism can now be enabled without having Skill Death Penalty enabled
! Admin and Party chat prefixes are now customizable
! 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 partial name matcher
! Improved update checker
! Updated localization files
! 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)
! 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
- 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
Version 1.4.06
+ Added "Ice Fishing" ability to Fishing + Added "Ice Fishing" ability to Fishing
+ Added global scoreboards to track skill rankings (display using /mctop) + Added global scoreboards to track skill rankings (display using /mctop)
+ Added per-player scoreboard displays for the /inspect, /mcrank, /mcstats, and /<skillname> commands + Added per-player scoreboard displays for the /inspect, /mcrank, /mcstats, and /<skillname> commands
@@ -122,9 +29,6 @@ Version 1.4.06
+ Added information about /party itemshare and /party expshare to the party help page + Added information about /party itemshare and /party expshare to the party help page
+ Added option to use scoreboards for power level display instead of Spout. + Added option to use scoreboards for power level display instead of Spout.
+ Added permission node to prevent inspecting hidden players + Added permission node to prevent inspecting hidden players
+ Added SQL to Flatfile database conversion
+ Added ability to use custom database managers and convert to/from them
= Fixed bug which could cause the server to hang for a minute when checking for updates. (Thanks to Riking)
= Fixed bug where spawned arrows could throw ArrayIndexOutOfBoundsException = Fixed bug where spawned arrows could throw ArrayIndexOutOfBoundsException
= Fixed bug where custom Spout titles were overwritten by mcMMO. = Fixed bug where custom Spout titles were overwritten by mcMMO.
= Fixed bug where Nether Quartz wasn't included in Smelting or item sharing = Fixed bug where Nether Quartz wasn't included in Smelting or item sharing
@@ -148,8 +52,6 @@ Version 1.4.06
= Fixed bug where the chance of a successful Gracefull Roll was twice as high as displayed = Fixed bug where the chance of a successful Gracefull Roll was twice as high as displayed
= Fixed bug where lucky perks where not working = Fixed bug where lucky perks where not working
= Fixed bug with Ice Fishing on a single block of ice = Fixed bug with Ice Fishing on a single block of ice
= Fixed bug with Ice Fishing which allowed players to break ice in protected areas
= Fixed a small bug with mob healthbars and bosses, such as EnderDragons and Withers
! Changed Spout notification tiers to be stored in SpoutConfig instead of AdvancedConfig ! Changed Spout notification tiers to be stored in SpoutConfig instead of AdvancedConfig
! Changed Berserk to add items to inventory rather than denying pickup ! Changed Berserk to add items to inventory rather than denying pickup
! Changed Call of the Wild, newly summoned pet's will have a custom name. (added permission node to disable this) ! Changed Call of the Wild, newly summoned pet's will have a custom name. (added permission node to disable this)

View File

@@ -2,10 +2,12 @@
## 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. mcMMO takes core Minecraft game mechanics and expands them to add an extensive RPG experience, the goal of the project has always been a quality RPG experience. Everything in mcMMO is carefully thought out and is constantly improving. mcMMO adds eleven skills to train in and level in, while also offering a high level of customization for server admins. There are countless features, including custom sounds, graphical elements, and more added when running mcMMO in conjunction with Spout. I carefully read feedback and evaluate the mechanics of mcMMO in every update to provide an ever-evolving experience.
If you want an original RPG experience like no other mod out there, mcMMO is for you.
## About the Team ## About the Team
@@ -29,18 +31,17 @@ 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
mcMMO uses Maven 3 to manage dependancies, packaging, and shading of necessary classes; Maven 3 is required to compile mcMMO. mcMMO uses Maven 3 to manage dependancies, packaging, and shading of necessary classes; Maven 3 is required to compile mcMMO.
The typical command used to build mcMMO is: `mvn clean package install` The typical command used to build mcMMO is: mvn clean package install
Required Libraries: Required Libraries:
* Spout API
* JUnit * JUnit
* EMetrics * Metrics
* Bukkit * Bukkit
http://dev.bukkit.org/server-mods/mcmmo for more up to date information. http://dev.bukkit.org/server-mods/mcmmo for more up to date information.

View File

@@ -1,11 +1,11 @@
# #
# Repair configuration
# Last updated on ${project.version}-b${BUILD_NUMBER}
#
# Any file named repair.*.yml in the mcmmmo folder will be loaded as a repair config # Any file named repair.*.yml in the mcmmmo folder will be loaded as a repair config
# All repair configs have a main section titled "Repairables" # All repair configs have a main section titled "Repairables"
# Afterwards, all sub-items are considered a Repairable to be loaded. The names of each subitem should be the exact material name. # Afterwards, all sub-items are considered a Repairable to be loaded
# The bare minimum of a Repairable is that it have a RepairMaterial and a MaximumDurability # The bare minimum of a Repairable is that it have an ItemId, a RepairMaterialId, and a MaximumDurability
#
# ItemId: This is the id of the item to be repairable.
## This is required to be set.
# #
# ItemType: This is the type of item to be repaired, this is only important to permissions. # ItemType: This is the type of item to be repaired, this is only important to permissions.
## Valid values are ARMOR, TOOL, and OTHER. ## Valid values are ARMOR, TOOL, and OTHER.
@@ -15,7 +15,7 @@
## Valid values are STRING, LEATHER, WOOD, STONE, IRON, GOLD, DIAMOND, and OTHER ## Valid values are STRING, LEATHER, WOOD, STONE, IRON, GOLD, DIAMOND, and OTHER
## This defaults to OTHER. ## This defaults to OTHER.
# #
# RepairMaterial: This is the material name of the item used to repair this repairable. # RepairMaterialId: This is the id of the item used to repair this repairable.
## This is required to be set. ## This is required to be set.
# #
# RepairMaterialMetadata: This is the metadata of the item used to repair this repairable. # RepairMaterialMetadata: This is the metadata of the item used to repair this repairable.
@@ -26,7 +26,7 @@
## This is required to be set. ## This is required to be set.
# #
# MinimumLevel: This is the minimum repair level needed to repair this item. # MinimumLevel: This is the minimum repair level needed to repair this item.
## Valid values are => 0 ## Valid values are > 0
## This defaults to 0 ## This defaults to 0
# #
# MinimumQuantity: This is the minimum number of items needed to repair this item ignoring all other repair bonuses. # MinimumQuantity: This is the minimum number of items needed to repair this item ignoring all other repair bonuses.
@@ -42,19 +42,32 @@
# #
### ###
Repairables: Repairables:
# ChainHelmet:
# Chainmail repairables ItemId: 302
### ItemType: ARMOR
# Armor RepairMaterialId: 51
CHAINMAIL_HELMET: MaximumDurability: 165
RepairMaterial: FIRE MinimumQuantity: 5
XpMultiplier: 2 XpMultiplier: 2
CHAINMAIL_CHESTPLATE: ChainChest:
RepairMaterial: FIRE ItemId: 303
ItemType: ARMOR
RepairMaterialId: 51
MaximumDurability: 240
MinimumQuantity: 8
XpMultiplier: 2 XpMultiplier: 2
CHAINMAIL_LEGGINGS: ChainLegs:
RepairMaterial: FIRE ItemId: 304
ItemType: ARMOR
RepairMaterialId: 51
MaximumDurability: 225
MinimumQuantity: 7
XpMultiplier: 2 XpMultiplier: 2
CHAINMAIL_BOOTS: ChainBoots:
RepairMaterial: FIRE ItemId: 305
ItemType: ARMOR
RepairMaterialId: 51
RepairMaterialMetadata: -1
MaximumDurability: 195
MinimumQuantity: 4
XpMultiplier: 2 XpMultiplier: 2

59
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.06-dev6</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>
@@ -22,6 +22,38 @@
<include>.jenkins</include> <include>.jenkins</include>
</includes> </includes>
</resource> </resource>
<resource>
<targetPath>resources</targetPath>
<filtering>false</filtering>
<directory>${basedir}/src/main/resources/xpbar/</directory>
<includes>
<include>xpbar*.png</include>
</includes>
</resource>
<resource>
<targetPath>resources</targetPath>
<filtering>false</filtering>
<directory>${basedir}/src/main/resources/healthbar/</directory>
<includes>
<include>health*.png</include>
</includes>
</resource>
<resource>
<targetPath>resources</targetPath>
<filtering>false</filtering>
<directory>${basedir}/src/main/resources/skillicon/</directory>
<includes>
<include>*.png</include>
</includes>
</resource>
<resource>
<targetPath>resources</targetPath>
<filtering>false</filtering>
<directory>${basedir}/src/main/resources/sound/</directory>
<includes>
<include>*.wav</include>
</includes>
</resource>
<resource> <resource>
<targetPath>com/gmail/nossr50/locale</targetPath> <targetPath>com/gmail/nossr50/locale</targetPath>
<filtering>true</filtering> <filtering>true</filtering>
@@ -30,14 +62,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>
@@ -108,6 +132,10 @@
<id>bukkit-repo</id> <id>bukkit-repo</id>
<url>http://repo.bukkit.org/content/groups/public/</url> <url>http://repo.bukkit.org/content/groups/public/</url>
</repository> </repository>
<repository>
<id>spout-repo</id>
<url>http://nexus.spout.org/content/groups/public/</url>
</repository>
<repository> <repository>
<id>Plugin MetricsExtension</id> <id>Plugin MetricsExtension</id>
<url>http://repo.turt2live.com</url> <url>http://repo.turt2live.com</url>
@@ -121,6 +149,13 @@
<type>jar</type> <type>jar</type>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>org.getspout</groupId>
<artifactId>spoutplugin</artifactId>
<version>LATEST</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit-dep</artifactId> <artifactId>junit-dep</artifactId>
@@ -130,7 +165,7 @@
<dependency> <dependency>
<groupId>com.turt2live.metrics</groupId> <groupId>com.turt2live.metrics</groupId>
<artifactId>MetricsExtension</artifactId> <artifactId>MetricsExtension</artifactId>
<version>0.0.5-SNAPSHOT</version> <version>0.0.4-SNAPSHOT</version>
</dependency> </dependency>
</dependencies> </dependencies>
<distributionManagement> <distributionManagement>
@@ -143,7 +178,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

@@ -50,34 +50,34 @@ public final class AbilityAPI {
} }
public static void resetCooldowns(Player player) { public static void resetCooldowns(Player player) {
UserManager.getPlayer(player).resetCooldowns(); UserManager.getPlayer(player).getProfile().resetCooldowns();
} }
public static void setBerserkCooldown(Player player, long cooldown) { public static void setBerserkCooldown(Player player, long cooldown) {
UserManager.getPlayer(player).setAbilityDATS(AbilityType.BERSERK, cooldown); UserManager.getPlayer(player).getProfile().setSkillDATS(AbilityType.BERSERK, cooldown);
} }
public static void setGigaDrillBreakerCooldown(Player player, long cooldown) { public static void setGigaDrillBreakerCooldown(Player player, long cooldown) {
UserManager.getPlayer(player).setAbilityDATS(AbilityType.GIGA_DRILL_BREAKER, cooldown); UserManager.getPlayer(player).getProfile().setSkillDATS(AbilityType.GIGA_DRILL_BREAKER, cooldown);
} }
public static void setGreenTerraCooldown(Player player, long cooldown) { public static void setGreenTerraCooldown(Player player, long cooldown) {
UserManager.getPlayer(player).setAbilityDATS(AbilityType.GREEN_TERRA, cooldown); UserManager.getPlayer(player).getProfile().setSkillDATS(AbilityType.GREEN_TERRA, cooldown);
} }
public static void setSerratedStrikesCooldown(Player player, long cooldown) { public static void setSerratedStrikesCooldown(Player player, long cooldown) {
UserManager.getPlayer(player).setAbilityDATS(AbilityType.SERRATED_STRIKES, cooldown); UserManager.getPlayer(player).getProfile().setSkillDATS(AbilityType.SERRATED_STRIKES, cooldown);
} }
public static void setSkullSplitterCooldown(Player player, long cooldown) { public static void setSkullSplitterCooldown(Player player, long cooldown) {
UserManager.getPlayer(player).setAbilityDATS(AbilityType.SKULL_SPLITTER, cooldown); UserManager.getPlayer(player).getProfile().setSkillDATS(AbilityType.SKULL_SPLITTER, cooldown);
} }
public static void setSuperBreakerCooldown(Player player, long cooldown) { public static void setSuperBreakerCooldown(Player player, long cooldown) {
UserManager.getPlayer(player).setAbilityDATS(AbilityType.SUPER_BREAKER, cooldown); UserManager.getPlayer(player).getProfile().setSkillDATS(AbilityType.SUPER_BREAKER, cooldown);
} }
public static void setTreeFellerCooldown(Player player, long cooldown) { public static void setTreeFellerCooldown(Player player, long cooldown) {
UserManager.getPlayer(player).setAbilityDATS(AbilityType.TREE_FELLER, cooldown); UserManager.getPlayer(player).getProfile().setSkillDATS(AbilityType.TREE_FELLER, cooldown);
} }
} }

View File

@@ -5,8 +5,8 @@ import org.bukkit.plugin.Plugin;
import com.gmail.nossr50.chat.ChatManager; import com.gmail.nossr50.chat.ChatManager;
import com.gmail.nossr50.chat.ChatManagerFactory; import com.gmail.nossr50.chat.ChatManagerFactory;
import com.gmail.nossr50.chat.ChatMode;
import com.gmail.nossr50.chat.PartyChatManager; import com.gmail.nossr50.chat.PartyChatManager;
import com.gmail.nossr50.datatypes.chat.ChatMode;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
@@ -76,7 +76,7 @@ public final class ChatAPI {
* @return true if the player is using party chat, false otherwise * @return true if the player is using party chat, false otherwise
*/ */
public static boolean isUsingPartyChat(Player player) { public static boolean isUsingPartyChat(Player player) {
return UserManager.getPlayer(player).isChatEnabled(ChatMode.PARTY); return UserManager.getPlayer(player).getPartyChatMode();
} }
/** /**
@@ -86,7 +86,7 @@ public final class ChatAPI {
* @return true if the player is using party chat, false otherwise * @return true if the player is using party chat, false otherwise
*/ */
public static boolean isUsingPartyChat(String playerName) { public static boolean isUsingPartyChat(String playerName) {
return UserManager.getPlayer(playerName).isChatEnabled(ChatMode.PARTY); return UserManager.getPlayer(playerName).getPartyChatMode();
} }
/** /**
@@ -96,7 +96,7 @@ public final class ChatAPI {
* @return true if the player is using admin chat, false otherwise * @return true if the player is using admin chat, false otherwise
*/ */
public static boolean isUsingAdminChat(Player player) { public static boolean isUsingAdminChat(Player player) {
return UserManager.getPlayer(player).isChatEnabled(ChatMode.ADMIN); return UserManager.getPlayer(player).getAdminChatMode();
} }
/** /**
@@ -106,7 +106,7 @@ public final class ChatAPI {
* @return true if the player is using admin chat, false otherwise * @return true if the player is using admin chat, false otherwise
*/ */
public static boolean isUsingAdminChat(String playerName) { public static boolean isUsingAdminChat(String playerName) {
return UserManager.getPlayer(playerName).isChatEnabled(ChatMode.ADMIN); return UserManager.getPlayer(playerName).getAdminChatMode();
} }
/** /**
@@ -115,7 +115,7 @@ public final class ChatAPI {
* @param player The player to toggle party chat on. * @param player The player to toggle party chat on.
*/ */
public static void togglePartyChat(Player player) { public static void togglePartyChat(Player player) {
UserManager.getPlayer(player).toggleChat(ChatMode.PARTY); UserManager.getPlayer(player).togglePartyChat();
} }
/** /**
@@ -124,7 +124,7 @@ public final class ChatAPI {
* @param playerName The name of the player to toggle party chat on. * @param playerName The name of the player to toggle party chat on.
*/ */
public static void togglePartyChat(String playerName) { public static void togglePartyChat(String playerName) {
UserManager.getPlayer(playerName).toggleChat(ChatMode.PARTY); UserManager.getPlayer(playerName).togglePartyChat();
} }
/** /**
@@ -133,7 +133,7 @@ public final class ChatAPI {
* @param player The player to toggle admin chat on. * @param player The player to toggle admin chat on.
*/ */
public static void toggleAdminChat(Player player) { public static void toggleAdminChat(Player player) {
UserManager.getPlayer(player).toggleChat(ChatMode.ADMIN); UserManager.getPlayer(player).toggleAdminChat();
} }
/** /**
@@ -142,7 +142,7 @@ public final class ChatAPI {
* @param playerName The name of the player to toggle party chat on. * @param playerName The name of the player to toggle party chat on.
*/ */
public static void toggleAdminChat(String playerName) { public static void toggleAdminChat(String playerName) {
UserManager.getPlayer(playerName).toggleChat(ChatMode.ADMIN); UserManager.getPlayer(playerName).toggleAdminChat();
} }
private static ChatManager getPartyChatManager(Plugin plugin, String party) { private static ChatManager getPartyChatManager(Plugin plugin, String party) {

View File

@@ -4,11 +4,9 @@ import java.util.Set;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.api.exceptions.InvalidPlayerException; import com.gmail.nossr50.api.exceptions.InvalidPlayerException;
import com.gmail.nossr50.api.exceptions.InvalidSkillException; import com.gmail.nossr50.api.exceptions.InvalidSkillException;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.experience.ExperienceConfig;
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.skills.child.FamilyTree; import com.gmail.nossr50.skills.child.FamilyTree;
@@ -48,11 +46,6 @@ public final class ExperienceAPI {
return !skill.isChildSkill(); return !skill.isChildSkill();
} }
@Deprecated
public static void addRawXP(Player player, String skillType, int XP) {
addRawXP(player, skillType, (float) XP);
}
/** /**
* Adds raw XP to the player. * Adds raw XP to the player.
* </br> * </br>
@@ -64,15 +57,10 @@ public final class ExperienceAPI {
* *
* @throws InvalidSkillException if the given skill is not valid * @throws InvalidSkillException if the given skill is not valid
*/ */
public static void addRawXP(Player player, String skillType, float XP) { public static void addRawXP(Player player, String skillType, int XP) {
UserManager.getPlayer(player).applyXpGain(getSkillType(skillType), XP); UserManager.getPlayer(player).applyXpGain(getSkillType(skillType), XP);
} }
@Deprecated
public static void addRawXPOffline(String playerName, String skillType, int XP) {
addRawXPOffline(playerName, skillType, (float) XP);
}
/** /**
* Adds raw XP to an offline player. * Adds raw XP to an offline player.
* </br> * </br>
@@ -85,8 +73,8 @@ public final class ExperienceAPI {
* @throws InvalidSkillException if the given skill is not valid * @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database * @throws InvalidPlayerException if the given player does not exist in the database
*/ */
public static void addRawXPOffline(String playerName, String skillType, float XP) { public static void addRawXPOffline(String playerName, String skillType, int XP) {
addOfflineXP(playerName, getSkillType(skillType), (int) Math.floor(XP)); addOfflineXP(playerName, getSkillType(skillType), XP);
} }
/** /**
@@ -101,7 +89,7 @@ public final class ExperienceAPI {
* @throws InvalidSkillException if the given skill is not valid * @throws InvalidSkillException if the given skill is not valid
*/ */
public static void addMultipliedXP(Player player, String skillType, int XP) { public static void addMultipliedXP(Player player, String skillType, int XP) {
UserManager.getPlayer(player).applyXpGain(getSkillType(skillType), (int) (XP * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier())); UserManager.getPlayer(player).applyXpGain(getSkillType(skillType), (int) (XP * Config.getInstance().getExperienceGainsGlobalMultiplier()));
} }
/** /**
@@ -117,7 +105,7 @@ public final class ExperienceAPI {
* @throws InvalidPlayerException if the given player does not exist in the database * @throws InvalidPlayerException if the given player does not exist in the database
*/ */
public static void addMultipliedXPOffline(String playerName, String skillType, int XP) { public static void addMultipliedXPOffline(String playerName, String skillType, int XP) {
addOfflineXP(playerName, getSkillType(skillType), (int) (XP * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier())); addOfflineXP(playerName, getSkillType(skillType), (int) (XP * Config.getInstance().getExperienceGainsGlobalMultiplier()));
} }
/** /**
@@ -134,7 +122,7 @@ public final class ExperienceAPI {
public static void addModifiedXP(Player player, String skillType, int XP) { public static void addModifiedXP(Player player, String skillType, int XP) {
SkillType skill = getSkillType(skillType); SkillType skill = getSkillType(skillType);
UserManager.getPlayer(player).applyXpGain(skill, (int) (XP / skill.getXpModifier() * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier())); UserManager.getPlayer(player).applyXpGain(skill, (int) (XP / skill.getXpModifier() * Config.getInstance().getExperienceGainsGlobalMultiplier()));
} }
/** /**
@@ -152,7 +140,7 @@ public final class ExperienceAPI {
public static void addModifiedXPOffline(String playerName, String skillType, int XP) { public static void addModifiedXPOffline(String playerName, String skillType, int XP) {
SkillType skill = getSkillType(skillType); SkillType skill = getSkillType(skillType);
addOfflineXP(playerName, skill, (int) (XP / skill.getXpModifier() * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier())); addOfflineXP(playerName, skill, (int) (XP / skill.getXpModifier() * Config.getInstance().getExperienceGainsGlobalMultiplier()));
} }
/** /**
@@ -184,7 +172,7 @@ public final class ExperienceAPI {
* @throws UnsupportedOperationException if the given skill is a child skill * @throws UnsupportedOperationException if the given skill is a child skill
*/ */
public static int getXP(Player player, String skillType) { public static int getXP(Player player, String skillType) {
return UserManager.getPlayer(player).getSkillXpLevel(getNonChildSkillType(skillType)); return UserManager.getPlayer(player).getProfile().getSkillXpLevel(getNonChildSkillType(skillType));
} }
/** /**
@@ -217,7 +205,7 @@ public final class ExperienceAPI {
* @throws UnsupportedOperationException if the given skill is a child skill * @throws UnsupportedOperationException if the given skill is a child skill
*/ */
public static float getXPRaw(Player player, String skillType) { public static float getXPRaw(Player player, String skillType) {
return UserManager.getPlayer(player).getSkillXpLevelRaw(getNonChildSkillType(skillType)); return UserManager.getPlayer(player).getProfile().getSkillXpLevelRaw(getNonChildSkillType(skillType));
} }
/** /**
@@ -250,7 +238,7 @@ public final class ExperienceAPI {
* @throws UnsupportedOperationException if the given skill is a child skill * @throws UnsupportedOperationException if the given skill is a child skill
*/ */
public static int getXPToNextLevel(Player player, String skillType) { public static int getXPToNextLevel(Player player, String skillType) {
return UserManager.getPlayer(player).getXpToLevel(getNonChildSkillType(skillType)); return UserManager.getPlayer(player).getProfile().getXpToLevel(getNonChildSkillType(skillType));
} }
/** /**
@@ -323,7 +311,7 @@ public final class ExperienceAPI {
* @throws InvalidSkillException if the given skill is not valid * @throws InvalidSkillException if the given skill is not valid
*/ */
public static void addLevel(Player player, String skillType, int levels) { public static void addLevel(Player player, String skillType, int levels) {
UserManager.getPlayer(player).addLevels(getSkillType(skillType), levels); UserManager.getPlayer(player).getProfile().addLevels(getSkillType(skillType), levels);
} }
/** /**
@@ -369,7 +357,7 @@ public final class ExperienceAPI {
* @throws InvalidSkillException if the given skill is not valid * @throws InvalidSkillException if the given skill is not valid
*/ */
public static int getLevel(Player player, String skillType) { public static int getLevel(Player player, String skillType) {
return UserManager.getPlayer(player).getSkillLevel(getSkillType(skillType)); return UserManager.getPlayer(player).getProfile().getSkillLevel(getSkillType(skillType));
} }
/** /**
@@ -414,7 +402,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);
} }
@@ -446,40 +434,6 @@ public final class ExperienceAPI {
return Config.getInstance().getPowerLevelCap(); return Config.getInstance().getPowerLevelCap();
} }
/**
* Get the position on the leaderboard of a player.
* </br>
* This function is designed for API usage.
*
* @param playerName The name of the player to check
* @param skillType The skill to check
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
* @throws UnsupportedOperationException if the given skill is a child skill
*
* @return the position on the leaderboard
*/
public static int getPlayerRankSkill(String playerName, String skillType) {
return mcMMO.getDatabaseManager().readRank(getOfflineProfile(playerName).getPlayerName()).get(getNonChildSkillType(skillType));
}
/**
* Get the position on the power level leaderboard of a player.
* </br>
* This function is designed for API usage.
*
* @param playerName The name of the player to check
*
* @throws InvalidPlayerException if the given player does not exist in the database
*
* @return the position on the power level leaderboard
*/
public static int getPlayerRankOverall(String playerName) {
return mcMMO.getDatabaseManager().readRank(getOfflineProfile(playerName).getPlayerName()).get(null);
}
/** /**
* Sets the level of a player in a specific skill type. * Sets the level of a player in a specific skill type.
* </br> * </br>
@@ -492,7 +446,7 @@ public final class ExperienceAPI {
* @throws InvalidSkillException if the given skill is not valid * @throws InvalidSkillException if the given skill is not valid
*/ */
public static void setLevel(Player player, String skillType, int skillLevel) { public static void setLevel(Player player, String skillType, int skillLevel) {
UserManager.getPlayer(player).modifySkill(getSkillType(skillType), skillLevel); UserManager.getPlayer(player).getProfile().modifySkill(getSkillType(skillType), skillLevel);
} }
/** /**
@@ -524,7 +478,7 @@ public final class ExperienceAPI {
* @throws UnsupportedOperationException if the given skill is a child skill * @throws UnsupportedOperationException if the given skill is a child skill
*/ */
public static void setXP(Player player, String skillType, int newValue) { public static void setXP(Player player, String skillType, int newValue) {
UserManager.getPlayer(player).setSkillXpLevel(getNonChildSkillType(skillType), newValue); UserManager.getPlayer(player).getProfile().setSkillXpLevel(getNonChildSkillType(skillType), newValue);
} }
/** /**
@@ -557,7 +511,7 @@ public final class ExperienceAPI {
* @throws UnsupportedOperationException if the given skill is a child skill * @throws UnsupportedOperationException if the given skill is a child skill
*/ */
public static void removeXP(Player player, String skillType, int xp) { public static void removeXP(Player player, String skillType, int xp) {
UserManager.getPlayer(player).removeXp(getNonChildSkillType(skillType), xp); UserManager.getPlayer(player).getProfile().removeXp(getNonChildSkillType(skillType), xp);
} }
/** /**
@@ -582,12 +536,23 @@ public final class ExperienceAPI {
private static void addOfflineXP(String playerName, SkillType skill, int XP) { private static void addOfflineXP(String playerName, SkillType skill, int XP) {
PlayerProfile profile = getOfflineProfile(playerName); PlayerProfile profile = getOfflineProfile(playerName);
profile.addXp(skill, XP); if (skill.isChildSkill()) {
Set<SkillType> parentSkills = FamilyTree.getParents(skill);
for (SkillType parentSkill : parentSkills) {
profile.setSkillXpLevel(parentSkill, profile.getSkillLevel(parentSkill) + (XP / parentSkills.size()));
}
profile.save();
return;
}
profile.setSkillXpLevel(skill, profile.getSkillXpLevel(skill) + XP);
profile.save(); profile.save();
} }
private static PlayerProfile getOfflineProfile(String playerName) { private static PlayerProfile getOfflineProfile(String playerName) {
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(playerName, false); PlayerProfile profile = new PlayerProfile(playerName, false);
if (!profile.isLoaded()) { if (!profile.isLoaded()) {
throw new InvalidPlayerException(); throw new InvalidPlayerException();

View File

@@ -77,12 +77,13 @@ public final class PartyAPI {
*/ */
public static void addToParty(Player player, String partyName) { public static void addToParty(Player player, String partyName) {
Party party = PartyManager.getParty(partyName); Party party = PartyManager.getParty(partyName);
String playerName = player.getName();
if (party == null) { if (party == null) {
party = new Party(player.getName(), partyName); party = new Party(playerName, partyName);
} }
PartyManager.addToParty(UserManager.getPlayer(player), party); PartyManager.addToParty(playerName, UserManager.getPlayer(player), party);
} }
/** /**
@@ -93,7 +94,7 @@ public final class PartyAPI {
* @param player The player to remove * @param player The player to remove
*/ */
public static void removeFromParty(Player player) { public static void removeFromParty(Player player) {
PartyManager.removeFromParty(UserManager.getPlayer(player)); PartyManager.removeFromParty(player, UserManager.getPlayer(player).getParty());
} }
/** /**

View File

@@ -0,0 +1,29 @@
package com.gmail.nossr50.api;
import org.bukkit.entity.Player;
import com.gmail.nossr50.config.spout.SpoutConfig;
import com.gmail.nossr50.datatypes.spout.huds.HudType;
import com.gmail.nossr50.util.player.UserManager;
public class SpoutHudAPI {
private SpoutHudAPI() {}
/**
* Disable the mcMMO XP bar for a player.
* </br>
* This function is designed for API usage.
*/
public static void disableXpBar(Player player) {
UserManager.getPlayer(player).getProfile().setHudType(HudType.DISABLED);
}
/**
* Disable the mcMMO XP bar for the server.
* </br>
* This function is designed for API usage.
*/
public static void disableXpBar() {
SpoutConfig.getInstance().setXPBarEnabled(false);
}
}

View File

@@ -0,0 +1,53 @@
package com.gmail.nossr50.api;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.datatypes.skills.ToolType;
public final class SpoutToolsAPI {
public static final List<ItemStack> spoutSwords = new ArrayList<ItemStack>();
public static final List<ItemStack> spoutAxes = new ArrayList<ItemStack>();
public static final List<ItemStack> spoutPickaxes = new ArrayList<ItemStack>();
public static final List<ItemStack> spoutHoes = new ArrayList<ItemStack>();
public static final List<ItemStack> spoutShovels = new ArrayList<ItemStack>();
private SpoutToolsAPI() {}
/**
* Add a custom Spout tool to mcMMO for XP gain & ability use.
* </br>
* This function is designed for API usage.
*
* @param spoutTool The tool to add
* @param type The type of tool to add
*/
public static void addCustomTool(ItemStack spoutTool, ToolType type) {
switch (type) {
case AXE:
spoutAxes.add(spoutTool);
break;
case HOE:
spoutHoes.add(spoutTool);
break;
case PICKAXE:
spoutPickaxes.add(spoutTool);
break;
case SHOVEL:
spoutShovels.add(spoutTool);
break;
case SWORD:
spoutSwords.add(spoutTool);
break;
default:
break;
}
}
}

View File

@@ -7,7 +7,7 @@ import com.gmail.nossr50.events.chat.McMMOAdminChatEvent;
public class AdminChatManager extends ChatManager { public class AdminChatManager extends ChatManager {
protected AdminChatManager(Plugin plugin) { protected AdminChatManager(Plugin plugin) {
super(plugin, Config.getInstance().getAdminDisplayNames(), Config.getInstance().getAdminChatPrefix()); super(plugin, Config.getInstance().getAdminDisplayNames(), "Commands.AdminChat.Prefix");
} }
@Override @Override

View File

@@ -11,7 +11,6 @@ public abstract class ChatManager {
protected boolean useDisplayNames; protected boolean useDisplayNames;
protected String chatPrefix; protected String chatPrefix;
protected String senderName;
protected String displayName; protected String displayName;
protected String message; protected String message;
@@ -28,9 +27,8 @@ public abstract class ChatManager {
return; return;
} }
senderName = event.getSender(); displayName = useDisplayNames ? event.getDisplayName() : event.getSender();
displayName = useDisplayNames ? event.getDisplayName() : senderName; message = LocaleLoader.getString(chatPrefix, displayName) + event.getMessage();
message = LocaleLoader.formatString(chatPrefix, displayName) + " " + event.getMessage();
sendMessage(); sendMessage();
} }

View File

@@ -4,8 +4,6 @@ import java.util.HashMap;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import com.gmail.nossr50.datatypes.chat.ChatMode;
public class ChatManagerFactory { public class ChatManagerFactory {
private static final HashMap<Plugin, AdminChatManager> adminChatManagers = new HashMap<Plugin, AdminChatManager>(); private static final HashMap<Plugin, AdminChatManager> adminChatManagers = new HashMap<Plugin, AdminChatManager>();
private static final HashMap<Plugin, PartyChatManager> partyChatManagers = new HashMap<Plugin, PartyChatManager>(); private static final HashMap<Plugin, PartyChatManager> partyChatManagers = new HashMap<Plugin, PartyChatManager>();

View File

@@ -0,0 +1,70 @@
package com.gmail.nossr50.chat;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
public enum ChatMode {
ADMIN(LocaleLoader.getString("Commands.AdminChat.On"), LocaleLoader.getString("Commands.AdminChat.Off")),
PARTY(LocaleLoader.getString("Commands.Party.Chat.On"), LocaleLoader.getString("Commands.Party.Chat.Off"));
private String enabledMessage;
private String disabledMessage;
private ChatMode(String enabledMessage, String disabledMessage) {
this.enabledMessage = enabledMessage;
this.disabledMessage = disabledMessage;
}
public boolean isEnabled(McMMOPlayer mcMMOPlayer) {
switch (this) {
case ADMIN:
return mcMMOPlayer.getAdminChatMode();
case PARTY:
return mcMMOPlayer.getPartyChatMode();
default:
return false;
}
}
public void disable(McMMOPlayer mcMMOPlayer) {
switch (this) {
case ADMIN:
mcMMOPlayer.setAdminChat(false);
return;
case PARTY:
mcMMOPlayer.setPartyChat(false);
return;
default:
return;
}
}
public void enable(McMMOPlayer mcMMOPlayer) {
switch (this) {
case ADMIN:
mcMMOPlayer.setAdminChat(true);
mcMMOPlayer.setPartyChat(false);
return;
case PARTY:
mcMMOPlayer.setPartyChat(true);
mcMMOPlayer.setAdminChat(false);
return;
default:
return;
}
}
public String getEnabledMessage() {
return enabledMessage;
}
public String getDisabledMessage() {
return disabledMessage;
}
}

View File

@@ -1,6 +1,5 @@
package com.gmail.nossr50.chat; package com.gmail.nossr50.chat;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
@@ -12,7 +11,7 @@ public class PartyChatManager extends ChatManager {
private Party party; private Party party;
protected PartyChatManager(Plugin plugin) { protected PartyChatManager(Plugin plugin) {
super(plugin, Config.getInstance().getPartyDisplayNames(), Config.getInstance().getPartyChatPrefix()); super(plugin, Config.getInstance().getPartyDisplayNames(), "Commands.Party.Chat.Prefix");
} }
public void setParty(Party party) { public void setParty(Party party) {
@@ -26,10 +25,6 @@ public class PartyChatManager extends ChatManager {
@Override @Override
protected void sendMessage() { protected void sendMessage() {
if (Config.getInstance().getPartyChatColorLeaderName() && senderName.equalsIgnoreCase(party.getLeader())) {
message = message.replaceFirst(displayName, ChatColor.GOLD + displayName + ChatColor.RESET);
}
for (Player member : party.getOnlineMembers()) { for (Player member : party.getOnlineMembers()) {
member.sendMessage(message); member.sendMessage(message);
} }

View File

@@ -7,14 +7,13 @@ import java.util.Set;
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.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
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 {
@@ -31,7 +30,7 @@ public class KrakenCommand implements TabExecutor {
return true; return true;
} }
UserManager.getPlayer(sender.getName()).getFishingManager().unleashTheKraken(); UserManager.getPlayer((Player) sender).getFishingManager().unleashTheKraken();
return true; return true;
case 1: case 1:
@@ -40,10 +39,9 @@ public class KrakenCommand implements TabExecutor {
return true; return true;
} }
String playerName = Misc.getMatchedPlayerName(args[0]); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(args[0]);
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(playerName);
if (!CommandUtils.checkPlayerExistence(sender, playerName, mcMMOPlayer)) { if (!CommandUtils.checkPlayerExistence(sender, args[0], mcMMOPlayer)) {
return true; return true;
} }
@@ -59,7 +57,7 @@ public class KrakenCommand 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:
Set<String> playerNames = UserManager.getPlayerNames(); Set<String> playerNames = UserManager.getPlayers().keySet();
return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList<String>(playerNames.size())); return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList<String>(playerNames.size()));
default: default:
return ImmutableList.of(); return ImmutableList.of();

View File

@@ -2,7 +2,6 @@ package com.gmail.nossr50.commands;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
@@ -18,13 +17,13 @@ public class McabilityCommand extends ToggleCommand {
} }
@Override @Override
protected void applyCommandAction(McMMOPlayer mcMMOPlayer) { protected void applyCommandAction() {
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.Ability." + (mcMMOPlayer.getAbilityUse() ? "Off" : "On"))); player.sendMessage(LocaleLoader.getString("Commands.Ability." + (mcMMOPlayer.getAbilityUse() ? "Off" : "On")));
mcMMOPlayer.toggleAbilityUse(); mcMMOPlayer.toggleAbilityUse();
} }
@Override @Override
protected void sendSuccessMessage(CommandSender sender, String playerName) { protected void sendSuccessMessage(CommandSender sender) {
sender.sendMessage(LocaleLoader.getString("Commands.Ability.Toggle", playerName)); sender.sendMessage("Ability use has been toggled for " + player.getName()); // TODO: Localize
} }
} }

View File

@@ -1,93 +0,0 @@
package com.gmail.nossr50.commands;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.util.StringUtil;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.commands.database.ConvertDatabaseCommand;
import com.gmail.nossr50.commands.experience.ConvertExperienceCommand;
import com.gmail.nossr50.database.DatabaseManagerFactory;
import com.gmail.nossr50.datatypes.database.DatabaseType;
import com.gmail.nossr50.datatypes.experience.FormulaType;
import com.google.common.collect.ImmutableList;
public class McconvertCommand implements TabExecutor {
private static final List<String> FORMULA_TYPES;
private static final List<String> DATABASE_TYPES;
private static final List<String> SUBCOMMANDS = ImmutableList.of("database", "experience");
private CommandExecutor databaseConvertCommand = new ConvertDatabaseCommand();
private CommandExecutor experienceConvertCommand = new ConvertExperienceCommand();
static {
ArrayList<String> formulaTypes = new ArrayList<String>();
ArrayList<String> databaseTypes = new ArrayList<String>();
for (FormulaType type : FormulaType.values()) {
formulaTypes.add(type.toString());
}
for (DatabaseType type : DatabaseType.values()) {
databaseTypes.add(type.toString());
}
// Custom stuff
databaseTypes.remove(DatabaseType.CUSTOM.toString());
if (mcMMO.getDatabaseManager().getDatabaseType() == DatabaseType.CUSTOM) {
databaseTypes.add(DatabaseManagerFactory.getCustomDatabaseManagerClass().getName());
}
Collections.sort(formulaTypes);
Collections.sort(databaseTypes);
FORMULA_TYPES = ImmutableList.copyOf(formulaTypes);
DATABASE_TYPES = ImmutableList.copyOf(databaseTypes);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) {
case 2:
if (args[0].equalsIgnoreCase("database") || args[0].equalsIgnoreCase("db")) {
return databaseConvertCommand.onCommand(sender, command, label, args);
}
else if (args[0].equalsIgnoreCase("experience") || args[0].equalsIgnoreCase("xp") || args[1].equalsIgnoreCase("exp")) {
return experienceConvertCommand.onCommand(sender, command, label, args);
}
return false;
default:
return false;
}
}
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
switch (args.length) {
case 1:
return StringUtil.copyPartialMatches(args[0], SUBCOMMANDS, new ArrayList<String>(SUBCOMMANDS.size()));
case 2:
if (args[0].equalsIgnoreCase("database") || args[0].equalsIgnoreCase("db")) {
return StringUtil.copyPartialMatches(args[0], DATABASE_TYPES, new ArrayList<String>(DATABASE_TYPES.size()));
}
if (args[0].equalsIgnoreCase("experience") || args[0].equalsIgnoreCase("xp") || args[0].equalsIgnoreCase("exp")) {
return StringUtil.copyPartialMatches(args[0], FORMULA_TYPES, new ArrayList<String>(FORMULA_TYPES.size()));
}
return ImmutableList.of();
default:
return ImmutableList.of();
}
}
}

View File

@@ -2,7 +2,6 @@ package com.gmail.nossr50.commands;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
@@ -18,13 +17,13 @@ public class McgodCommand extends ToggleCommand {
} }
@Override @Override
protected void applyCommandAction(McMMOPlayer mcMMOPlayer) { protected void applyCommandAction() {
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.GodMode." + (mcMMOPlayer.getGodMode() ? "Disabled" : "Enabled"))); player.sendMessage(LocaleLoader.getString("Commands.GodMode." + (mcMMOPlayer.getGodMode() ? "Disabled" : "Enabled")));
mcMMOPlayer.toggleGodMode(); mcMMOPlayer.toggleGodMode();
} }
@Override @Override
protected void sendSuccessMessage(CommandSender sender, String playerName) { protected void sendSuccessMessage(CommandSender sender) {
sender.sendMessage(LocaleLoader.getString("Commands.GodMode.Toggle", playerName)); sender.sendMessage("God mode has been toggled for " + player.getName()); // TODO: Localize
} }
} }

View File

@@ -4,13 +4,14 @@ import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.commands.party.PartySubcommandType; import com.gmail.nossr50.commands.party.PartySubcommandType;
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.HolidayManager;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.spout.SpoutUtils;
public class McmmoCommand implements CommandExecutor { public class McmmoCommand implements CommandExecutor {
@Override @Override
@@ -27,12 +28,16 @@ public class McmmoCommand implements CommandExecutor {
sender.sendMessage(mcSplit); sender.sendMessage(mcSplit);
if (Config.getInstance().getDonateMessageEnabled()) { if (Config.getInstance().getDonateMessageEnabled()) {
sender.sendMessage(LocaleLoader.getString("MOTD.Donate")); if (mcMMO.isSpoutEnabled() && sender instanceof Player) {
sender.sendMessage(ChatColor.GOLD + " - " + ChatColor.GREEN + "gjmcferrin@gmail.com" + ChatColor.GOLD + " Paypal"); SpoutUtils.sendDonationNotification((Player) sender);
}
else {
sender.sendMessage(LocaleLoader.getString("MOTD.Donate"));
sender.sendMessage(ChatColor.GOLD + " - " + ChatColor.GREEN + "gjmcferrin@gmail.com" + ChatColor.GOLD + " Paypal");
}
} }
sender.sendMessage(LocaleLoader.getString("MOTD.Version", mcMMO.p.getDescription().getVersion())); sender.sendMessage(LocaleLoader.getString("MOTD.Version", mcMMO.p.getDescription().getVersion()));
HolidayManager.anniversaryCheck(sender);
return true; return true;
case 1: case 1:

View File

@@ -2,7 +2,6 @@ package com.gmail.nossr50.commands;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
@@ -18,17 +17,17 @@ public class McrefreshCommand extends ToggleCommand {
} }
@Override @Override
protected void applyCommandAction(McMMOPlayer mcMMOPlayer) { protected void applyCommandAction() {
mcMMOPlayer.setRecentlyHurt(0); mcMMOPlayer.setRecentlyHurt(0);
mcMMOPlayer.resetCooldowns(); mcMMOPlayer.getProfile().resetCooldowns();
mcMMOPlayer.resetToolPrepMode(); mcMMOPlayer.resetToolPrepMode();
mcMMOPlayer.resetAbilityMode(); mcMMOPlayer.resetAbilityMode();
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Ability.Generic.Refresh")); player.sendMessage(LocaleLoader.getString("Ability.Generic.Refresh"));
} }
@Override @Override
protected void sendSuccessMessage(CommandSender sender, String playerName) { protected void sendSuccessMessage(CommandSender sender) {
sender.sendMessage(LocaleLoader.getString("Commands.mcrefresh.Success", playerName)); sender.sendMessage(LocaleLoader.getString("Commands.mcrefresh.Success", player.getName()));
} }
} }

View File

@@ -6,17 +6,20 @@ 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) {
@@ -24,49 +27,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;
} }
} }
@@ -74,17 +122,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

@@ -11,7 +11,7 @@ import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil; import org.bukkit.util.StringUtil;
import com.gmail.nossr50.datatypes.MobHealthbarType; import com.gmail.nossr50.datatypes.MobHealthbarType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.datatypes.player.PlayerProfile;
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;
@@ -39,14 +39,16 @@ public class MobhealthCommand implements TabExecutor {
switch (args.length) { switch (args.length) {
case 1: case 1:
PlayerProfile playerProfile = UserManager.getPlayer((Player) sender).getProfile();
try { try {
MobHealthbarType type = MobHealthbarType.valueOf(args[0].toUpperCase().trim()); MobHealthbarType type = MobHealthbarType.valueOf(args[0].toUpperCase().trim());
UserManager.getPlayer((Player) sender).getProfile().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

@@ -7,16 +7,19 @@ import java.util.Set;
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.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
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 {
protected McMMOPlayer mcMMOPlayer;
protected Player player;
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) { switch (args.length) {
@@ -30,7 +33,10 @@ public abstract class ToggleCommand implements TabExecutor {
return true; return true;
} }
applyCommandAction(UserManager.getPlayer(sender.getName())); player = (Player) sender;
mcMMOPlayer = UserManager.getPlayer(player);
applyCommandAction();
return true; return true;
case 1: case 1:
@@ -39,19 +45,20 @@ public abstract class ToggleCommand implements TabExecutor {
return true; return true;
} }
String playerName = Misc.getMatchedPlayerName(args[0]); mcMMOPlayer = UserManager.getPlayer(args[0]);
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(playerName);
if (!CommandUtils.checkPlayerExistence(sender, playerName, mcMMOPlayer)) { if (!CommandUtils.checkPlayerExistence(sender, args[0], mcMMOPlayer)) {
return true; return true;
} }
if (CommandUtils.isOffline(sender, mcMMOPlayer.getPlayer())) { player = mcMMOPlayer.getPlayer();
if (CommandUtils.isOffline(sender, player)) {
return true; return true;
} }
applyCommandAction(mcMMOPlayer); applyCommandAction();
sendSuccessMessage(sender, playerName); sendSuccessMessage(sender);
return true; return true;
default: default:
@@ -63,7 +70,7 @@ public abstract class ToggleCommand 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:
Set<String> playerNames = UserManager.getPlayerNames(); Set<String> playerNames = UserManager.getPlayers().keySet();
return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList<String>(playerNames.size())); return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList<String>(playerNames.size()));
default: default:
return ImmutableList.of(); return ImmutableList.of();
@@ -72,6 +79,6 @@ public abstract class ToggleCommand implements TabExecutor {
protected abstract boolean hasOtherPermission(CommandSender sender); protected abstract boolean hasOtherPermission(CommandSender sender);
protected abstract boolean hasSelfPermission(CommandSender sender); protected abstract boolean hasSelfPermission(CommandSender sender);
protected abstract void applyCommandAction(McMMOPlayer mcMMOPlayer); protected abstract void applyCommandAction();
protected abstract void sendSuccessMessage(CommandSender sender, String playerName); protected abstract void sendSuccessMessage(CommandSender sender);
} }

View File

@@ -9,7 +9,7 @@ import org.bukkit.command.TabExecutor;
import org.bukkit.util.StringUtil; import org.bukkit.util.StringUtil;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.StringUtils;
@@ -18,7 +18,11 @@ import com.gmail.nossr50.util.commands.CommandUtils;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
public class XprateCommand implements TabExecutor { public class XprateCommand implements TabExecutor {
private final double ORIGINAL_XP_RATE = ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier(); private double originalRate;
public XprateCommand() {
originalRate = Config.getInstance().getExperienceGainsGlobalMultiplier();
}
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
@@ -38,7 +42,7 @@ public class XprateCommand implements TabExecutor {
mcMMO.p.toggleXpEventEnabled(); mcMMO.p.toggleXpEventEnabled();
} }
ExperienceConfig.getInstance().setExperienceGainsGlobalMultiplier(ORIGINAL_XP_RATE); Config.getInstance().setExperienceGainsGlobalMultiplier(originalRate);
return true; return true;
case 2: case 2:
@@ -62,7 +66,7 @@ public class XprateCommand implements TabExecutor {
} }
int newXpRate = Integer.parseInt(args[0]); int newXpRate = Integer.parseInt(args[0]);
ExperienceConfig.getInstance().setExperienceGainsGlobalMultiplier(newXpRate); Config.getInstance().setExperienceGainsGlobalMultiplier(newXpRate);
if (mcMMO.p.isXPEventEnabled()) { if (mcMMO.p.isXPEventEnabled()) {
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Commands.xprate.started.0")); mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Commands.xprate.started.0"));

View File

@@ -2,7 +2,7 @@ package com.gmail.nossr50.commands.chat;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.gmail.nossr50.datatypes.chat.ChatMode; import com.gmail.nossr50.chat.ChatMode;
public class AdminChatCommand extends ChatCommand { public class AdminChatCommand extends ChatCommand {
public AdminChatCommand() { public AdminChatCommand() {

View File

@@ -12,7 +12,7 @@ import org.bukkit.util.StringUtil;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.chat.ChatManager; import com.gmail.nossr50.chat.ChatManager;
import com.gmail.nossr50.chat.ChatManagerFactory; import com.gmail.nossr50.chat.ChatManagerFactory;
import com.gmail.nossr50.datatypes.chat.ChatMode; import com.gmail.nossr50.chat.ChatMode;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.commands.CommandUtils;
@@ -21,8 +21,9 @@ import com.gmail.nossr50.util.player.UserManager;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
public abstract class ChatCommand implements TabExecutor { public abstract class ChatCommand implements TabExecutor {
private ChatMode chatMode; protected ChatMode chatMode;
protected ChatManager chatManager; protected ChatManager chatManager;
private McMMOPlayer mcMMOPlayer;
public ChatCommand(ChatMode chatMode) { public ChatCommand(ChatMode chatMode) {
this.chatMode = chatMode; this.chatMode = chatMode;
@@ -31,21 +32,19 @@ public abstract class ChatCommand implements TabExecutor {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
McMMOPlayer mcMMOPlayer;
switch (args.length) { switch (args.length) {
case 0: case 0:
if (CommandUtils.noConsoleUsage(sender)) { if (CommandUtils.noConsoleUsage(sender)) {
return true; return true;
} }
mcMMOPlayer = UserManager.getPlayer(sender.getName()); mcMMOPlayer = UserManager.getPlayer((Player) sender);
if (mcMMOPlayer.isChatEnabled(chatMode)) { if (chatMode.isEnabled(mcMMOPlayer)) {
disableChatMode(mcMMOPlayer, sender); disableChatMode(sender);
} }
else { else {
enableChatMode(mcMMOPlayer, sender); enableChatMode(sender);
} }
return true; return true;
@@ -56,7 +55,9 @@ public abstract class ChatCommand implements TabExecutor {
return true; return true;
} }
enableChatMode(UserManager.getPlayer(sender.getName()), sender); mcMMOPlayer = UserManager.getPlayer((Player) sender);
enableChatMode(sender);
return true; return true;
} }
@@ -65,7 +66,9 @@ public abstract class ChatCommand implements TabExecutor {
return true; return true;
} }
disableChatMode(UserManager.getPlayer(sender.getName()), sender); mcMMOPlayer = UserManager.getPlayer((Player) sender);
disableChatMode(sender);
return true; return true;
} }
@@ -105,23 +108,23 @@ public abstract class ChatCommand implements TabExecutor {
protected abstract void handleChatSending(CommandSender sender, String[] args); protected abstract void handleChatSending(CommandSender sender, String[] args);
private void enableChatMode(McMMOPlayer mcMMOPlayer, CommandSender sender) { private void enableChatMode(CommandSender sender) {
if (chatMode == ChatMode.PARTY && mcMMOPlayer.getParty() == null) { if (chatMode == ChatMode.PARTY && mcMMOPlayer.getParty() == null) {
sender.sendMessage(LocaleLoader.getString("Commands.Party.None")); sender.sendMessage(LocaleLoader.getString("Commands.Party.None"));
return; return;
} }
mcMMOPlayer.enableChat(chatMode); chatMode.enable(mcMMOPlayer);
sender.sendMessage(chatMode.getEnabledMessage()); sender.sendMessage(chatMode.getEnabledMessage());
} }
private void disableChatMode(McMMOPlayer mcMMOPlayer, CommandSender sender) { private void disableChatMode(CommandSender sender) {
if (chatMode == ChatMode.PARTY && mcMMOPlayer.getParty() == null) { if (chatMode == ChatMode.PARTY && mcMMOPlayer.getParty() == null) {
sender.sendMessage(LocaleLoader.getString("Commands.Party.None")); sender.sendMessage(LocaleLoader.getString("Commands.Party.None"));
return; return;
} }
mcMMOPlayer.disableChat(chatMode); chatMode.disable(mcMMOPlayer);
sender.sendMessage(chatMode.getDisabledMessage()); sender.sendMessage(chatMode.getDisabledMessage());
} }
} }

View File

@@ -3,8 +3,8 @@ package com.gmail.nossr50.commands.chat;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.chat.ChatMode;
import com.gmail.nossr50.chat.PartyChatManager; import com.gmail.nossr50.chat.PartyChatManager;
import com.gmail.nossr50.datatypes.chat.ChatMode;
import com.gmail.nossr50.datatypes.party.Party; import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;

View File

@@ -1,74 +0,0 @@
package com.gmail.nossr50.commands.database;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.database.DatabaseManager;
import com.gmail.nossr50.database.DatabaseManagerFactory;
import com.gmail.nossr50.datatypes.database.DatabaseType;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.runnables.database.DatabaseConversionTask;
import com.gmail.nossr50.util.player.UserManager;
public class ConvertDatabaseCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) {
case 2:
DatabaseType previousType = DatabaseType.getDatabaseType(args[1]);
DatabaseType newType = mcMMO.getDatabaseManager().getDatabaseType();
if (previousType == newType || (newType == DatabaseType.CUSTOM && DatabaseManagerFactory.getCustomDatabaseManagerClass().getSimpleName().equalsIgnoreCase(args[1]))) {
sender.sendMessage(LocaleLoader.getString("Commands.mcconvert.Database.Same", newType.toString()));
return true;
}
DatabaseManager oldDatabase = DatabaseManagerFactory.createDatabaseManager(previousType);
if (previousType == DatabaseType.CUSTOM) {
Class<?> clazz;
try {
clazz = Class.forName(args[1]);
if (!DatabaseManager.class.isAssignableFrom(clazz)) {
sender.sendMessage(LocaleLoader.getString("Commands.mcconvert.Database.InvalidType", args[1]));
return true;
}
oldDatabase = DatabaseManagerFactory.createCustomDatabaseManager((Class<? extends DatabaseManager>) clazz);
}
catch (Throwable e) {
e.printStackTrace();
sender.sendMessage(LocaleLoader.getString("Commands.mcconvert.Database.InvalidType", args[1]));
return true;
}
}
sender.sendMessage(LocaleLoader.getString("Commands.mcconvert.Database.Start", previousType.toString(), newType.toString()));
UserManager.saveAll();
UserManager.clearAll();
for (Player player : mcMMO.p.getServer().getOnlinePlayers()) {
PlayerProfile profile = oldDatabase.loadPlayerProfile(player.getName(), false);
if (profile.isLoaded()) {
mcMMO.getDatabaseManager().saveUser(profile);
}
UserManager.addUser(player);
}
new DatabaseConversionTask(oldDatabase, sender, previousType.toString(), newType.toString()).runTaskAsynchronously(mcMMO.p);
return true;
default:
return false;
}
}
}

View File

@@ -10,8 +10,8 @@ import org.bukkit.command.TabExecutor;
import org.bukkit.util.StringUtil; import org.bukkit.util.StringUtil;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader; 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;
@@ -22,17 +22,15 @@ public class McremoveCommand 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:
String playerName = Misc.getMatchedPlayerName(args[0]); if (UserManager.getPlayer(args[0]) == null && CommandUtils.unloadedProfile(sender, new PlayerProfile(args[0], false))) {
if (UserManager.getPlayer(playerName, true) == null && CommandUtils.unloadedProfile(sender, mcMMO.getDatabaseManager().loadPlayerProfile(playerName, false))) {
return true; return true;
} }
if (mcMMO.getDatabaseManager().removeUser(playerName)) { if (mcMMO.getDatabaseManager().removeUser(args[0])) {
sender.sendMessage(LocaleLoader.getString("Commands.mcremove.Success", playerName)); sender.sendMessage(LocaleLoader.getString("Commands.mcremove.Success", args[0]));
} }
else { else {
sender.sendMessage(playerName + " could not be removed from the database."); // Pretty sure this should NEVER happen. sender.sendMessage(args[0] + " could not be removed from the database."); // Pretty sure this should NEVER happen.
} }
return true; return true;
@@ -46,7 +44,7 @@ public class McremoveCommand 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:
Set<String> playerNames = UserManager.getPlayerNames(); Set<String> playerNames = UserManager.getPlayers().keySet();
return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList<String>(playerNames.size())); return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList<String>(playerNames.size()));
default: default:
return ImmutableList.of(); return ImmutableList.of();

View File

@@ -5,26 +5,36 @@ 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 com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.database.DatabaseManagerFactory;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.runnables.database.SQLConversionTask;
import com.gmail.nossr50.util.player.UserManager;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
public class MmoshowdbCommand implements TabExecutor { public class MmoupdateCommand implements TabExecutor {
@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 (!Config.getInstance().getUseMySQL()) {
sender.sendMessage("SQL Mode is not enabled."); // TODO: Localize
return true;
}
switch (args.length) { switch (args.length) {
case 0: case 0:
Class<?> clazz = DatabaseManagerFactory.getCustomDatabaseManagerClass(); sender.sendMessage(LocaleLoader.getString("Commands.mmoupdate.Start"));
UserManager.saveAll();
UserManager.clearAll();
new SQLConversionTask().runTaskLaterAsynchronously(mcMMO.p, 1);
if (clazz != null) { for (Player player : mcMMO.p.getServer().getOnlinePlayers()) {
sender.sendMessage(LocaleLoader.getString("Commands.mmoshowdb", clazz.getName())); UserManager.addUser(player);
return true;
} }
sender.sendMessage(LocaleLoader.getString("Commands.mmoshowdb", (Config.getInstance().getUseMySQL() ? "sql" : "flatfile"))); sender.sendMessage(LocaleLoader.getString("Commands.mmoupdate.Finish"));
return true; return true;
default: default:

View File

@@ -1,13 +1,13 @@
package com.gmail.nossr50.commands.experience; package com.gmail.nossr50.commands.experience;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.player.PlayerProfile; 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
@@ -21,25 +21,21 @@ public class AddlevelsCommand extends ExperienceCommand {
} }
@Override @Override
protected void handleCommand(Player player, PlayerProfile profile, SkillType skill, int value) { protected void handleCommand(SkillType skill) {
float xpRemoved = profile.getSkillXpLevelRaw(skill);
profile.addLevels(skill, value); profile.addLevels(skill, value);
if (player == null) { if (player != null) {
profile.save(); mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerLevelUpEvent(player, skill, value));
return;
} }
EventUtils.handleLevelChangeEvent(player, skill, value, xpRemoved, true);
} }
@Override @Override
protected void handlePlayerMessageAll(Player player, int value) { protected void handlePlayerMessageAll() {
player.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.1", value)); player.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.1", value));
} }
@Override @Override
protected void handlePlayerMessageSkill(Player player, int value, SkillType skill) { 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

@@ -1,13 +1,11 @@
package com.gmail.nossr50.commands.experience; package com.gmail.nossr50.commands.experience;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.skills.SkillUtils;
public class AddxpCommand extends ExperienceCommand { public class AddxpCommand extends ExperienceCommand {
@Override @Override
@@ -21,23 +19,22 @@ public class AddxpCommand extends ExperienceCommand {
} }
@Override @Override
protected void handleCommand(Player player, PlayerProfile profile, SkillType skill, int value) { protected void handleCommand(SkillType skill) {
if (player != null) { if (player != null) {
UserManager.getPlayer(player).applyXpGain(skill, value); mcMMOPlayer.applyXpGain(skill, value);
} }
else { else {
profile.addXp(skill, value); profile.addExperience(skill, value);
profile.save();
} }
} }
@Override @Override
protected void handlePlayerMessageAll(Player player, int value) { protected void handlePlayerMessageAll() {
player.sendMessage(LocaleLoader.getString("Commands.addxp.AwardAll", value)); player.sendMessage(LocaleLoader.getString("Commands.addxp.AwardAll", value));
} }
@Override @Override
protected void handlePlayerMessageSkill(Player player, int value, SkillType skill) { 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

@@ -1,49 +0,0 @@
package com.gmail.nossr50.commands.experience;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.experience.FormulaType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.runnables.database.FormulaConversionTask;
import com.gmail.nossr50.util.player.UserManager;
public class ConvertExperienceCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) {
case 2:
FormulaType previousType = mcMMO.getFormulaManager().getPreviousFormulaType();
FormulaType newType = FormulaType.getFormulaType(args[1].toUpperCase());
if (newType == FormulaType.UNKNOWN) {
sender.sendMessage(LocaleLoader.getString("Commands.mcconvert.Experience.Invalid"));
return true;
}
if (previousType == newType) {
sender.sendMessage(LocaleLoader.getString("Commands.mcconvert.Experience.Same", newType.toString()));
return true;
}
sender.sendMessage(LocaleLoader.getString("Commands.mcconvert.Experience.Start", previousType.toString(), newType.toString()));
UserManager.saveAll();
UserManager.clearAll();
new FormulaConversionTask(sender, newType).runTaskLater(mcMMO.p, 1);
for (Player player : mcMMO.p.getServer().getOnlinePlayers()) {
UserManager.addUser(player);
}
return true;
default:
return false;
}
}
}

View File

@@ -10,18 +10,25 @@ import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil; import org.bukkit.util.StringUtil;
import com.gmail.nossr50.mcMMO;
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.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;
public abstract class ExperienceCommand implements TabExecutor { public abstract class ExperienceCommand implements TabExecutor {
protected McMMOPlayer mcMMOPlayer;
protected Player player;
protected PlayerProfile profile;
protected boolean allSkills;
protected SkillType skill;
protected int value;
@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) {
@@ -39,7 +46,12 @@ public abstract class ExperienceCommand implements TabExecutor {
return true; return true;
} }
editValues((Player) sender, UserManager.getPlayer(sender.getName()).getProfile(), SkillType.getSkill(args[0]), Integer.parseInt(args[1])); player = (Player) sender;
mcMMOPlayer = UserManager.getPlayer(player);
profile = mcMMOPlayer.getProfile();
editValues();
allSkills = false;
return true; return true;
case 3: case 3:
@@ -52,27 +64,27 @@ public abstract class ExperienceCommand implements TabExecutor {
return true; return true;
} }
SkillType skill = SkillType.getSkill(args[1]); mcMMOPlayer = UserManager.getPlayer(args[0]);
int value = Integer.parseInt(args[2]);
String playerName = Misc.getMatchedPlayerName(args[0]);
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(playerName, true);
// If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process. // If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
if (mcMMOPlayer == null) { if (mcMMOPlayer == null) {
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(playerName, false); profile = new PlayerProfile(args[0], false);
if (CommandUtils.unloadedProfile(sender, profile)) { if (CommandUtils.unloadedProfile(sender, profile)) {
return true; return true;
} }
editValues(null, profile, skill, value); editValues();
profile.save(); // Since this is a temporary profile, we save it here.
} }
else { else {
editValues(mcMMOPlayer.getPlayer(), mcMMOPlayer.getProfile(), skill, value); profile = mcMMOPlayer.getProfile();
player = mcMMOPlayer.getPlayer();
editValues();
} }
handleSenderMessage(sender, playerName, skill); handleSenderMessage(sender, args[0]);
allSkills = false;
return true; return true;
default: default:
@@ -84,7 +96,7 @@ public abstract class ExperienceCommand 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:
Set<String> playerNames = UserManager.getPlayerNames(); Set<String> playerNames = UserManager.getPlayers().keySet();
return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList<String>(playerNames.size())); return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList<String>(playerNames.size()));
case 2: case 2:
return StringUtil.copyPartialMatches(args[1], SkillType.SKILL_NAMES, new ArrayList<String>(SkillType.SKILL_NAMES.size())); return StringUtil.copyPartialMatches(args[1], SkillType.SKILL_NAMES, new ArrayList<String>(SkillType.SKILL_NAMES.size()));
@@ -95,42 +107,64 @@ public abstract class ExperienceCommand implements TabExecutor {
protected abstract boolean permissionsCheckSelf(CommandSender sender); protected abstract boolean permissionsCheckSelf(CommandSender sender);
protected abstract boolean permissionsCheckOthers(CommandSender sender); protected abstract boolean permissionsCheckOthers(CommandSender sender);
protected abstract void handleCommand(Player player, PlayerProfile profile, SkillType skill, int value); protected abstract void handleCommand(SkillType skill);
protected abstract void handlePlayerMessageAll(Player player, int value); protected abstract void handlePlayerMessageAll();
protected abstract void handlePlayerMessageSkill(Player player, int value, SkillType skill); protected abstract void handlePlayerMessageSkill();
private boolean validateArguments(CommandSender sender, String skillName, String value) { private boolean validateArguments(CommandSender sender, String skillName, String value) {
if (CommandUtils.isInvalidInteger(sender, value) || CommandUtils.isInvalidSkill(sender, skillName)) { if (isInvalidInteger(sender, value) || isInvalidSkill(sender, skillName)) {
return false; return false;
} }
return true; return true;
} }
protected static void handleSenderMessage(CommandSender sender, String playerName, SkillType skill) { private boolean isInvalidInteger(CommandSender sender, String value) {
if (skill == null) { if (CommandUtils.isInvalidInteger(sender, value)) {
return true;
}
this.value = Integer.parseInt(value);
return false;
}
protected boolean isInvalidSkill(CommandSender sender, String skillName) {
if (skillName.equalsIgnoreCase("all")) {
allSkills = true;
return false;
}
else if (CommandUtils.isInvalidSkill(sender, skillName)) {
return true;
}
skill = SkillType.getSkill(skillName);
return false;
}
protected void handleSenderMessage(CommandSender sender, String playerName) {
if (allSkills) {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", playerName)); 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));
} }
} }
protected void editValues(Player player, PlayerProfile profile, SkillType skill, int value) { protected void editValues() {
if (skill == null) { if (allSkills) {
for (SkillType skillType : SkillType.values()) { for (SkillType skillType : SkillType.values()) {
handleCommand(player, profile, skillType, value); handleCommand(skillType);
} }
if (player != null) { if (player != null) {
handlePlayerMessageAll(player, value); handlePlayerMessageAll();
} }
} }
else { else {
handleCommand(player, profile, skill, value); handleCommand(skill);
if (player != null) { if (player != null) {
handlePlayerMessageSkill(player, value, skill); handlePlayerMessageSkill();
} }
} }
} }

View File

@@ -1,13 +1,13 @@
package com.gmail.nossr50.commands.experience; package com.gmail.nossr50.commands.experience;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.player.PlayerProfile; 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 MmoeditCommand extends ExperienceCommand { public class MmoeditCommand extends ExperienceCommand {
@Override @Override
@@ -21,31 +21,21 @@ public class MmoeditCommand extends ExperienceCommand {
} }
@Override @Override
protected void handleCommand(Player player, PlayerProfile profile, SkillType skill, int value) { 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) { if (player != null) {
profile.save(); mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerLevelUpEvent(player, skill, value - profile.getSkillLevel(skill)));
return;
} }
if (value == skillLevel) {
return;
}
EventUtils.handleLevelChangeEvent(player, skill, value, xpRemoved, value > skillLevel);
} }
@Override @Override
protected void handlePlayerMessageAll(Player player, int value) { protected void handlePlayerMessageAll() {
player.sendMessage(LocaleLoader.getString("Commands.mmoedit.AllSkills.1", value)); player.sendMessage(LocaleLoader.getString("Commands.mmoedit.AllSkills.1", value));
} }
@Override @Override
protected void handlePlayerMessageSkill(Player player, int value, SkillType skill) { 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

@@ -1,30 +1,30 @@
package com.gmail.nossr50.commands.experience; package com.gmail.nossr50.commands.experience;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
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.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
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.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.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.gmail.nossr50.util.skills.SkillUtils;
public class SkillresetCommand extends ExperienceCommand {
private CommandSender sender;
private Command command;
private int argsLength;
public class SkillresetCommand implements TabExecutor {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
this.command = command;
this.sender = sender;
argsLength = args.length;
switch (args.length) { switch (args.length) {
case 1: case 1:
if (CommandUtils.noConsoleUsage(sender)) { if (CommandUtils.noConsoleUsage(sender)) {
@@ -36,11 +36,15 @@ public class SkillresetCommand implements TabExecutor {
return true; return true;
} }
if (CommandUtils.isInvalidSkill(sender, args[0])) { if (isInvalidSkill(sender, args[0])) {
return true; return true;
} }
editValues((Player) sender, UserManager.getPlayer(sender.getName()).getProfile(), SkillType.getSkill(args[0]), args.length, sender, command); player = (Player) sender;
mcMMOPlayer = UserManager.getPlayer(player);
profile = mcMMOPlayer.getProfile();
editValues();
return true; return true;
case 2: case 2:
@@ -49,30 +53,31 @@ public class SkillresetCommand implements TabExecutor {
return true; return true;
} }
if (CommandUtils.isInvalidSkill(sender, args[1])) { if (isInvalidSkill(sender, args[1])) {
return true; return true;
} }
SkillType skill = SkillType.getSkill(args[1]); mcMMOPlayer = UserManager.getPlayer(args[0]);
String playerName = Misc.getMatchedPlayerName(args[0]);
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(playerName, true);
// If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process. // If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
if (mcMMOPlayer == null) { if (mcMMOPlayer == null) {
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(playerName, false); profile = new PlayerProfile(args[0], false);
if (CommandUtils.unloadedProfile(sender, profile)) { if (CommandUtils.unloadedProfile(sender, profile)) {
return true; return true;
} }
editValues(null, profile, skill, args.length, sender, command); editValues();
profile.save(); // Since this is a temporary profile, we save it here.
} }
else { else {
editValues(mcMMOPlayer.getPlayer(), mcMMOPlayer.getProfile(), skill, args.length, sender, command); profile = mcMMOPlayer.getProfile();
player = mcMMOPlayer.getPlayer();
editValues();
} }
ExperienceCommand.handleSenderMessage(sender, playerName, skill); handleSenderMessage(sender, args[0]);
return true; return true;
default: default:
@@ -81,53 +86,36 @@ public class SkillresetCommand implements TabExecutor {
} }
@Override @Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) { protected boolean permissionsCheckSelf(CommandSender sender) {
switch (args.length) { return false;
case 1:
Set<String> playerNames = UserManager.getPlayerNames();
return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList<String>(playerNames.size()));
case 2:
return StringUtil.copyPartialMatches(args[1], SkillType.SKILL_NAMES, new ArrayList<String>(SkillType.SKILL_NAMES.size()));
default:
return ImmutableList.of();
}
} }
private void editValues(Player player, PlayerProfile profile, SkillType skill, int argsLength, CommandSender sender, Command command) { @Override
if (skill == null) { protected boolean permissionsCheckOthers(CommandSender sender) {
for (SkillType skillType : SkillType.values()) { return false;
handleCommand(player, profile, skillType, argsLength, sender, command);
}
if (player != null) {
player.sendMessage(LocaleLoader.getString("Commands.Reset.All"));
}
}
else {
handleCommand(player, profile, skill, argsLength, sender, command);
if (player != null) {
player.sendMessage(LocaleLoader.getString("Commands.Reset.Single", skill.getName()));
}
}
} }
private void handleCommand(Player player, PlayerProfile profile, SkillType skill, int argsLength, CommandSender sender, Command command) { @Override
protected void handleCommand(SkillType skill) {
if (argsLength == 1 && !Permissions.skillreset(sender, skill) || (argsLength == 2 && !Permissions.skillresetOthers(sender, skill))) { if (argsLength == 1 && !Permissions.skillreset(sender, skill) || (argsLength == 2 && !Permissions.skillresetOthers(sender, skill))) {
sender.sendMessage(command.getPermissionMessage()); sender.sendMessage(command.getPermissionMessage());
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) {
profile.save(); mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerLevelUpEvent(player, skill, 0 - profile.getSkillLevel(skill)));
return;
} }
}
EventUtils.handleLevelChangeEvent(player, skill, levelsRemoved, xpRemoved, false); @Override
protected void handlePlayerMessageAll() {
player.sendMessage(LocaleLoader.getString("Commands.Reset.All"));
}
@Override
protected void handlePlayerMessageSkill() {
player.sendMessage(LocaleLoader.getString("Commands.Reset.Single", SkillUtils.getSkillName(skill)));
} }
} }

View File

@@ -1,65 +1,41 @@
package com.gmail.nossr50.commands.hardcore; package com.gmail.nossr50.commands.hardcore;
import org.bukkit.command.CommandSender;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.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;
public class HardcoreCommand extends HardcoreModeCommand { public class HardcoreCommand extends HardcoreModeCommand {
@Override @Override
protected boolean checkTogglePermissions(CommandSender sender) { protected void disable() {
Config.getInstance().setHardcoreEnabled(false);
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Hardcore.Disabled"));
}
@Override
protected void enable() {
Config.getInstance().setHardcoreEnabled(true);
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Hardcore.Enabled"));
}
@Override
protected boolean checkTogglePermissions() {
return Permissions.hardcoreToggle(sender); return Permissions.hardcoreToggle(sender);
} }
@Override @Override
protected boolean checkModifyPermissions(CommandSender sender) { protected boolean checkModifyPermissions() {
return Permissions.hardcoreModify(sender); return Permissions.hardcoreModify(sender);
} }
@Override @Override
protected boolean checkEnabled(SkillType skill) { protected boolean checkEnabled() {
if (skill == null) { return Config.getInstance().getHardcoreEnabled();
for (SkillType skillType : SkillType.values()) {
if (!skillType.getHardcoreStatLossEnabled()) {
return false;
}
}
return true;
}
return skill.getHardcoreStatLossEnabled();
} }
@Override @Override
protected void enable(SkillType skill) { protected void modify() {
toggle(true, skill); Config.getInstance().setHardcoreDeathStatPenaltyPercentage(newPercent);
} sender.sendMessage(LocaleLoader.getString("Hardcore.PercentageChanged", percent.format(newPercent / 100D)));
@Override
protected void disable(SkillType skill) {
toggle(false, skill);
}
@Override
protected void modify(CommandSender sender, double newPercentage) {
Config.getInstance().setHardcoreDeathStatPenaltyPercentage(newPercentage);
sender.sendMessage(LocaleLoader.getString("Hardcore.DeathStatLoss.PercentageChanged", percent.format(newPercentage / 100.0D)));
}
private void toggle(boolean enable, SkillType skill) {
if (skill == null) {
for (SkillType skillType : SkillType.NON_CHILD_SKILLS) {
skillType.setHardcoreStatLossEnabled(enable);
}
}
else {
skill.setHardcoreStatLossEnabled(enable);
}
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Hardcore.Mode." + (enable ? "Enabled" : "Disabled"), LocaleLoader.getString("Hardcore.DeathStatLoss.Name"), (skill == null ? "all skills" : skill.getName())));
} }
} }

View File

@@ -9,7 +9,6 @@ import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor; import org.bukkit.command.TabExecutor;
import org.bukkit.util.StringUtil; import org.bukkit.util.StringUtil;
import com.gmail.nossr50.datatypes.skills.SkillType;
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;
@@ -17,22 +16,30 @@ import com.gmail.nossr50.util.commands.CommandUtils;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
public abstract class HardcoreModeCommand implements TabExecutor { public abstract class HardcoreModeCommand implements TabExecutor {
protected final DecimalFormat percent = new DecimalFormat("##0.00%"); protected CommandSender sender;
protected double newPercent;
protected DecimalFormat percent;
public HardcoreModeCommand() {
percent = new DecimalFormat("##0.00%");
}
@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 0: case 0:
if (!checkTogglePermissions(sender)) { this.sender = sender;
if (!checkTogglePermissions()) {
sender.sendMessage(command.getPermissionMessage()); sender.sendMessage(command.getPermissionMessage());
return true; return true;
} }
if (checkEnabled(null)) { if (checkEnabled()) {
disable(null); disable();
} }
else { else {
enable(null); enable();
} }
return true; return true;
@@ -44,7 +51,7 @@ public abstract class HardcoreModeCommand implements TabExecutor {
return true; return true;
} }
enable(null); enable();
return true; return true;
} }
@@ -54,11 +61,11 @@ public abstract class HardcoreModeCommand implements TabExecutor {
return true; return true;
} }
disable(null); disable();
return true; return true;
} }
if (CommandUtils.isInvalidDouble(sender, args[0])) { if (isInvalidPercentage(sender, args[0])) {
return true; return true;
} }
@@ -67,41 +74,7 @@ public abstract class HardcoreModeCommand implements TabExecutor {
return true; return true;
} }
modify(sender, Double.parseDouble(args[0])); modify();
return true;
case 2:
if (CommandUtils.isInvalidSkill(sender, args[0])) {
return true;
}
SkillType skill = SkillType.getSkill(args[0]);
if (!CommandUtils.isChildSkill(sender, skill)) {
return true;
}
if (CommandUtils.shouldEnableToggle(args[1])) {
if (!Permissions.hardcoreToggle(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
enable(skill);
return true;
}
if (CommandUtils.shouldDisableToggle(args[1])) {
if (!Permissions.hardcoreToggle(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
enable(skill);
return true;
}
return true; return true;
default: default:
@@ -123,10 +96,19 @@ public abstract class HardcoreModeCommand implements TabExecutor {
} }
} }
protected abstract boolean checkTogglePermissions(CommandSender sender); protected abstract boolean checkTogglePermissions();
protected abstract boolean checkModifyPermissions(CommandSender sender); protected abstract boolean checkModifyPermissions();
protected abstract boolean checkEnabled(SkillType skill); protected abstract boolean checkEnabled();
protected abstract void enable(SkillType skill); protected abstract void enable();
protected abstract void disable(SkillType skill); protected abstract void disable();
protected abstract void modify(CommandSender sender, double newPercentage); protected abstract void modify();
private boolean isInvalidPercentage(CommandSender sender, String value) {
if (CommandUtils.isInvalidDouble(sender, value)) {
return true;
}
newPercent = Double.parseDouble(value);
return false;
}
} }

View File

@@ -1,65 +1,41 @@
package com.gmail.nossr50.commands.hardcore; package com.gmail.nossr50.commands.hardcore;
import org.bukkit.command.CommandSender;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.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;
public class VampirismCommand extends HardcoreModeCommand { public class VampirismCommand extends HardcoreModeCommand {
@Override @Override
protected boolean checkTogglePermissions(CommandSender sender) { protected boolean checkTogglePermissions() {
return Permissions.vampirismToggle(sender); return Permissions.vampirismToggle(sender);
} }
@Override @Override
protected boolean checkModifyPermissions(CommandSender sender) { protected boolean checkModifyPermissions() {
return Permissions.vampirismModify(sender); return Permissions.vampirismModify(sender);
} }
@Override @Override
protected boolean checkEnabled(SkillType skill) { protected boolean checkEnabled() {
if (skill == null) { return Config.getInstance().getHardcoreVampirismEnabled();
for (SkillType skillType : SkillType.values()) {
if (!skillType.getHardcoreVampirismEnabled()) {
return false;
}
}
return true;
}
return skill.getHardcoreVampirismEnabled();
} }
@Override @Override
protected void enable(SkillType skill) { protected void enable() {
toggle(true, skill); Config.getInstance().setHardcoreVampirismEnabled(true);
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Vampirism.Enabled"));
} }
@Override @Override
protected void disable(SkillType skill) { protected void disable() {
toggle(false, skill); Config.getInstance().setHardcoreVampirismEnabled(false);
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Vampirism.Disabled"));
} }
@Override @Override
protected void modify(CommandSender sender, double newPercentage) { protected void modify() {
Config.getInstance().setHardcoreVampirismStatLeechPercentage(newPercentage); Config.getInstance().setHardcoreVampirismStatLeechPercentage(newPercent);
sender.sendMessage(LocaleLoader.getString("Hardcore.Vampirism.PercentageChanged", percent.format(newPercentage / 100.0D))); sender.sendMessage(LocaleLoader.getString("Vampirism.PercentageChanged", percent.format(newPercent / 100D)));
}
private void toggle(boolean enable, SkillType skill) {
if (skill == null) {
for (SkillType skillType : SkillType.NON_CHILD_SKILLS) {
skillType.setHardcoreVampirismEnabled(enable);
}
}
else {
skill.setHardcoreVampirismEnabled(enable);
}
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Hardcore.Mode." + (enable ? "Enabled" : "Disabled"), LocaleLoader.getString("Hardcore.Vampirism.Name"), (skill == null ? "all skills" : skill)));
} }
} }

View File

@@ -24,11 +24,11 @@ public class PartyAcceptCommand implements CommandExecutor {
} }
// Changing parties // Changing parties
if (!PartyManager.changeOrJoinParty(mcMMOPlayer, mcMMOPlayer.getPartyInvite().getName())) { if (!PartyManager.changeOrJoinParty(mcMMOPlayer, player, mcMMOPlayer.getParty(), mcMMOPlayer.getPartyInvite().getName())) {
return true; return true;
} }
PartyManager.joinInvitedParty(mcMMOPlayer); PartyManager.joinInvitedParty(player, mcMMOPlayer);
return true; return true;
default: default:

View File

@@ -8,7 +8,6 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.party.Party; import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
public class PartyChangeOwnerCommand implements CommandExecutor { public class PartyChangeOwnerCommand implements CommandExecutor {
@@ -17,14 +16,13 @@ public class PartyChangeOwnerCommand implements CommandExecutor {
switch (args.length) { switch (args.length) {
case 2: case 2:
Party playerParty = UserManager.getPlayer((Player) sender).getParty(); Party playerParty = UserManager.getPlayer((Player) sender).getParty();
String targetName = Misc.getMatchedPlayerName(args[1]);
if (!playerParty.getMembers().contains(targetName)) { if (!playerParty.getMembers().contains(args[1])) {
sender.sendMessage(LocaleLoader.getString("Party.NotInYourParty", targetName)); sender.sendMessage(LocaleLoader.getString("Party.NotInYourParty", args[1]));
return true; return true;
} }
PartyManager.setPartyLeader(targetName, playerParty); PartyManager.setPartyLeader(args[1], playerParty);
return true; return true;
default: default:

View File

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

View File

@@ -20,10 +20,12 @@ import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.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 PartyCommand implements TabExecutor { public class PartyCommand implements TabExecutor {
private McMMOPlayer mcMMOPlayer;
private Player player;
private static final List<String> PARTY_SUBCOMMANDS; private static final List<String> PARTY_SUBCOMMANDS;
private static final List<String> EXPSHARE_COMPLETIONS = ImmutableList.of("none", "equal"); private static final List<String> EXPSHARE_COMPLETIONS = ImmutableList.of("none", "equal");
private static final List<String> ITEMSHARE_COMPLETIONS = ImmutableList.of("none", "equal", "random", "loot", "mining", "herbalism", "woodcutting", "misc"); private static final List<String> ITEMSHARE_COMPLETIONS = ImmutableList.of("none", "equal", "random", "loot", "mining", "herbalism", "woodcutting", "misc");
@@ -68,13 +70,13 @@ public class PartyCommand implements TabExecutor {
return true; return true;
} }
Player player = (Player) sender; player = (Player) sender;
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); mcMMOPlayer = UserManager.getPlayer(player);
if (args.length < 1) { if (args.length < 1) {
if (!mcMMOPlayer.inParty()) { if (!mcMMOPlayer.inParty()) {
sender.sendMessage(LocaleLoader.getString("Commands.Party.None")); sender.sendMessage(LocaleLoader.getString("Commands.Party.None"));
return printUsage(player); return printUsage();
} }
return partyInfoCommand.onCommand(sender, command, label, args); return partyInfoCommand.onCommand(sender, command, label, args);
@@ -83,7 +85,7 @@ public class PartyCommand implements TabExecutor {
PartySubcommandType subcommand = PartySubcommandType.getSubcommand(args[0]); PartySubcommandType subcommand = PartySubcommandType.getSubcommand(args[0]);
if (subcommand == null) { if (subcommand == null) {
return printUsage(player); return printUsage();
} }
// Can't use this for lock/unlock since they're handled by the same command // Can't use this for lock/unlock since they're handled by the same command
@@ -108,7 +110,7 @@ public class PartyCommand implements TabExecutor {
// Party member commands // Party member commands
if (!mcMMOPlayer.inParty()) { if (!mcMMOPlayer.inParty()) {
sender.sendMessage(LocaleLoader.getString("Commands.Party.None")); sender.sendMessage(LocaleLoader.getString("Commands.Party.None"));
return printUsage(player); return printUsage();
} }
switch (subcommand) { switch (subcommand) {
@@ -174,7 +176,7 @@ public class PartyCommand implements TabExecutor {
case INVITE: case INVITE:
case KICK: case KICK:
case OWNER: case OWNER:
Set<String> playerNames = UserManager.getPlayerNames(); Set<String> playerNames = UserManager.getPlayers().keySet();
return StringUtil.copyPartialMatches(args[1], playerNames, new ArrayList<String>(playerNames.size())); return StringUtil.copyPartialMatches(args[1], playerNames, new ArrayList<String>(playerNames.size()));
case EXPSHARE: case EXPSHARE:
return StringUtil.copyPartialMatches(args[1], EXPSHARE_COMPLETIONS, new ArrayList<String>(EXPSHARE_COMPLETIONS.size())); return StringUtil.copyPartialMatches(args[1], EXPSHARE_COMPLETIONS, new ArrayList<String>(EXPSHARE_COMPLETIONS.size()));
@@ -189,7 +191,7 @@ public class PartyCommand implements TabExecutor {
List<String> matches = StringUtil.copyPartialMatches(args[1], PtpCommand.TELEPORT_SUBCOMMANDS, new ArrayList<String>(PtpCommand.TELEPORT_SUBCOMMANDS.size())); List<String> matches = StringUtil.copyPartialMatches(args[1], PtpCommand.TELEPORT_SUBCOMMANDS, new ArrayList<String>(PtpCommand.TELEPORT_SUBCOMMANDS.size()));
if (matches.size() == 0) { if (matches.size() == 0) {
playerNames = UserManager.getPlayerNames(); playerNames = UserManager.getPlayers().keySet();
return StringUtil.copyPartialMatches(args[1], playerNames, new ArrayList<String>(playerNames.size())); return StringUtil.copyPartialMatches(args[1], playerNames, new ArrayList<String>(playerNames.size()));
} }
@@ -208,7 +210,7 @@ public class PartyCommand implements TabExecutor {
} }
} }
private boolean printUsage(Player player) { private boolean printUsage() {
player.sendMessage(LocaleLoader.getString("Party.Help.0", "/party join")); player.sendMessage(LocaleLoader.getString("Party.Help.0", "/party join"));
player.sendMessage(LocaleLoader.getString("Party.Help.1", "/party create")); player.sendMessage(LocaleLoader.getString("Party.Help.1", "/party create"));
player.sendMessage(LocaleLoader.getString("Party.Help.2", "/party ?")); player.sendMessage(LocaleLoader.getString("Party.Help.2", "/party ?"));

View File

@@ -5,6 +5,7 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.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;
@@ -16,20 +17,22 @@ public class PartyCreateCommand implements CommandExecutor {
switch (args.length) { switch (args.length) {
case 2: case 2:
case 3: case 3:
Party newParty = PartyManager.getParty(args[1]);
Player player = (Player) sender; Player player = (Player) sender;
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
// Check to see if the party exists, and if it does cancel creating a new party // Check to see if the party exists, and if it does cancel creating a new party
if (PartyManager.checkPartyExistence(player, args[1])) { if (PartyManager.checkPartyExistence(player, newParty, args[1])) {
return true; return true;
} }
// Changing parties // Changing parties
if (!PartyManager.changeOrJoinParty(mcMMOPlayer, args[1])) { if (!PartyManager.changeOrJoinParty(mcMMOPlayer, player, mcMMOPlayer.getParty(), args[1])) {
return true; return true;
} }
PartyManager.createParty(mcMMOPlayer, args[1], getPassword(args)); PartyManager.createParty(player, mcMMOPlayer, args[1], getPassword(args));
return true; return true;
default: default:

View File

@@ -7,13 +7,16 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.party.Party; import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.datatypes.party.ShareMode;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.ShareHandler;
import com.gmail.nossr50.party.ShareHandler.ShareMode;
import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.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.player.UserManager;
public class PartyExpShareCommand implements CommandExecutor { public class PartyExpShareCommand implements CommandExecutor {
private Party playerParty;
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!Config.getInstance().getExpShareEnabled()) { if (!Config.getInstance().getExpShareEnabled()) {
@@ -23,13 +26,13 @@ public class PartyExpShareCommand implements CommandExecutor {
switch (args.length) { switch (args.length) {
case 2: case 2:
Party party = UserManager.getPlayer((Player) sender).getParty(); playerParty = UserManager.getPlayer((Player) sender).getParty();
if (args[1].equalsIgnoreCase("none") || CommandUtils.shouldDisableToggle(args[1])) { if (args[1].equalsIgnoreCase("none") || CommandUtils.shouldDisableToggle(args[1])) {
handleChangingShareMode(party, ShareMode.NONE); handleChangingShareMode(ShareMode.NONE);
} }
else if (args[1].equalsIgnoreCase("equal") || args[1].equalsIgnoreCase("even") || CommandUtils.shouldEnableToggle(args[1])) { else if (args[1].equalsIgnoreCase("equal") || args[1].equalsIgnoreCase("even") || CommandUtils.shouldEnableToggle(args[1])) {
handleChangingShareMode(party, ShareMode.EQUAL); handleChangingShareMode(ShareMode.EQUAL);
} }
else { else {
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "expshare", "<NONE | EQUAL>")); sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "expshare", "<NONE | EQUAL>"));
@@ -43,12 +46,12 @@ public class PartyExpShareCommand implements CommandExecutor {
} }
} }
private void handleChangingShareMode(Party party, ShareMode mode) { private void handleChangingShareMode(ShareHandler.ShareMode mode) {
party.setXpShareMode(mode); playerParty.setXpShareMode(mode);
String changeModeMessage = LocaleLoader.getString("Commands.Party.SetSharing", LocaleLoader.getString("Party.ShareType.Exp"), LocaleLoader.getString("Party.ShareMode." + StringUtils.getCapitalized(mode.toString()))); String changeModeMessage = LocaleLoader.getString("Commands.Party.SetSharing", LocaleLoader.getString("Party.ShareType.Exp"), LocaleLoader.getString("Party.ShareMode." + StringUtils.getCapitalized(mode.toString())));
for (Player member : party.getOnlineMembers()) { for (Player member : playerParty.getOnlineMembers()) {
member.sendMessage(changeModeMessage); member.sendMessage(changeModeMessage);
} }
} }

View File

@@ -1,6 +1,7 @@
package com.gmail.nossr50.commands.party; package com.gmail.nossr50.commands.party;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@@ -9,43 +10,45 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.party.Party; import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.datatypes.party.ShareMode;
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.party.ShareHandler;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
public class PartyInfoCommand implements CommandExecutor { public class PartyInfoCommand implements CommandExecutor {
private Player player;
private Party playerParty;
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) { switch (args.length) {
case 0: case 0:
case 1: case 1:
Player player = (Player) sender; player = (Player) sender;
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
Party party = mcMMOPlayer.getParty(); playerParty = mcMMOPlayer.getParty();
displayPartyHeader(player, party); displayPartyHeader();
displayShareModeInfo(party, player); displayShareModeInfo();
displayMemberInfo(player, mcMMOPlayer, party); displayMemberInfo();
return true; return true;
default: default:
sender.sendMessage(LocaleLoader.getString("Commands.Usage.1", "party", "info")); sender.sendMessage(LocaleLoader.getString("Commands.Usage.1", "party", "info"));
return true; return true;
} }
} }
private String createMembersList(Party party) { private String createMembersList() {
StringBuilder memberList = new StringBuilder(); StringBuilder memberList = new StringBuilder();
for (String memberName : party.getMembers()) { for (String memberName : playerParty.getMembers()) {
Player member = mcMMO.p.getServer().getPlayerExact(memberName); OfflinePlayer member = mcMMO.p.getServer().getOfflinePlayer(memberName);
if (party.getLeader().equalsIgnoreCase(memberName)) { if (playerParty.getLeader().equalsIgnoreCase(memberName)) {
memberList.append(ChatColor.GOLD); memberList.append(ChatColor.GOLD);
} }
else if (member != null) { else if (member.isOnline()) {
memberList.append(ChatColor.WHITE); memberList.append(ChatColor.WHITE);
} }
else { else {
@@ -58,10 +61,10 @@ public class PartyInfoCommand implements CommandExecutor {
return memberList.toString(); return memberList.toString();
} }
private void displayShareModeInfo(Party party, Player player) { private void displayShareModeInfo() {
boolean xpShareEnabled = Config.getInstance().getExpShareEnabled(); boolean xpShareEnabled = Config.getInstance().getExpShareEnabled();
boolean itemShareEnabled = Config.getInstance().getItemShareEnabled(); boolean itemShareEnabled = Config.getInstance().getItemShareEnabled();
boolean itemSharingActive = (party.getItemShareMode() != ShareMode.NONE); boolean itemSharingActive = (playerParty.getItemShareMode() != ShareHandler.ShareMode.NONE);
if (!xpShareEnabled && !itemShareEnabled) { if (!xpShareEnabled && !itemShareEnabled) {
return; return;
@@ -72,11 +75,11 @@ public class PartyInfoCommand implements CommandExecutor {
String separator = ""; String separator = "";
if (xpShareEnabled) { if (xpShareEnabled) {
expShareInfo = LocaleLoader.getString("Commands.Party.ExpShare", party.getXpShareMode().toString()); expShareInfo = LocaleLoader.getString("Commands.Party.ExpShare", playerParty.getXpShareMode().toString());
} }
if (itemShareEnabled) { if (itemShareEnabled) {
itemShareInfo = LocaleLoader.getString("Commands.Party.ItemShare", party.getItemShareMode().toString()); itemShareInfo = LocaleLoader.getString("Commands.Party.ItemShare", playerParty.getItemShareMode().toString());
} }
if (xpShareEnabled && itemShareEnabled) { if (xpShareEnabled && itemShareEnabled) {
@@ -84,23 +87,28 @@ public class PartyInfoCommand implements CommandExecutor {
} }
player.sendMessage(LocaleLoader.getString("Commands.Party.ShareMode") + expShareInfo + separator + itemShareInfo); player.sendMessage(LocaleLoader.getString("Commands.Party.ShareMode") + expShareInfo + separator + itemShareInfo);
if (itemSharingActive) { if (itemSharingActive) {
player.sendMessage(LocaleLoader.getString("Commands.Party.ItemShareCategories", party.getItemShareCategories())); player.sendMessage(LocaleLoader.getString("Commands.Party.ItemShareCategories", playerParty.getItemShareCategories()));
} }
} }
private void displayPartyHeader(Player player, Party party) { private void displayPartyHeader() {
player.sendMessage(LocaleLoader.getString("Commands.Party.Header")); player.sendMessage(LocaleLoader.getString("Commands.Party.Header"));
player.sendMessage(LocaleLoader.getString("Commands.Party.Status", party.getName(), LocaleLoader.getString("Party.Status." + (party.isLocked() ? "Locked" : "Unlocked"))));
if (playerParty.isLocked()) {
player.sendMessage(LocaleLoader.getString("Commands.Party.Status", playerParty.getName(), LocaleLoader.getString("Party.Status.Locked")));
}
else {
player.sendMessage(LocaleLoader.getString("Commands.Party.Status", playerParty.getName(), LocaleLoader.getString("Party.Status.Unlocked")));
}
} }
private void displayMemberInfo(Player player, McMMOPlayer mcMMOPlayer, Party party) { private void displayMemberInfo() {
int membersNear = PartyManager.getNearMembers(mcMMOPlayer).size(); int membersNear = PartyManager.getNearMembers(player, playerParty, Config.getInstance().getPartyShareRange()).size();
int membersOnline = party.getOnlineMembers().size() - 1; int membersOnline = playerParty.getOnlineMembers().size() - 1;
player.sendMessage(LocaleLoader.getString("Commands.Party.Members.Header")); player.sendMessage(LocaleLoader.getString("Commands.Party.Members.Header"));
player.sendMessage(LocaleLoader.getString("Commands.Party.MembersNear", membersNear, membersOnline)); player.sendMessage(LocaleLoader.getString("Commands.Party.MembersNear", membersNear, membersOnline));
player.sendMessage(createMembersList(party)); player.sendMessage(createMembersList());
} }
} }

View File

@@ -9,7 +9,6 @@ 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;
@@ -18,17 +17,15 @@ public class PartyInviteCommand implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) { switch (args.length) {
case 2: case 2:
String targetName = Misc.getMatchedPlayerName(args[1]); McMMOPlayer mcMMOTarget = UserManager.getPlayer(args[1]);
McMMOPlayer mcMMOTarget = UserManager.getPlayer(targetName, true);
if (!CommandUtils.checkPlayerExistence(sender, targetName, mcMMOTarget)) { if (!CommandUtils.checkPlayerExistence(sender, args[1], mcMMOTarget)) {
return false; return false;
} }
Player target = mcMMOTarget.getPlayer(); 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();
if (player.equals(target)) { if (player.equals(target)) {
sender.sendMessage(LocaleLoader.getString("Party.Invite.Self")); sender.sendMessage(LocaleLoader.getString("Party.Invite.Self"));
@@ -36,20 +33,21 @@ public class PartyInviteCommand implements CommandExecutor {
} }
if (PartyManager.inSameParty(player, target)) { if (PartyManager.inSameParty(player, target)) {
sender.sendMessage(LocaleLoader.getString("Party.Player.InSameParty", targetName)); sender.sendMessage(LocaleLoader.getString("Party.Player.InSameParty", target.getName()));
return true;
}
if (!PartyManager.canInvite(mcMMOPlayer)) {
player.sendMessage(LocaleLoader.getString("Party.Locked"));
return true; return true;
} }
Party playerParty = mcMMOPlayer.getParty(); Party playerParty = mcMMOPlayer.getParty();
if (!PartyManager.canInvite(player, playerParty)) {
player.sendMessage(LocaleLoader.getString("Party.Locked"));
return true;
}
mcMMOTarget.setPartyInvite(playerParty); mcMMOTarget.setPartyInvite(playerParty);
sender.sendMessage(LocaleLoader.getString("Commands.Invite.Success")); sender.sendMessage(LocaleLoader.getString("Commands.Invite.Success"));
target.sendMessage(LocaleLoader.getString("Commands.Party.Invite.0", playerParty.getName(), playerName)); target.sendMessage(LocaleLoader.getString("Commands.Party.Invite.0", playerParty.getName(), player.getName()));
target.sendMessage(LocaleLoader.getString("Commands.Party.Invite.1")); target.sendMessage(LocaleLoader.getString("Commands.Party.Invite.1"));
return true; return true;

View File

@@ -8,13 +8,15 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.party.ItemShareType; import com.gmail.nossr50.datatypes.party.ItemShareType;
import com.gmail.nossr50.datatypes.party.Party; import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.datatypes.party.ShareMode;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.ShareHandler.ShareMode;
import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
public class PartyItemShareCommand implements CommandExecutor { public class PartyItemShareCommand implements CommandExecutor {
private Party playerParty;
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!Config.getInstance().getItemShareEnabled()) { if (!Config.getInstance().getItemShareEnabled()) {
@@ -22,10 +24,9 @@ public class PartyItemShareCommand implements CommandExecutor {
return true; return true;
} }
Party party = UserManager.getPlayer((Player) sender).getParty();
switch (args.length) { switch (args.length) {
case 2: case 2:
playerParty = UserManager.getPlayer((Player) sender).getParty();
ShareMode mode = ShareMode.getShareMode(args[1].toUpperCase()); ShareMode mode = ShareMode.getShareMode(args[1].toUpperCase());
if (mode == null) { if (mode == null) {
@@ -33,10 +34,11 @@ public class PartyItemShareCommand implements CommandExecutor {
return true; return true;
} }
handleChangingShareMode(party, mode); handleChangingShareMode(mode);
return true; return true;
case 3: case 3:
playerParty = UserManager.getPlayer((Player) sender).getParty();
boolean toggle = false; boolean toggle = false;
if (CommandUtils.shouldEnableToggle(args[2])) { if (CommandUtils.shouldEnableToggle(args[2])) {
@@ -51,7 +53,7 @@ public class PartyItemShareCommand implements CommandExecutor {
} }
try { try {
handleToggleItemShareCategory(party, ItemShareType.valueOf(args[1].toUpperCase()), toggle); handleToggleItemShareCategory(ItemShareType.valueOf(args[1].toUpperCase()), toggle);
} }
catch (IllegalArgumentException ex) { catch (IllegalArgumentException ex) {
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "<loot | mining | herbalism | woodcutting | misc> <true | false>")); sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "<loot | mining | herbalism | woodcutting | misc> <true | false>"));
@@ -66,22 +68,22 @@ public class PartyItemShareCommand implements CommandExecutor {
} }
} }
private void handleChangingShareMode(Party party, ShareMode mode) { private void handleChangingShareMode(ShareMode mode) {
party.setItemShareMode(mode); playerParty.setItemShareMode(mode);
String changeModeMessage = LocaleLoader.getString("Commands.Party.SetSharing", LocaleLoader.getString("Party.ShareType.Item"), LocaleLoader.getString("Party.ShareMode." + StringUtils.getCapitalized(mode.toString()))); String changeModeMessage = LocaleLoader.getString("Commands.Party.SetSharing", LocaleLoader.getString("Party.ShareType.Item"), LocaleLoader.getString("Party.ShareMode." + StringUtils.getCapitalized(mode.toString())));
for (Player member : party.getOnlineMembers()) { for (Player member : playerParty.getOnlineMembers()) {
member.sendMessage(changeModeMessage); member.sendMessage(changeModeMessage);
} }
} }
private void handleToggleItemShareCategory(Party party, ItemShareType type, boolean toggle) { private void handleToggleItemShareCategory(ItemShareType type, boolean toggle) {
party.setSharingDrops(type, toggle); playerParty.setSharingDrops(type, toggle);
String toggleMessage = LocaleLoader.getString("Commands.Party.ToggleShareCategory", StringUtils.getCapitalized(type.toString()), toggle ? "enabled" : "disabled"); String toggleMessage = LocaleLoader.getString("Commands.Party.ToggleShareCategory", StringUtils.getCapitalized(type.toString()), toggle ? "enabled" : "disabled");
for (Player member : party.getOnlineMembers()) { for (Player member : playerParty.getOnlineMembers()) {
member.sendMessage(toggleMessage); member.sendMessage(toggleMessage);
} }
} }

View File

@@ -9,38 +9,30 @@ 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 PartyJoinCommand implements CommandExecutor { public class PartyJoinCommand implements CommandExecutor {
private McMMOPlayer mcMMOTarget;
private Player target;
private Party targetParty;
private McMMOPlayer mcMMOPlayer;
private Player player;
private Party playerParty;
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) { switch (args.length) {
case 2: case 2:
case 3: case 3:
String targetName = Misc.getMatchedPlayerName(args[1]); // Verify target exists and is in a different party than the player
McMMOPlayer mcMMOTarget = UserManager.getPlayer(targetName); if (!canJoinParty(sender, args[1])) {
if (!CommandUtils.checkPlayerExistence(sender, targetName, mcMMOTarget)) {
return true; return true;
} }
Player target = mcMMOTarget.getPlayer(); mcMMOPlayer = UserManager.getPlayer((Player) sender);
player = mcMMOPlayer.getPlayer();
if (!mcMMOTarget.inParty()) {
sender.sendMessage(LocaleLoader.getString("Party.PlayerNotInParty", targetName));
return true;
}
Player player = (Player) sender;
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
Party targetParty = mcMMOTarget.getParty();
if (player.equals(target) || (mcMMOPlayer.inParty() && mcMMOPlayer.getParty().equals(targetParty))) {
sender.sendMessage(LocaleLoader.getString("Party.Join.Self"));
return true;
}
String password = getPassword(args); String password = getPassword(args);
@@ -49,15 +41,12 @@ public class PartyJoinCommand implements CommandExecutor {
return true; return true;
} }
String partyName = targetParty.getName();
// Changing parties // Changing parties
if (!PartyManager.changeOrJoinParty(mcMMOPlayer, partyName)) { if (!PartyManager.changeOrJoinParty(mcMMOPlayer, player, playerParty, targetParty.getName())) {
return true; return true;
} }
player.sendMessage(LocaleLoader.getString("Commands.Party.Join", partyName)); PartyManager.joinParty(player, mcMMOPlayer, targetParty, password);
PartyManager.addToParty(mcMMOPlayer, targetParty);
return true; return true;
default: default:
@@ -73,4 +62,32 @@ public class PartyJoinCommand implements CommandExecutor {
return null; return null;
} }
private boolean canJoinParty(CommandSender sender, String targetName) {
mcMMOTarget = UserManager.getPlayer(targetName);
if (!CommandUtils.checkPlayerExistence(sender, targetName, mcMMOTarget)) {
return false;
}
target = mcMMOTarget.getPlayer();
if (!mcMMOTarget.inParty()) {
sender.sendMessage(LocaleLoader.getString("Party.PlayerNotInParty", targetName));
return false;
}
player = (Player) sender;
mcMMOPlayer = UserManager.getPlayer(player);
playerParty = mcMMOPlayer.getParty();
targetParty = mcMMOTarget.getParty();
if (player.equals(target) || (mcMMOPlayer.inParty() && playerParty.equals(targetParty))) {
sender.sendMessage(LocaleLoader.getString("Party.Join.Self"));
return false;
}
return true;
}
} }

View File

@@ -22,7 +22,7 @@ public class PartyKickCommand implements CommandExecutor {
OfflinePlayer target = mcMMO.p.getServer().getOfflinePlayer(args[1]); OfflinePlayer target = mcMMO.p.getServer().getOfflinePlayer(args[1]);
if (!playerParty.getMembers().contains(target.getName())) { if (!playerParty.getMembers().contains(target.getName())) {
sender.sendMessage(LocaleLoader.getString("Party.NotInYourParty", target.getName())); sender.sendMessage(LocaleLoader.getString("Party.NotInYourParty", args[1]));
return true; return true;
} }
@@ -34,7 +34,6 @@ public class PartyKickCommand implements CommandExecutor {
return true; return true;
} }
PartyManager.processPartyLeaving(UserManager.getPlayer(onlineTarget));
onlineTarget.sendMessage(LocaleLoader.getString("Commands.Party.Kick", partyName)); onlineTarget.sendMessage(LocaleLoader.getString("Commands.Party.Kick", partyName));
} }

View File

@@ -12,15 +12,19 @@ import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
public class PartyLockCommand implements CommandExecutor { public class PartyLockCommand implements CommandExecutor {
private Party playerParty;
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
playerParty = UserManager.getPlayer((Player) sender).getParty();
switch (args.length) { switch (args.length) {
case 1: case 1:
if (args[0].equalsIgnoreCase("lock")) { if (args[0].equalsIgnoreCase("lock")) {
togglePartyLock(sender, true); lockParty(sender, command.getPermissionMessage());
} }
else if (args[0].equalsIgnoreCase("unlock")) { else if (args[0].equalsIgnoreCase("unlock")) {
togglePartyLock(sender, false); unlockParty(sender, command.getPermissionMessage());
} }
return true; return true;
@@ -32,10 +36,10 @@ public class PartyLockCommand implements CommandExecutor {
} }
if (CommandUtils.shouldEnableToggle(args[1])) { if (CommandUtils.shouldEnableToggle(args[1])) {
togglePartyLock(sender, true); lockParty(sender, command.getPermissionMessage());
} }
else if (CommandUtils.shouldDisableToggle(args[1])) { else if (CommandUtils.shouldDisableToggle(args[1])) {
togglePartyLock(sender, false); unlockParty(sender, command.getPermissionMessage());
} }
else { else {
sendUsageStrings(sender); sendUsageStrings(sender);
@@ -49,25 +53,46 @@ public class PartyLockCommand implements CommandExecutor {
} }
} }
/**
* Handle locking a party.
*/
private void lockParty(CommandSender sender, String permissionMessage) {
if (!Permissions.partySubcommand(sender, PartySubcommandType.LOCK)) {
sender.sendMessage(permissionMessage);
return;
}
if (playerParty.isLocked()) {
sender.sendMessage(LocaleLoader.getString("Party.IsLocked"));
return;
}
playerParty.setLocked(true);
sender.sendMessage(LocaleLoader.getString("Party.Locked"));
}
/**
* Handle unlocking a party.
*
* @return true if party is successfully unlocked, false otherwise.
*/
private void unlockParty(CommandSender sender, String permissionMessage) {
if (!Permissions.partySubcommand(sender, PartySubcommandType.UNLOCK)) {
sender.sendMessage(permissionMessage);
return;
}
if (!playerParty.isLocked()) {
sender.sendMessage(LocaleLoader.getString("Party.IsntLocked"));
return;
}
playerParty.setLocked(false);
sender.sendMessage(LocaleLoader.getString("Party.Unlocked"));
}
private void sendUsageStrings(CommandSender sender) { private void sendUsageStrings(CommandSender sender) {
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "lock", "[on|off]")); sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "lock", "[on|off]"));
sender.sendMessage(LocaleLoader.getString("Commands.Usage.1", "party", "unlock")); sender.sendMessage(LocaleLoader.getString("Commands.Usage.1", "party", "unlock"));
} }
private void togglePartyLock(CommandSender sender, boolean lock) {
Party party = UserManager.getPlayer((Player) sender).getParty();
if (!Permissions.partySubcommand(sender, lock ? PartySubcommandType.LOCK : PartySubcommandType.UNLOCK)) {
sender.sendMessage(LocaleLoader.getString("mcMMO.NoPermission"));
return;
}
if (lock ? party.isLocked() : !party.isLocked()) {
sender.sendMessage(LocaleLoader.getString("Party." + (lock ? "IsLocked" : "IsntLocked")));
return;
}
party.setLocked(lock);
sender.sendMessage(LocaleLoader.getString("Party." + (lock ? "Locked" : "Unlocked")));
}
} }

View File

@@ -6,7 +6,6 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.party.Party; import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason; import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;
@@ -18,14 +17,13 @@ public class PartyQuitCommand implements CommandExecutor {
switch (args.length) { switch (args.length) {
case 1: case 1:
Player player = (Player) sender; Player player = (Player) sender;
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); Party playerParty = UserManager.getPlayer(player).getParty();
Party playerParty = mcMMOPlayer.getParty();
if (!PartyManager.handlePartyChangeEvent(player, playerParty.getName(), null, EventReason.LEFT_PARTY)) { if (!PartyManager.handlePartyChangeEvent(player, playerParty.getName(), null, EventReason.LEFT_PARTY)) {
return true; return true;
} }
PartyManager.removeFromParty(mcMMOPlayer); PartyManager.removeFromParty(player, playerParty);
sender.sendMessage(LocaleLoader.getString("Commands.Party.Leave")); sender.sendMessage(LocaleLoader.getString("Commands.Party.Leave"));
return true; return true;

View File

@@ -30,9 +30,10 @@ public class PartyRenameCommand implements CommandExecutor {
} }
Player player = mcMMOPlayer.getPlayer(); Player player = mcMMOPlayer.getPlayer();
Party newParty = PartyManager.getParty(newPartyName);
// Check to see if the party exists, and if it does cancel renaming the party // Check to see if the party exists, and if it does cancel renaming the party
if (PartyManager.checkPartyExistence(player, newPartyName)) { if (PartyManager.checkPartyExistence(player, newParty, newPartyName)) {
return true; return true;
} }

View File

@@ -3,8 +3,9 @@ package com.gmail.nossr50.commands.party.teleport;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.party.PartyTeleportRecord; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
@@ -17,16 +18,17 @@ public class PtpAcceptAnyCommand implements CommandExecutor {
return true; return true;
} }
PartyTeleportRecord ptpRecord = UserManager.getPlayer(sender.getName()).getPartyTeleportRecord(); Player player = (Player) sender;
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
if (ptpRecord.isConfirmRequired()) { if (mcMMOPlayer.getPtpConfirmRequired()) {
sender.sendMessage(LocaleLoader.getString("Commands.ptp.AcceptAny.Disabled")); player.sendMessage(LocaleLoader.getString("Commands.ptp.AcceptAny.Disabled"));
} }
else { else {
sender.sendMessage(LocaleLoader.getString("Commands.ptp.AcceptAny.Enabled")); player.sendMessage(LocaleLoader.getString("Commands.ptp.AcceptAny.Enabled"));
} }
ptpRecord.toggleConfirmRequired(); mcMMOPlayer.togglePtpConfirmRequired();
return true; return true;
} }
} }

View File

@@ -7,7 +7,7 @@ import org.bukkit.command.CommandSender;
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.party.PartyTeleportRecord; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
@@ -22,21 +22,21 @@ public class PtpAcceptCommand implements CommandExecutor {
} }
Player player = (Player) sender; Player player = (Player) sender;
PartyTeleportRecord ptpRecord = UserManager.getPlayer(player).getPartyTeleportRecord(); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
if (!ptpRecord.hasRequest()) { if (!mcMMOPlayer.hasPtpRequest()) {
player.sendMessage(LocaleLoader.getString("Commands.ptp.NoRequests")); player.sendMessage(LocaleLoader.getString("Commands.ptp.NoRequests"));
return true; return true;
} }
if ((ptpRecord.getTimeout() + Config.getInstance().getPTPCommandTimeout()) * Misc.TIME_CONVERSION_FACTOR < System.currentTimeMillis()) { if ((mcMMOPlayer.getPtpTimeout() + Config.getInstance().getPTPCommandTimeout()) * Misc.TIME_CONVERSION_FACTOR < System.currentTimeMillis()) {
ptpRecord.removeRequest(); mcMMOPlayer.removePtpRequest();
player.sendMessage(LocaleLoader.getString("Commands.ptp.RequestExpired")); player.sendMessage(LocaleLoader.getString("Commands.ptp.RequestExpired"));
return true; return true;
} }
Player target = ptpRecord.getRequestor(); Player target = mcMMOPlayer.getPtpRequest();
ptpRecord.removeRequest(); mcMMOPlayer.removePtpRequest();
if (!PtpCommand.canTeleport(sender, player, target.getName())) { if (!PtpCommand.canTeleport(sender, player, target.getName())) {
return true; return true;

View File

@@ -13,21 +13,22 @@ 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.party.PartyTeleportRecord;
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;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.skills.SkillUtils; import com.gmail.nossr50.util.skills.SkillUtils;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
public class PtpCommand implements TabExecutor { public class PtpCommand implements TabExecutor {
private static Player target;
private static McMMOPlayer mcMMOTarget;
public static final List<String> TELEPORT_SUBCOMMANDS = ImmutableList.of("toggle", "accept", "acceptany", "acceptall"); public static final List<String> TELEPORT_SUBCOMMANDS = ImmutableList.of("toggle", "accept", "acceptany", "acceptall");
private CommandExecutor ptpToggleCommand = new PtpToggleCommand(); private CommandExecutor ptpToggleCommand = new PtpToggleCommand();
@@ -75,10 +76,10 @@ public class PtpCommand implements TabExecutor {
} }
int ptpCooldown = Config.getInstance().getPTPCommandCooldown(); int ptpCooldown = Config.getInstance().getPTPCommandCooldown();
long ptpLastUse = mcMMOPlayer.getPartyTeleportRecord().getLastUse(); long lastTeleport = mcMMOPlayer.getLastTeleport();
if (ptpCooldown > 0) { if (ptpCooldown > 0) {
int timeRemaining = SkillUtils.calculateTimeLeft(ptpLastUse * Misc.TIME_CONVERSION_FACTOR, ptpCooldown, player); int timeRemaining = SkillUtils.calculateTimeLeft(lastTeleport * Misc.TIME_CONVERSION_FACTOR, ptpCooldown, player);
if (timeRemaining > 0) { if (timeRemaining > 0) {
player.sendMessage(LocaleLoader.getString("Item.Generic.Wait", timeRemaining)); player.sendMessage(LocaleLoader.getString("Item.Generic.Wait", timeRemaining));
@@ -86,7 +87,7 @@ public class PtpCommand implements TabExecutor {
} }
} }
sendTeleportRequest(sender, player, Misc.getMatchedPlayerName(args[0])); sendTeleportRequest(sender, player, args[0]);
return true; return true;
default: default:
@@ -101,7 +102,7 @@ public class PtpCommand implements TabExecutor {
List<String> matches = StringUtil.copyPartialMatches(args[0], TELEPORT_SUBCOMMANDS, new ArrayList<String>(TELEPORT_SUBCOMMANDS.size())); List<String> matches = StringUtil.copyPartialMatches(args[0], TELEPORT_SUBCOMMANDS, new ArrayList<String>(TELEPORT_SUBCOMMANDS.size()));
if (matches.size() == 0) { if (matches.size() == 0) {
Set<String> playerNames = UserManager.getPlayerNames(); Set<String> playerNames = UserManager.getPlayers().keySet();
return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList<String>(playerNames.size())); return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList<String>(playerNames.size()));
} }
@@ -116,18 +117,13 @@ public class PtpCommand implements TabExecutor {
return; return;
} }
McMMOPlayer mcMMOTarget = UserManager.getPlayer(targetName); if (!mcMMOTarget.getPtpConfirmRequired()) {
Player target = mcMMOTarget.getPlayer();
PartyTeleportRecord ptpRecord = mcMMOTarget.getPartyTeleportRecord();
if (!ptpRecord.isConfirmRequired()) {
handleTeleportWarmup(player, target); handleTeleportWarmup(player, target);
return; return;
} }
ptpRecord.setRequestor(player); mcMMOTarget.setPtpRequest(player);
ptpRecord.actualizeTimeout(); mcMMOTarget.actualizePtpTimeout();
player.sendMessage(LocaleLoader.getString("Commands.Invite.Success")); player.sendMessage(LocaleLoader.getString("Commands.Invite.Success"));
@@ -136,13 +132,14 @@ public class PtpCommand implements TabExecutor {
} }
protected static boolean canTeleport(CommandSender sender, Player player, String targetName) { protected static boolean canTeleport(CommandSender sender, Player player, String targetName) {
McMMOPlayer mcMMOTarget = UserManager.getPlayer(targetName); mcMMOTarget = UserManager.getPlayer(targetName);
if (!CommandUtils.checkPlayerExistence(sender, targetName, mcMMOTarget)) { if (!CommandUtils.checkPlayerExistence(sender, targetName, mcMMOTarget)) {
return false; return false;
} }
Player target = mcMMOTarget.getPlayer(); target = mcMMOTarget.getPlayer();
targetName = target.getName();
if (player.equals(target)) { if (player.equals(target)) {
player.sendMessage(LocaleLoader.getString("Party.Teleport.Self")); player.sendMessage(LocaleLoader.getString("Party.Teleport.Self"));
@@ -154,7 +151,7 @@ public class PtpCommand implements TabExecutor {
return false; return false;
} }
if (!mcMMOTarget.getPartyTeleportRecord().isEnabled()) { if (!mcMMOTarget.getPtpEnabled()) {
player.sendMessage(LocaleLoader.getString("Party.Teleport.Disabled", targetName)); player.sendMessage(LocaleLoader.getString("Party.Teleport.Disabled", targetName));
return false; return false;
} }
@@ -169,7 +166,7 @@ public class PtpCommand implements TabExecutor {
protected static void handleTeleportWarmup(Player teleportingPlayer, Player targetPlayer) { protected static void handleTeleportWarmup(Player teleportingPlayer, Player targetPlayer) {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(teleportingPlayer); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(teleportingPlayer);
McMMOPlayer mcMMOTarget = UserManager.getPlayer(targetPlayer); mcMMOTarget = UserManager.getPlayer(targetPlayer);
long warmup = Config.getInstance().getPTPCommandWarmup(); long warmup = Config.getInstance().getPTPCommandWarmup();
@@ -180,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.actualizeRecentlyHurt();
}
} }

View File

@@ -3,8 +3,9 @@ package com.gmail.nossr50.commands.party.teleport;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.party.PartyTeleportRecord; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
@@ -17,16 +18,17 @@ public class PtpToggleCommand implements CommandExecutor {
return true; return true;
} }
PartyTeleportRecord ptpRecord = UserManager.getPlayer(sender.getName()).getPartyTeleportRecord(); Player player = (Player) sender;
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
if (ptpRecord.isEnabled()) { if (mcMMOPlayer.getPtpEnabled()) {
sender.sendMessage(LocaleLoader.getString("Commands.ptp.Disabled")); player.sendMessage(LocaleLoader.getString("Commands.ptp.Disabled"));
} }
else { else {
sender.sendMessage(LocaleLoader.getString("Commands.ptp.Enabled")); player.sendMessage(LocaleLoader.getString("Commands.ptp.Enabled"));
} }
ptpRecord.toggleEnabled(); mcMMOPlayer.togglePtpUse();
return true; return true;
} }
} }

View File

@@ -10,13 +10,11 @@ import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player; 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.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.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;
@@ -29,42 +27,44 @@ 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:
String playerName = Misc.getMatchedPlayerName(args[0]); if (sender instanceof Player && Config.getInstance().getInspectScoreboardEnabled()) {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(playerName, true); ScoreboardManager.setupPlayerScoreboard(sender.getName());
}
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(args[0]);
// If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process. // If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
if (mcMMOPlayer == null) { if (mcMMOPlayer == null) {
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(playerName, false); // Temporary Profile PlayerProfile profile = new PlayerProfile(args[0], false); // Temporary Profile
if (CommandUtils.inspectOffline(sender, profile, Permissions.inspectOffline(sender))) { if (CommandUtils.inspectOffline(sender, profile, Permissions.inspectOffline(sender))) {
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", args[0]));
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 +79,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()));
@@ -105,7 +102,7 @@ public class InspectCommand 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:
Set<String> playerNames = UserManager.getPlayerNames(); Set<String> playerNames = UserManager.getPlayers().keySet();
return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList<String>(playerNames.size())); return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList<String>(playerNames.size()));
default: default:
return ImmutableList.of(); return ImmutableList.of();

View File

@@ -1,70 +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,13 +13,12 @@ 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.datatypes.player.PlayerProfile;
import com.gmail.nossr50.runnables.commands.McrankCommandAsyncTask; import com.gmail.nossr50.runnables.commands.McrankCommandAsyncTask;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.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 {
@@ -36,7 +35,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;
@@ -46,22 +51,27 @@ public class McrankCommand implements TabExecutor {
return true; return true;
} }
String playerName = Misc.getMatchedPlayerName(args[0]); String playerName = args[0];
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(playerName, true); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(playerName);
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;
} }
} }
else if (CommandUtils.inspectOffline(sender, mcMMO.getDatabaseManager().loadPlayerProfile(playerName, false), Permissions.mcrankOffline(sender))) { else if (CommandUtils.inspectOffline(sender, new PlayerProfile(playerName, false), Permissions.mcrankOffline(sender))) {
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:
@@ -73,7 +83,7 @@ public class McrankCommand 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:
Set<String> playerNames = UserManager.getPlayerNames(); Set<String> playerNames = UserManager.getPlayers().keySet();
return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList<String>(playerNames.size())); return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList<String>(playerNames.size()));
default: default:
return ImmutableList.of(); return ImmutableList.of();
@@ -81,20 +91,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,11 +8,11 @@ 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;
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 McstatsCommand implements TabExecutor { public class McstatsCommand implements TabExecutor {
@@ -25,29 +25,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,41 +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:
@@ -53,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:
@@ -77,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,10 +1,5 @@
package com.gmail.nossr50.commands.skills; package com.gmail.nossr50.commands.skills;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.entity.Player;
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.acrobatics.Acrobatics; import com.gmail.nossr50.skills.acrobatics.Acrobatics;
@@ -27,71 +22,75 @@ public class AcrobaticsCommand extends SkillCommand {
} }
@Override @Override
protected void dataCalculations(Player player, float skillValue, boolean isLucky) { protected void dataCalculations() {
// DODGE // DODGE
if (canDodge) { if (canDodge) {
String[] dodgeStrings = calculateAbilityDisplayValues(skillValue, Acrobatics.dodgeMaxBonusLevel, Acrobatics.dodgeMaxChance, isLucky); String[] dodgeStrings = calculateAbilityDisplayValues(Acrobatics.dodgeMaxBonusLevel, Acrobatics.dodgeMaxChance);
dodgeChance = dodgeStrings[0]; dodgeChance = dodgeStrings[0];
dodgeChanceLucky = dodgeStrings[1]; dodgeChanceLucky = dodgeStrings[1];
} }
// ROLL // ROLL
if (canRoll) { if (canRoll) {
String[] rollStrings = calculateAbilityDisplayValues(skillValue, Acrobatics.rollMaxBonusLevel, Acrobatics.rollMaxChance, isLucky); String[] rollStrings = calculateAbilityDisplayValues(Acrobatics.rollMaxBonusLevel, Acrobatics.rollMaxChance);
rollChance = rollStrings[0]; rollChance = rollStrings[0];
rollChanceLucky = rollStrings[1]; rollChanceLucky = rollStrings[1];
} }
// GRACEFUL ROLL // GRACEFUL ROLL
if (canGracefulRoll) { if (canGracefulRoll) {
String[] gracefulRollStrings = calculateAbilityDisplayValues(skillValue, Acrobatics.gracefulRollMaxBonusLevel, Acrobatics.gracefulRollMaxChance, isLucky); String[] gracefulRollStrings = calculateAbilityDisplayValues(Acrobatics.gracefulRollMaxBonusLevel, Acrobatics.gracefulRollMaxChance);
gracefulRollChance = gracefulRollStrings[0]; gracefulRollChance = gracefulRollStrings[0];
gracefulRollChanceLucky = gracefulRollStrings[1]; gracefulRollChanceLucky = gracefulRollStrings[1];
} }
} }
@Override @Override
protected void permissionsCheck(Player player) { protected void permissionsCheck() {
canDodge = Permissions.dodge(player); canDodge = Permissions.dodge(player);
canRoll = Permissions.roll(player); canRoll = Permissions.roll(player);
canGracefulRoll = Permissions.gracefulRoll(player); canGracefulRoll = Permissions.gracefulRoll(player);
} }
@Override @Override
protected List<String> effectsDisplay() { protected boolean effectsHeaderPermissions() {
List<String> messages = new ArrayList<String>(); return canDodge || canGracefulRoll || canRoll;
if (canRoll) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Acrobatics.Effect.0"), LocaleLoader.getString("Acrobatics.Effect.1")));
}
if (canGracefulRoll) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Acrobatics.Effect.2"), LocaleLoader.getString("Acrobatics.Effect.3")));
}
if (canDodge) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Acrobatics.Effect.4"), LocaleLoader.getString("Acrobatics.Effect.5")));
}
return messages;
} }
@Override @Override
protected List<String> statsDisplay(Player player, float skillValue, boolean hasEndurance, boolean isLucky) { protected void effectsDisplay() {
List<String> messages = new ArrayList<String>(); luckyEffectsDisplay();
if (canRoll) { if (canRoll) {
messages.add(LocaleLoader.getString("Acrobatics.Roll.Chance", rollChance) + (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", rollChanceLucky) : "")); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Acrobatics.Effect.0"), LocaleLoader.getString("Acrobatics.Effect.1")));
} }
if (canGracefulRoll) { if (canGracefulRoll) {
messages.add(LocaleLoader.getString("Acrobatics.Roll.GraceChance", gracefulRollChance) + (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", gracefulRollChanceLucky) : "")); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Acrobatics.Effect.2"), LocaleLoader.getString("Acrobatics.Effect.3")));
} }
if (canDodge) { if (canDodge) {
messages.add(LocaleLoader.getString("Acrobatics.DodgeChance", dodgeChance) + (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", dodgeChanceLucky) : "")); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Acrobatics.Effect.4"), LocaleLoader.getString("Acrobatics.Effect.5")));
}
}
@Override
protected boolean statsHeaderPermissions() {
return canDodge || canGracefulRoll || canRoll;
}
@Override
protected void statsDisplay() {
if (canRoll) {
player.sendMessage(LocaleLoader.getString("Acrobatics.Roll.Chance", rollChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", rollChanceLucky) : ""));
} }
return messages; if (canGracefulRoll) {
player.sendMessage(LocaleLoader.getString("Acrobatics.Roll.GraceChance", gracefulRollChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", gracefulRollChanceLucky) : ""));
}
if (canDodge) {
player.sendMessage(LocaleLoader.getString("Acrobatics.DodgeChance", dodgeChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", dodgeChanceLucky) : ""));
}
} }
} }

View File

@@ -1,10 +1,5 @@
package com.gmail.nossr50.commands.skills; package com.gmail.nossr50.commands.skills;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.entity.Player;
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.archery.Archery; import com.gmail.nossr50.skills.archery.Archery;
@@ -26,7 +21,7 @@ public class ArcheryCommand extends SkillCommand {
} }
@Override @Override
protected void dataCalculations(Player player, float skillValue, boolean isLucky) { protected void dataCalculations() {
// SKILL SHOT // SKILL SHOT
if (canSkillShot) { if (canSkillShot) {
double bonus = (skillValue / Archery.skillShotIncreaseLevel) * Archery.skillShotIncreasePercentage; double bonus = (skillValue / Archery.skillShotIncreaseLevel) * Archery.skillShotIncreasePercentage;
@@ -35,61 +30,65 @@ public class ArcheryCommand extends SkillCommand {
// DAZE // DAZE
if (canDaze) { if (canDaze) {
String[] dazeStrings = calculateAbilityDisplayValues(skillValue, Archery.dazeMaxBonusLevel, Archery.dazeMaxBonus, isLucky); String[] dazeStrings = calculateAbilityDisplayValues(Archery.dazeMaxBonusLevel, Archery.dazeMaxBonus);
dazeChance = dazeStrings[0]; dazeChance = dazeStrings[0];
dazeChanceLucky = dazeStrings[1]; dazeChanceLucky = dazeStrings[1];
} }
// RETRIEVE // RETRIEVE
if (canRetrieve) { if (canRetrieve) {
String[] retrieveStrings = calculateAbilityDisplayValues(skillValue, Archery.retrieveMaxBonusLevel, Archery.retrieveMaxChance, isLucky); String[] retrieveStrings = calculateAbilityDisplayValues(Archery.retrieveMaxBonusLevel, Archery.retrieveMaxChance);
retrieveChance = retrieveStrings[0]; retrieveChance = retrieveStrings[0];
retrieveChanceLucky = retrieveStrings[1]; retrieveChanceLucky = retrieveStrings[1];
} }
} }
@Override @Override
protected void permissionsCheck(Player player) { protected void permissionsCheck() {
canSkillShot = Permissions.bonusDamage(player, skill); canSkillShot = Permissions.bonusDamage(player, skill);
canDaze = Permissions.daze(player); canDaze = Permissions.daze(player);
canRetrieve = Permissions.arrowRetrieval(player); canRetrieve = Permissions.arrowRetrieval(player);
} }
@Override @Override
protected List<String> effectsDisplay() { protected boolean effectsHeaderPermissions() {
List<String> messages = new ArrayList<String>(); return canSkillShot || canDaze || canRetrieve;
if (canSkillShot) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Archery.Effect.0"), LocaleLoader.getString("Archery.Effect.1")));
}
if (canDaze) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Archery.Effect.2"), LocaleLoader.getString("Archery.Effect.3", Archery.dazeModifier)));
}
if (canRetrieve) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Archery.Effect.4"), LocaleLoader.getString("Archery.Effect.5")));
}
return messages;
} }
@Override @Override
protected List<String> statsDisplay(Player player, float skillValue, boolean hasEndurance, boolean isLucky) { protected void effectsDisplay() {
List<String> messages = new ArrayList<String>(); luckyEffectsDisplay();
if (canSkillShot) { if (canSkillShot) {
messages.add(LocaleLoader.getString("Archery.Combat.SkillshotBonus", skillShotBonus)); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Archery.Effect.0"), LocaleLoader.getString("Archery.Effect.1")));
} }
if (canDaze) { if (canDaze) {
messages.add(LocaleLoader.getString("Archery.Combat.DazeChance", dazeChance) + (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", dazeChanceLucky) : "")); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Archery.Effect.2"), LocaleLoader.getString("Archery.Effect.3", Archery.dazeModifier)));
} }
if (canRetrieve) { if (canRetrieve) {
messages.add(LocaleLoader.getString("Archery.Combat.RetrieveChance", retrieveChance) + (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", retrieveChanceLucky) : "")); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Archery.Effect.4"), LocaleLoader.getString("Archery.Effect.5")));
}
}
@Override
protected boolean statsHeaderPermissions() {
return canSkillShot || canDaze || canRetrieve;
}
@Override
protected void statsDisplay() {
if (canSkillShot) {
player.sendMessage(LocaleLoader.getString("Archery.Combat.SkillshotBonus", skillShotBonus));
} }
return messages; if (canDaze) {
player.sendMessage(LocaleLoader.getString("Archery.Combat.DazeChance", dazeChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", dazeChanceLucky) : ""));
}
if (canRetrieve) {
player.sendMessage(LocaleLoader.getString("Archery.Combat.RetrieveChance", retrieveChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", retrieveChanceLucky) : ""));
}
} }
} }

View File

@@ -1,10 +1,5 @@
package com.gmail.nossr50.commands.skills; package com.gmail.nossr50.commands.skills;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.entity.Player;
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.axes.Axes; import com.gmail.nossr50.skills.axes.Axes;
@@ -13,8 +8,8 @@ import com.gmail.nossr50.util.Permissions;
public class AxesCommand extends SkillCommand { public class AxesCommand extends SkillCommand {
private String critChance; private String critChance;
private String critChanceLucky; private String critChanceLucky;
private double bonusDamage; private float bonusDamage;
private double impactDamage; private float impactDamage;
private String skullSplitterLength; private String skullSplitterLength;
private String skullSplitterLengthEndurance; private String skullSplitterLengthEndurance;
@@ -29,7 +24,7 @@ public class AxesCommand extends SkillCommand {
} }
@Override @Override
protected void dataCalculations(Player player, float skillValue, boolean isLucky) { protected void dataCalculations() {
// IMPACT // IMPACT
if (canImpact) { if (canImpact) {
impactDamage = 1 + (skillValue / Axes.impactIncreaseLevel); impactDamage = 1 + (skillValue / Axes.impactIncreaseLevel);
@@ -37,14 +32,14 @@ public class AxesCommand extends SkillCommand {
// SKULL SPLITTER // SKULL SPLITTER
if (canSkullSplitter) { if (canSkullSplitter) {
String[] skullSplitterStrings = calculateLengthDisplayValues(player, skillValue); String[] skullSplitterStrings = calculateLengthDisplayValues();
skullSplitterLength = skullSplitterStrings[0]; skullSplitterLength = skullSplitterStrings[0];
skullSplitterLengthEndurance = skullSplitterStrings[1]; skullSplitterLengthEndurance = skullSplitterStrings[1];
} }
// CRITICAL STRIKES // CRITICAL STRIKES
if (canCritical) { if (canCritical) {
String[] criticalStrikeStrings = calculateAbilityDisplayValues(skillValue, Axes.criticalHitMaxBonusLevel, Axes.criticalHitMaxChance, isLucky); String[] criticalStrikeStrings = calculateAbilityDisplayValues(Axes.criticalHitMaxBonusLevel, Axes.criticalHitMaxChance);
critChance = criticalStrikeStrings[0]; critChance = criticalStrikeStrings[0];
critChanceLucky = criticalStrikeStrings[1]; critChanceLucky = criticalStrikeStrings[1];
} }
@@ -56,7 +51,7 @@ public class AxesCommand extends SkillCommand {
} }
@Override @Override
protected void permissionsCheck(Player player) { protected void permissionsCheck() {
canSkullSplitter = Permissions.skullSplitter(player); canSkullSplitter = Permissions.skullSplitter(player);
canCritical = Permissions.criticalStrikes(player); canCritical = Permissions.criticalStrikes(player);
canBonusDamage = Permissions.bonusDamage(player, skill); canBonusDamage = Permissions.bonusDamage(player, skill);
@@ -65,56 +60,60 @@ public class AxesCommand extends SkillCommand {
} }
@Override @Override
protected List<String> effectsDisplay() { protected boolean effectsHeaderPermissions() {
List<String> messages = new ArrayList<String>(); return canSkullSplitter || canCritical || canBonusDamage || canImpact || canGreaterImpact;
if (canSkullSplitter) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Axes.Effect.0"), LocaleLoader.getString("Axes.Effect.1")));
}
if (canCritical) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Axes.Effect.2"), LocaleLoader.getString("Axes.Effect.3")));
}
if (canBonusDamage) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Axes.Effect.4"), LocaleLoader.getString("Axes.Effect.5")));
}
if (canImpact) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Axes.Effect.6"), LocaleLoader.getString("Axes.Effect.7")));
}
if (canGreaterImpact) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Axes.Effect.8"), LocaleLoader.getString("Axes.Effect.9")));
}
return messages;
} }
@Override @Override
protected List<String> statsDisplay(Player player, float skillValue, boolean hasEndurance, boolean isLucky) { protected void effectsDisplay() {
List<String> messages = new ArrayList<String>(); luckyEffectsDisplay();
if (canBonusDamage) { if (canSkullSplitter) {
messages.add(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Axes.Ability.Bonus.0"), LocaleLoader.getString("Axes.Ability.Bonus.1", bonusDamage))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Axes.Effect.0"), LocaleLoader.getString("Axes.Effect.1")));
}
if (canImpact) {
messages.add(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Axes.Ability.Bonus.2"), LocaleLoader.getString("Axes.Ability.Bonus.3", impactDamage)));
}
if (canGreaterImpact) {
messages.add(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Axes.Ability.Bonus.4"), LocaleLoader.getString("Axes.Ability.Bonus.5", Axes.greaterImpactBonusDamage)));
} }
if (canCritical) { if (canCritical) {
messages.add(LocaleLoader.getString("Axes.Combat.CritChance", critChance) + (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", critChanceLucky) : "")); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Axes.Effect.2"), LocaleLoader.getString("Axes.Effect.3")));
}
if (canBonusDamage) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Axes.Effect.4"), LocaleLoader.getString("Axes.Effect.5")));
}
if (canImpact) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Axes.Effect.6"), LocaleLoader.getString("Axes.Effect.7")));
}
if (canGreaterImpact) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Axes.Effect.8"), LocaleLoader.getString("Axes.Effect.9")));
}
}
@Override
protected boolean statsHeaderPermissions() {
return canSkullSplitter || canCritical || canBonusDamage || canImpact || canGreaterImpact;
}
@Override
protected void statsDisplay() {
if (canBonusDamage) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Axes.Ability.Bonus.0"), LocaleLoader.getString("Axes.Ability.Bonus.1", bonusDamage)));
}
if (canImpact) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Axes.Ability.Bonus.2"), LocaleLoader.getString("Axes.Ability.Bonus.3", impactDamage)));
}
if (canGreaterImpact) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Axes.Ability.Bonus.4"), LocaleLoader.getString("Axes.Ability.Bonus.5", Axes.greaterImpactBonusDamage)));
}
if (canCritical) {
player.sendMessage(LocaleLoader.getString("Axes.Combat.CritChance", critChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", critChanceLucky) : ""));
} }
if (canSkullSplitter) { if (canSkullSplitter) {
messages.add(LocaleLoader.getString("Axes.Combat.SS.Length", skullSplitterLength) + (hasEndurance ? LocaleLoader.getString("Perks.ActivationTime.Bonus", skullSplitterLengthEndurance) : "")); player.sendMessage(LocaleLoader.getString("Axes.Combat.SS.Length", skullSplitterLength) + (hasEndurance ? LocaleLoader.getString("Perks.activationtime.bonus", skullSplitterLengthEndurance) : ""));
} }
return messages;
} }
} }

View File

@@ -1,10 +1,5 @@
package com.gmail.nossr50.commands.skills; package com.gmail.nossr50.commands.skills;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.entity.Player;
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;
@@ -21,44 +16,48 @@ public class ExcavationCommand extends SkillCommand {
} }
@Override @Override
protected void dataCalculations(Player player, float skillValue, boolean isLucky) { protected void dataCalculations() {
// GIGA DRILL BREAKER // GIGA DRILL BREAKER
if (canGigaDrill) { if (canGigaDrill) {
String gigaDrillStrings[] = calculateLengthDisplayValues(player, skillValue); String gigaDrillStrings[] = calculateLengthDisplayValues();
gigaDrillBreakerLength = gigaDrillStrings[0]; gigaDrillBreakerLength = gigaDrillStrings[0];
gigaDrillBreakerLengthEndurance = gigaDrillStrings[1]; gigaDrillBreakerLengthEndurance = gigaDrillStrings[1];
} }
} }
@Override @Override
protected void permissionsCheck(Player player) { protected void permissionsCheck() {
canGigaDrill = Permissions.gigaDrillBreaker(player); canGigaDrill = Permissions.gigaDrillBreaker(player);
canTreasureHunt = Permissions.excavationTreasureHunter(player); canTreasureHunt = Permissions.excavationTreasureHunter(player);
} }
@Override @Override
protected List<String> effectsDisplay() { protected boolean effectsHeaderPermissions() {
List<String> messages = new ArrayList<String>(); return canGigaDrill || canTreasureHunt;
if (canGigaDrill) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Excavation.Effect.0"), LocaleLoader.getString("Excavation.Effect.1")));
}
if (canTreasureHunt) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Excavation.Effect.2"), LocaleLoader.getString("Excavation.Effect.3")));
}
return messages;
} }
@Override @Override
protected List<String> statsDisplay(Player player, float skillValue, boolean hasEndurance, boolean isLucky) { protected void effectsDisplay() {
List<String> messages = new ArrayList<String>(); luckyEffectsDisplay();
if (canGigaDrill) { if (canGigaDrill) {
messages.add(LocaleLoader.getString("Excavation.Effect.Length", gigaDrillBreakerLength) + (hasEndurance ? LocaleLoader.getString("Perks.ActivationTime.Bonus", gigaDrillBreakerLengthEndurance) : "")); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Excavation.Effect.0"), LocaleLoader.getString("Excavation.Effect.1")));
} }
return messages; if (canTreasureHunt) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Excavation.Effect.2"), LocaleLoader.getString("Excavation.Effect.3")));
}
}
@Override
protected boolean statsHeaderPermissions() {
return canGigaDrill;
}
@Override
protected void statsDisplay() {
if (canGigaDrill) {
player.sendMessage(LocaleLoader.getString("Excavation.Effect.Length", gigaDrillBreakerLength) + (hasEndurance ? LocaleLoader.getString("Perks.activationtime.bonus", gigaDrillBreakerLengthEndurance) : ""));
}
} }
} }

View File

@@ -1,41 +1,25 @@
package com.gmail.nossr50.commands.skills; package com.gmail.nossr50.commands.skills;
import java.util.ArrayList;
import java.util.List;
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 org.bukkit.entity.Player;
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.skills.fishing.FishingManager;
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;
@@ -48,72 +32,55 @@ public class FishingCommand extends SkillCommand {
} }
@Override @Override
protected void dataCalculations(Player player, float skillValue, boolean isLucky) { protected void dataCalculations() {
FishingManager fishingManager = UserManager.getPlayer(player).getFishingManager();
boolean isStorming = player.getWorld().hasStorm(); boolean isStorming = player.getWorld().hasStorm();
// TREASURE HUNTER // TREASURE HUNTER
if (canTreasureHunt) { if (canTreasureHunt) {
lootTier = fishingManager.getLootTier(); lootTier = mcMMOPlayer.getFishingManager().getLootTier();
double enchantChance = lootTier * AdvancedConfig.getInstance().getFishingMagicMultiplier();
// Item drop rates if (isStorming) {
trapTreasure = percent.format(TreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.TRAP) / 100.0); chanceRaining = LocaleLoader.getString("Fishing.Chance.Raining");
commonTreasure = percent.format(TreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.COMMON) / 100.0); enchantChance *= 1.1D;
uncommonTreasure = percent.format(TreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.UNCOMMON) / 100.0);
rareTreasure = percent.format(TreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.RARE) / 100.0);
epicTreasure = percent.format(TreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.EPIC) / 100.0);
legendaryTreasure = percent.format(TreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.LEGENDARY) / 100.0);
recordTreasure = percent.format(TreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.RECORD) / 100.0);
// Magic hunter drop rates
double totalEnchantChance = 0;
for (Rarity rarity : Rarity.values()) {
if (rarity != Rarity.TRAP || rarity != Rarity.RECORD) {
totalEnchantChance += TreasureConfig.getInstance().getEnchantmentDropRate(lootTier, rarity);
}
} }
magicChance = percent.format(totalEnchantChance / 100.0); String[] treasureHunterStrings = calculateAbilityDisplayValues(enchantChance);
magicChance = treasureHunterStrings[0];
magicChanceLucky = treasureHunterStrings[1];
} }
// SHAKE // SHAKE
if (canShake) { if (canShake) {
String[] shakeStrings = calculateAbilityDisplayValues(UserManager.getPlayer(player).getFishingManager().getShakeProbability(), isLucky); String[] shakeStrings = calculateAbilityDisplayValues(UserManager.getPlayer(player).getFishingManager().getShakeProbability());
shakeChance = shakeStrings[0]; shakeChance = shakeStrings[0];
shakeChanceLucky = shakeStrings[1]; shakeChanceLucky = shakeStrings[1];
} }
// FISHERMAN'S DIET // FISHERMAN'S DIET
if (canFishermansDiet) { if (canFishermansDiet) {
fishermansDietRank = calculateRank(skillValue, Fishing.fishermansDietMaxLevel, Fishing.fishermansDietRankLevel1); fishermansDietRank = calculateRank(Fishing.fishermansDietMaxLevel, Fishing.fishermansDietRankLevel1);
} }
// 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 = fishingManager.getHookLocation(); Biome biome = player.getLocation().getBlock().getBiome();
if (location == null) {
location = player.getLocation();
}
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, isLucky)[0]; biteChance = calculateAbilityDisplayValues(rawBiteChance * 100.0)[0];
} }
} }
@Override @Override
protected void permissionsCheck(Player player) { protected void permissionsCheck() {
canTreasureHunt = Permissions.fishingTreasureHunter(player); canTreasureHunt = Permissions.fishingTreasureHunter(player);
canMagicHunt = Permissions.magicHunter(player); canMagicHunt = Permissions.magicHunter(player);
canShake = Permissions.shake(player); canShake = Permissions.shake(player);
@@ -123,86 +90,82 @@ public class FishingCommand extends SkillCommand {
} }
@Override @Override
protected List<String> effectsDisplay() { protected boolean effectsHeaderPermissions() {
List<String> messages = new ArrayList<String>(); return canTreasureHunt || canMagicHunt || canShake || canMasterAngler || canFishermansDiet || canIceFish;
if (canTreasureHunt) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Fishing.Effect.0"), LocaleLoader.getString("Fishing.Effect.1")));
}
if (canMagicHunt) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Fishing.Effect.2"), LocaleLoader.getString("Fishing.Effect.3")));
}
if (canIceFish) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Fishing.Effect.10"), LocaleLoader.getString("Fishing.Effect.11")));
}
if (canMasterAngler) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Fishing.Effect.8"), LocaleLoader.getString("Fishing.Effect.9")));
}
if (canShake) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Fishing.Effect.4"), LocaleLoader.getString("Fishing.Effect.5")));
}
if (canFishermansDiet) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Fishing.Effect.6"), LocaleLoader.getString("Fishing.Effect.7")));
}
return messages;
} }
@Override @Override
protected List<String> statsDisplay(Player player, float skillValue, boolean hasEndurance, boolean isLucky) { protected void effectsDisplay() {
List<String> messages = new ArrayList<String>(); luckyEffectsDisplay();
if (canTreasureHunt) { if (canTreasureHunt) {
messages.add(LocaleLoader.getString("Fishing.Ability.Rank", lootTier, Tier.EIGHT.toNumerical())); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Fishing.Effect.0"), LocaleLoader.getString("Fishing.Effect.1")));
messages.add(LocaleLoader.getString("Fishing.Ability.TH.DropRate", trapTreasure, commonTreasure, uncommonTreasure, rareTreasure, epicTreasure, legendaryTreasure, recordTreasure));
} }
if (canMagicHunt) { if (canMagicHunt) {
messages.add(LocaleLoader.getString("Fishing.Ability.TH.MagicRate", magicChance)); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Fishing.Effect.2"), LocaleLoader.getString("Fishing.Effect.3")));
}
if (canShake) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Fishing.Effect.4"), LocaleLoader.getString("Fishing.Effect.5")));
}
if (canFishermansDiet) {
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
protected boolean statsHeaderPermissions() {
return canTreasureHunt || canMagicHunt || canShake || canMasterAngler || canFishermansDiet || canIceFish;
}
@Override
protected void statsDisplay() {
if (canMasterAngler) {
player.sendMessage(LocaleLoader.getString("Fishing.Ability.Chance", biteChance));
}
if (canTreasureHunt) {
player.sendMessage(LocaleLoader.getString("Fishing.Ability.Rank", lootTier));
}
if (canMagicHunt) {
player.sendMessage(LocaleLoader.getString("Fishing.Enchant.Chance", magicChance) + chanceRaining + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", magicChanceLucky) : ""));
}
if (canShake) {
int unlockLevel = AdvancedConfig.getInstance().getShakeUnlockLevel();
if (skillValue < unlockLevel) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Fishing.Ability.Locked.0", unlockLevel)));
}
else {
player.sendMessage(LocaleLoader.getString("Fishing.Ability.Shake", shakeChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", shakeChanceLucky) : ""));
}
}
if (canFishermansDiet) {
player.sendMessage(LocaleLoader.getString("Fishing.Ability.FD", fishermansDietRank));
} }
if (canIceFish) { if (canIceFish) {
int unlockLevel = AdvancedConfig.getInstance().getIceFishingUnlockLevel(); int unlockLevel = AdvancedConfig.getInstance().getIceFishingUnlockLevel();
if (skillValue < unlockLevel) { if (skillValue < unlockLevel) {
messages.add(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Fishing.Ability.Locked.1", unlockLevel))); player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Fishing.Ability.Locked.1", unlockLevel)));
} }
else { else {
messages.add(LocaleLoader.getString("Fishing.Ability.IceFishing")); player.sendMessage(LocaleLoader.getString("Fishing.Ability.IceFishing"));
} }
} }
if (canMasterAngler) {
int unlockLevel = AdvancedConfig.getInstance().getMasterAnglerUnlockLevel();
if (skillValue < unlockLevel) {
messages.add(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Fishing.Ability.Locked.2", unlockLevel)));
}
else {
messages.add(LocaleLoader.getString("Fishing.Ability.Chance", biteChance));
}
}
if (canShake) {
int unlockLevel = AdvancedConfig.getInstance().getFishingTierLevel(Tier.ONE);
if (skillValue < unlockLevel) {
messages.add(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Fishing.Ability.Locked.0", unlockLevel)));
}
else {
messages.add(LocaleLoader.getString("Fishing.Ability.Shake", shakeChance) + (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", shakeChanceLucky) : ""));
}
}
if (canFishermansDiet) {
messages.add(LocaleLoader.getString("Fishing.Ability.FD", fishermansDietRank));
}
return messages;
} }
} }

View File

@@ -1,10 +1,6 @@
package com.gmail.nossr50.commands.skills; package com.gmail.nossr50.commands.skills;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player;
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;
@@ -38,52 +34,52 @@ public class HerbalismCommand extends SkillCommand {
} }
@Override @Override
protected void dataCalculations(Player player, float skillValue, boolean isLucky) { protected void dataCalculations() {
// GREEN TERRA // GREEN TERRA
if (canGreenTerra) { if (canGreenTerra) {
String[] greenTerraStrings = calculateLengthDisplayValues(player, skillValue); String[] greenTerraStrings = calculateLengthDisplayValues();
greenTerraLength = greenTerraStrings[0]; greenTerraLength = greenTerraStrings[0];
greenTerraLengthEndurance = greenTerraStrings[1]; greenTerraLengthEndurance = greenTerraStrings[1];
} }
// FARMERS DIET // FARMERS DIET
if (canFarmersDiet) { if (canFarmersDiet) {
farmersDietRank = calculateRank(skillValue, Herbalism.farmersDietMaxLevel, Herbalism.farmersDietRankLevel1); farmersDietRank = calculateRank(Herbalism.farmersDietMaxLevel, Herbalism.farmersDietRankLevel1);
} }
// GREEN THUMB // GREEN THUMB
if (canGreenThumbBlocks || canGreenThumbPlants) { if (canGreenThumbBlocks || canGreenThumbPlants) {
greenThumbStage = calculateRank(skillValue, Herbalism.greenThumbStageMaxLevel, Herbalism.greenThumbStageChangeLevel); greenThumbStage = calculateRank(Herbalism.greenThumbStageMaxLevel, Herbalism.greenThumbStageChangeLevel);
String[] greenThumbStrings = calculateAbilityDisplayValues(skillValue, Herbalism.greenThumbMaxLevel, Herbalism.greenThumbMaxChance, isLucky); String[] greenThumbStrings = calculateAbilityDisplayValues(Herbalism.greenThumbMaxLevel, Herbalism.greenThumbMaxChance);
greenThumbChance = greenThumbStrings[0]; greenThumbChance = greenThumbStrings[0];
greenThumbChanceLucky = greenThumbStrings[1]; greenThumbChanceLucky = greenThumbStrings[1];
} }
// DOUBLE DROPS // DOUBLE DROPS
if (canDoubleDrop) { if (canDoubleDrop) {
String[] doubleDropStrings = calculateAbilityDisplayValues(skillValue, Herbalism.doubleDropsMaxLevel, Herbalism.doubleDropsMaxChance, isLucky); String[] doubleDropStrings = calculateAbilityDisplayValues(Herbalism.doubleDropsMaxLevel, Herbalism.doubleDropsMaxChance);
doubleDropChance = doubleDropStrings[0]; doubleDropChance = doubleDropStrings[0];
doubleDropChanceLucky = doubleDropStrings[1]; doubleDropChanceLucky = doubleDropStrings[1];
} }
// HYLIAN LUCK // HYLIAN LUCK
if (hasHylianLuck) { if (hasHylianLuck) {
String[] hylianLuckStrings = calculateAbilityDisplayValues(skillValue, Herbalism.hylianLuckMaxLevel, Herbalism.hylianLuckMaxChance, isLucky); String[] hylianLuckStrings = calculateAbilityDisplayValues(Herbalism.hylianLuckMaxLevel, Herbalism.hylianLuckMaxChance);
hylianLuckChance = hylianLuckStrings[0]; hylianLuckChance = hylianLuckStrings[0];
hylianLuckChanceLucky = hylianLuckStrings[1]; hylianLuckChanceLucky = hylianLuckStrings[1];
} }
// SHROOM THUMB // SHROOM THUMB
if (canShroomThumb) { if (canShroomThumb) {
String[] shroomThumbStrings = calculateAbilityDisplayValues(skillValue, Herbalism.shroomThumbMaxLevel, Herbalism.shroomThumbMaxChance, isLucky); String[] shroomThumbStrings = calculateAbilityDisplayValues(Herbalism.shroomThumbMaxLevel, Herbalism.shroomThumbMaxChance);
shroomThumbChance = shroomThumbStrings[0]; shroomThumbChance = shroomThumbStrings[0];
shroomThumbChanceLucky = shroomThumbStrings[1]; shroomThumbChanceLucky = shroomThumbStrings[1];
} }
} }
@Override @Override
protected void permissionsCheck(Player player) { protected void permissionsCheck() {
hasHylianLuck = Permissions.hylianLuck(player); hasHylianLuck = Permissions.hylianLuck(player);
canGreenTerra = Permissions.greenTerra(player); canGreenTerra = Permissions.greenTerra(player);
canGreenThumbPlants = Permissions.greenThumbPlant(player, Material.CROPS) || Permissions.greenThumbPlant(player, Material.CARROT) || Permissions.greenThumbPlant(player, Material.POTATO) || Permissions.greenThumbPlant(player, Material.NETHER_WARTS) || Permissions.greenThumbPlant(player, Material.COCOA); canGreenThumbPlants = Permissions.greenThumbPlant(player, Material.CROPS) || Permissions.greenThumbPlant(player, Material.CARROT) || Permissions.greenThumbPlant(player, Material.POTATO) || Permissions.greenThumbPlant(player, Material.NETHER_WARTS) || Permissions.greenThumbPlant(player, Material.COCOA);
@@ -94,72 +90,76 @@ public class HerbalismCommand extends SkillCommand {
} }
@Override @Override
protected List<String> effectsDisplay() { protected boolean effectsHeaderPermissions() {
List<String> messages = new ArrayList<String>(); return canGreenTerra || canDoubleDrop || canFarmersDiet || canGreenThumbBlocks || canGreenThumbPlants || canShroomThumb;
if (canGreenTerra) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.0"), LocaleLoader.getString("Herbalism.Effect.1")));
}
if (canGreenThumbPlants) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.2"), LocaleLoader.getString("Herbalism.Effect.3")));
}
if (canGreenThumbBlocks) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.4"), LocaleLoader.getString("Herbalism.Effect.5")));
}
if (canFarmersDiet) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.6"), LocaleLoader.getString("Herbalism.Effect.7")));
}
if (hasHylianLuck) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.10"), LocaleLoader.getString("Herbalism.Effect.11")));
}
if (canShroomThumb) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.12"), LocaleLoader.getString("Herbalism.Effect.13")));
}
if (canDoubleDrop) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.8"), LocaleLoader.getString("Herbalism.Effect.9")));
}
return messages;
} }
@Override @Override
protected List<String> statsDisplay(Player player, float skillValue, boolean hasEndurance, boolean isLucky) { protected void effectsDisplay() {
List<String> messages = new ArrayList<String>(); luckyEffectsDisplay();
if (canGreenTerra) { if (canGreenTerra) {
messages.add(LocaleLoader.getString("Herbalism.Ability.GTe.Length", greenTerraLength) + (hasEndurance ? LocaleLoader.getString("Perks.ActivationTime.Bonus", greenTerraLengthEndurance) : "")); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.0"), LocaleLoader.getString("Herbalism.Effect.1")));
}
if (canGreenThumbBlocks || canGreenThumbPlants) {
messages.add(LocaleLoader.getString("Herbalism.Ability.GTh.Chance", greenThumbChance) + (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", greenThumbChanceLucky) : ""));
} }
if (canGreenThumbPlants) { if (canGreenThumbPlants) {
messages.add(LocaleLoader.getString("Herbalism.Ability.GTh.Stage", greenThumbStage)); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.2"), LocaleLoader.getString("Herbalism.Effect.3")));
}
if (canGreenThumbBlocks) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.4"), LocaleLoader.getString("Herbalism.Effect.5")));
} }
if (canFarmersDiet) { if (canFarmersDiet) {
messages.add(LocaleLoader.getString("Herbalism.Ability.FD", farmersDietRank)); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.6"), LocaleLoader.getString("Herbalism.Effect.7")));
} }
if (hasHylianLuck) { if (hasHylianLuck) {
messages.add(LocaleLoader.getString("Herbalism.Ability.HylianLuck", hylianLuckChance) + (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", hylianLuckChanceLucky) : "")); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.10"), LocaleLoader.getString("Herbalism.Effect.11")));
} }
if (canShroomThumb) { if (canShroomThumb) {
messages.add(LocaleLoader.getString("Herbalism.Ability.ShroomThumb.Chance", shroomThumbChance) + (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", shroomThumbChanceLucky) : "")); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.12"), LocaleLoader.getString("Herbalism.Effect.13")));
} }
if (canDoubleDrop) { if (canDoubleDrop) {
messages.add(LocaleLoader.getString("Herbalism.Ability.DoubleDropChance", doubleDropChance) + (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", doubleDropChanceLucky) : "")); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.8"), LocaleLoader.getString("Herbalism.Effect.9")));
}
}
@Override
protected boolean statsHeaderPermissions() {
return canGreenTerra || canDoubleDrop || canFarmersDiet || canGreenThumbBlocks || canGreenThumbPlants || canShroomThumb;
}
@Override
protected void statsDisplay() {
if (canGreenTerra) {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTe.Length", greenTerraLength) + (hasEndurance ? LocaleLoader.getString("Perks.activationtime.bonus", greenTerraLengthEndurance) : ""));
} }
return messages; if (canGreenThumbBlocks || canGreenThumbPlants) {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTh.Chance", greenThumbChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", greenThumbChanceLucky) : ""));
}
if (canGreenThumbPlants) {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTh.Stage", greenThumbStage));
}
if (canFarmersDiet) {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.FD", farmersDietRank));
}
if (hasHylianLuck) {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.HylianLuck", hylianLuckChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", hylianLuckChanceLucky) : ""));
}
if (canShroomThumb) {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.ShroomThumb.Chance", shroomThumbChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", shroomThumbChanceLucky) : ""));
}
if (canDoubleDrop) {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.DoubleDropChance", doubleDropChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", doubleDropChanceLucky) : ""));
}
} }
} }

View File

@@ -1,18 +1,11 @@
package com.gmail.nossr50.commands.skills; package com.gmail.nossr50.commands.skills;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.entity.Player;
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;
import com.gmail.nossr50.util.player.UserManager;
public class MiningCommand extends SkillCommand { public class MiningCommand extends SkillCommand {
private String doubleDropChance; private String doubleDropChance;
@@ -38,24 +31,24 @@ public class MiningCommand extends SkillCommand {
} }
@Override @Override
protected void dataCalculations(Player player, float skillValue, boolean isLucky) { protected void dataCalculations() {
// SUPER BREAKER // SUPER BREAKER
if (canSuperBreaker) { if (canSuperBreaker) {
String[] superBreakerStrings = calculateLengthDisplayValues(player, skillValue); String[] superBreakerStrings = calculateLengthDisplayValues();
superBreakerLength = superBreakerStrings[0]; superBreakerLength = superBreakerStrings[0];
superBreakerLengthEndurance = superBreakerStrings[1]; superBreakerLengthEndurance = superBreakerStrings[1];
} }
// DOUBLE DROPS // DOUBLE DROPS
if (canDoubleDrop) { if (canDoubleDrop) {
String[] doubleDropStrings = calculateAbilityDisplayValues(skillValue, Mining.doubleDropsMaxLevel, Mining.doubleDropsMaxChance, isLucky); String[] doubleDropStrings = calculateAbilityDisplayValues(Mining.doubleDropsMaxLevel, Mining.doubleDropsMaxChance);
doubleDropChance = doubleDropStrings[0]; doubleDropChance = doubleDropStrings[0];
doubleDropChanceLucky = doubleDropStrings[1]; doubleDropChanceLucky = doubleDropStrings[1];
} }
// BLAST MINING // BLAST MINING
if (canBlast || canDemoExpert || canBiggerBombs) { if (canBlast || canDemoExpert || canBiggerBombs) {
MiningManager miningManager = UserManager.getPlayer(player).getMiningManager(); MiningManager miningManager = mcMMOPlayer.getMiningManager();
blastMiningRank = miningManager.getBlastMiningTier(); blastMiningRank = miningManager.getBlastMiningTier();
bonusTNTDrops = miningManager.getDropMultiplier(); bonusTNTDrops = miningManager.getDropMultiplier();
@@ -67,7 +60,7 @@ public class MiningCommand extends SkillCommand {
} }
@Override @Override
protected void permissionsCheck(Player player) { protected void permissionsCheck() {
canBiggerBombs = Permissions.biggerBombs(player); canBiggerBombs = Permissions.biggerBombs(player);
canBlast = Permissions.remoteDetonation(player); canBlast = Permissions.remoteDetonation(player);
canDemoExpert = Permissions.demolitionsExpertise(player); canDemoExpert = Permissions.demolitionsExpertise(player);
@@ -76,77 +69,81 @@ public class MiningCommand extends SkillCommand {
} }
@Override @Override
protected List<String> effectsDisplay() { protected boolean effectsHeaderPermissions() {
List<String> messages = new ArrayList<String>(); return canBiggerBombs || canBlast || canDemoExpert || canDoubleDrop || canSuperBreaker;
if (canSuperBreaker) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Mining.Effect.0"), LocaleLoader.getString("Mining.Effect.1")));
}
if (canDoubleDrop) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Mining.Effect.2"), LocaleLoader.getString("Mining.Effect.3")));
}
if (canBlast) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Mining.Effect.4"), LocaleLoader.getString("Mining.Effect.5")));
}
if (canBiggerBombs) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Mining.Effect.6"), LocaleLoader.getString("Mining.Effect.7")));
}
if (canDemoExpert) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Mining.Effect.8"), LocaleLoader.getString("Mining.Effect.9")));
}
return messages;
} }
@Override @Override
protected List<String> statsDisplay(Player player, float skillValue, boolean hasEndurance, boolean isLucky) { protected void effectsDisplay() {
List<String> messages = new ArrayList<String>(); luckyEffectsDisplay();
if (canDoubleDrop) {
messages.add(LocaleLoader.getString("Mining.Effect.DropChance", doubleDropChance) + (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", doubleDropChanceLucky) : ""));
}
if (canSuperBreaker) { if (canSuperBreaker) {
messages.add(LocaleLoader.getString("Mining.Ability.Length", superBreakerLength) + (hasEndurance ? LocaleLoader.getString("Perks.ActivationTime.Bonus", superBreakerLengthEndurance) : "")); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Mining.Effect.0"), LocaleLoader.getString("Mining.Effect.1")));
}
if (canDoubleDrop) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Mining.Effect.2"), LocaleLoader.getString("Mining.Effect.3")));
} }
if (canBlast) { if (canBlast) {
int unlockLevel = AdvancedConfig.getInstance().getBlastMiningRankLevel(Tier.ONE); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Mining.Effect.4"), LocaleLoader.getString("Mining.Effect.5")));
}
if (canBiggerBombs) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Mining.Effect.6"), LocaleLoader.getString("Mining.Effect.7")));
}
if (canDemoExpert) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Mining.Effect.8"), LocaleLoader.getString("Mining.Effect.9")));
}
}
@Override
protected boolean statsHeaderPermissions() {
return canBiggerBombs || canBlast || canDemoExpert || canDoubleDrop || canSuperBreaker;
}
@Override
protected void statsDisplay() {
if (canDoubleDrop) {
player.sendMessage(LocaleLoader.getString("Mining.Effect.DropChance", doubleDropChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", doubleDropChanceLucky) : ""));
}
if (canSuperBreaker) {
player.sendMessage(LocaleLoader.getString("Mining.Ability.Length", superBreakerLength) + (hasEndurance ? LocaleLoader.getString("Perks.activationtime.bonus", superBreakerLengthEndurance) : ""));
}
if (canBlast) {
int unlockLevel = AdvancedConfig.getInstance().getBlastMiningRank1();
if (skillValue < unlockLevel) { if (skillValue < unlockLevel) {
messages.add(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 {
messages.add(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) {
messages.add(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)));
} }
else { else {
messages.add(LocaleLoader.getString("Mining.Blast.Radius.Increase", blastRadiusIncrease)); player.sendMessage(LocaleLoader.getString("Mining.Blast.Radius.Increase", blastRadiusIncrease));
} }
} }
if (canDemoExpert) { if (canDemoExpert) {
int unlockLevel = AdvancedConfig.getInstance().getBlastMiningRankLevel(Tier.FOUR); int unlockLevel = AdvancedConfig.getInstance().getBlastMiningRank4();
if (skillValue < unlockLevel) { if (skillValue < unlockLevel) {
messages.add(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)));
} }
else { else {
messages.add(LocaleLoader.getString("Mining.Effect.Decrease", blastDamageDecrease)); player.sendMessage(LocaleLoader.getString("Mining.Effect.Decrease", blastDamageDecrease));
} }
} }
return messages;
} }
} }

View File

@@ -1,21 +1,15 @@
package com.gmail.nossr50.commands.skills; package com.gmail.nossr50.commands.skills;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Material; import org.bukkit.Material;
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.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;
import com.gmail.nossr50.util.player.UserManager;
public class RepairCommand extends SkillCommand { public class RepairCommand extends SkillCommand {
private String repairMasteryBonus; private String repairMasteryBonus;
@@ -45,12 +39,12 @@ public class RepairCommand extends SkillCommand {
} }
@Override @Override
protected void dataCalculations(Player player, float skillValue, boolean isLucky) { protected void dataCalculations() {
// We're using pickaxes here, not the best but it works // We're using pickaxes here, not the best but it works
Repairable diamondRepairable = mcMMO.getRepairableManager().getRepairable(Material.DIAMOND_PICKAXE); Repairable diamondRepairable = mcMMO.getRepairableManager().getRepairable(Material.DIAMOND_PICKAXE.getId());
Repairable goldRepairable = mcMMO.getRepairableManager().getRepairable(Material.GOLD_PICKAXE); Repairable goldRepairable = mcMMO.getRepairableManager().getRepairable(Material.GOLD_PICKAXE.getId());
Repairable ironRepairable = mcMMO.getRepairableManager().getRepairable(Material.IRON_PICKAXE); Repairable ironRepairable = mcMMO.getRepairableManager().getRepairable(Material.IRON_PICKAXE.getId());
Repairable stoneRepairable = mcMMO.getRepairableManager().getRepairable(Material.STONE_PICKAXE); Repairable stoneRepairable = mcMMO.getRepairableManager().getRepairable(Material.STONE_PICKAXE.getId());
// TODO: This isn't really accurate - if they don't have pickaxes loaded it doesn't always mean the repair level is 0 // TODO: This isn't really accurate - if they don't have pickaxes loaded it doesn't always mean the repair level is 0
diamondLevel = (diamondRepairable == null) ? 0 : diamondRepairable.getMinimumLevel(); diamondLevel = (diamondRepairable == null) ? 0 : diamondRepairable.getMinimumLevel();
@@ -65,14 +59,14 @@ public class RepairCommand extends SkillCommand {
// SUPER REPAIR // SUPER REPAIR
if (canSuperRepair) { if (canSuperRepair) {
String[] superRepairStrings = calculateAbilityDisplayValues(skillValue, Repair.superRepairMaxBonusLevel, Repair.superRepairMaxChance, isLucky); String[] superRepairStrings = calculateAbilityDisplayValues(Repair.superRepairMaxBonusLevel, Repair.superRepairMaxChance);
superRepairChance = superRepairStrings[0]; superRepairChance = superRepairStrings[0];
superRepairChanceLucky = superRepairStrings[1]; superRepairChanceLucky = superRepairStrings[1];
} }
} }
@Override @Override
protected void permissionsCheck(Player player) { protected void permissionsCheck() {
canSuperRepair = Permissions.superRepair(player); canSuperRepair = Permissions.superRepair(player);
canMasterRepair = Permissions.repairMastery(player); canMasterRepair = Permissions.repairMastery(player);
canArcaneForge = Permissions.arcaneForging(player); canArcaneForge = Permissions.arcaneForging(player);
@@ -88,76 +82,78 @@ public class RepairCommand extends SkillCommand {
} }
@Override @Override
protected List<String> effectsDisplay() { protected boolean effectsHeaderPermissions() {
List<String> messages = new ArrayList<String>(); return canArcaneForge || canSalvage || canRepairDiamond || canRepairGold || canRepairIron || canMasterRepair || canRepairStone || canSuperRepair || canRepairString || canRepairWood || canRepairLeather;
}
if (canRepairLeather || canRepairString || canRepairWood || canRepairStone || canRepairIron || canRepairGold || canRepairDiamond) { @Override
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.0"), LocaleLoader.getString("Repair.Effect.1"))); protected void effectsDisplay() {
} luckyEffectsDisplay();
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.0"), LocaleLoader.getString("Repair.Effect.1")));
if (canMasterRepair) { if (canMasterRepair) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.2"), LocaleLoader.getString("Repair.Effect.3"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.2"), LocaleLoader.getString("Repair.Effect.3")));
} }
if (canSuperRepair) { if (canSuperRepair) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.4"), LocaleLoader.getString("Repair.Effect.5"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.4"), LocaleLoader.getString("Repair.Effect.5")));
} }
/* Repair Level Requirements */ /* Repair Level Requirements */
if (canRepairStone && stoneLevel > 0) { if (canRepairStone && stoneLevel > 0) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.14", stoneLevel), LocaleLoader.getString("Repair.Effect.15"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.14", stoneLevel), LocaleLoader.getString("Repair.Effect.15")));
} }
if (canRepairIron && ironLevel > 0) { if (canRepairIron && ironLevel > 0) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.12", ironLevel), LocaleLoader.getString("Repair.Effect.13"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.12", ironLevel), LocaleLoader.getString("Repair.Effect.13")));
} }
if (canRepairGold && goldLevel > 0) { if (canRepairGold && goldLevel > 0) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.10", goldLevel), LocaleLoader.getString("Repair.Effect.11"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.10", goldLevel), LocaleLoader.getString("Repair.Effect.11")));
} }
if (canRepairDiamond && diamondLevel > 0) { if (canRepairDiamond && diamondLevel > 0) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.6", diamondLevel), LocaleLoader.getString("Repair.Effect.7"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.6", diamondLevel), LocaleLoader.getString("Repair.Effect.7")));
} }
if (canSalvage && Repair.salvageUnlockLevel > 0) { if (canSalvage && Repair.salvageUnlockLevel > 0) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.16", Repair.salvageUnlockLevel), LocaleLoader.getString("Repair.Effect.17"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.16", Repair.salvageUnlockLevel), LocaleLoader.getString("Repair.Effect.17")));
} }
if (canArcaneForge) { if (canArcaneForge) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.8"), LocaleLoader.getString("Repair.Effect.9"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.8"), LocaleLoader.getString("Repair.Effect.9")));
} }
return messages;
} }
@Override @Override
protected List<String> statsDisplay(Player player, float skillValue, boolean hasEndurance, boolean isLucky) { protected boolean statsHeaderPermissions() {
List<String> messages = new ArrayList<String>(); return canArcaneForge || canMasterRepair || canSuperRepair;
}
@Override
protected void statsDisplay() {
if (canMasterRepair) { if (canMasterRepair) {
messages.add(LocaleLoader.getString("Repair.Skills.Mastery", repairMasteryBonus)); player.sendMessage(LocaleLoader.getString("Repair.Skills.Mastery", repairMasteryBonus));
} }
if (canSuperRepair) { if (canSuperRepair) {
messages.add(LocaleLoader.getString("Repair.Skills.Super.Chance", superRepairChance) + (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", superRepairChanceLucky) : "")); player.sendMessage(LocaleLoader.getString("Repair.Skills.Super.Chance", superRepairChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", superRepairChanceLucky) : ""));
} }
if (canArcaneForge) { if (canArcaneForge) {
RepairManager repairManager = UserManager.getPlayer(player).getRepairManager(); RepairManager repairManager = mcMMOPlayer.getRepairManager();
messages.add(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) {
messages.add(LocaleLoader.getString("Repair.Arcane.Chance.Success", (arcaneBypass ? 100 : repairManager.getKeepEnchantChance()))); player.sendMessage(LocaleLoader.getString("Repair.Arcane.Chance.Success", (arcaneBypass ? 100 : repairManager.getKeepEnchantChance())));
} }
if (ArcaneForging.arcaneForgingDowngrades) { if (ArcaneForging.arcaneForgingDowngrades) {
messages.add(LocaleLoader.getString("Repair.Arcane.Chance.Downgrade", (arcaneBypass ? 0 : repairManager.getDowngradeEnchantChance()))); player.sendMessage(LocaleLoader.getString("Repair.Arcane.Chance.Downgrade", (arcaneBypass ? 0 : repairManager.getDowngradeEnchantChance())));
} }
} }
return messages;
} }
} }

View File

@@ -13,6 +13,7 @@ import org.bukkit.entity.Player;
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.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.child.FamilyTree; import com.gmail.nossr50.skills.child.FamilyTree;
@@ -22,12 +23,21 @@ 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;
public abstract class SkillCommand implements TabExecutor { public abstract class SkillCommand implements TabExecutor {
protected SkillType skill; protected SkillType skill;
private String skillName; protected String skillName;
protected Player player;
protected PlayerProfile profile;
protected McMMOPlayer mcMMOPlayer;
protected float skillValue;
protected boolean isLucky;
protected boolean hasEndurance;
protected DecimalFormat percent = new DecimalFormat("##0.00%"); protected DecimalFormat percent = new DecimalFormat("##0.00%");
protected DecimalFormat decimal = new DecimalFormat("##0.00"); protected DecimalFormat decimal = new DecimalFormat("##0.00");
@@ -36,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);
} }
@@ -46,26 +56,31 @@ public abstract class SkillCommand implements TabExecutor {
return true; return true;
} }
player = (Player) sender;
mcMMOPlayer = UserManager.getPlayer(player);
switch (args.length) { switch (args.length) {
case 0: case 0:
Player player = (Player) sender; profile = mcMMOPlayer.getProfile();
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
boolean isLucky = Permissions.lucky(player, skill); skillValue = profile.getSkillLevel(skill);
boolean hasEndurance = (PerksUtils.handleActivationPerks(player, 0, 0) != 0); isLucky = Permissions.lucky(sender, skill);
float skillValue = mcMMOPlayer.getSkillLevel(skill); hasEndurance = (PerksUtils.handleActivationPerks(player, 0, 0) != 0);
permissionsCheck(player); permissionsCheck();
dataCalculations(player, skillValue, isLucky); 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, mcMMOPlayer.getSkillXpLevel(skill), mcMMOPlayer.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")));
@@ -76,35 +91,22 @@ 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", mcMMOPlayer.getSkillLevel(parent), mcMMOPlayer.getSkillXpLevel(parent), mcMMOPlayer.getXpToLevel(parent))); player.sendMessage(SkillUtils.getSkillName(parent) + " - " + LocaleLoader.getString("Effects.Level", profile.getSkillLevel(parent), profile.getSkillXpLevel(parent), profile.getXpToLevel(parent)));
} }
} }
List<String> effectMessages = effectsDisplay(); if (effectsHeaderPermissions()) {
if (!effectMessages.isEmpty()) {
player.sendMessage(LocaleLoader.getString("Skills.Header", LocaleLoader.getString("Effects.Effects"))); player.sendMessage(LocaleLoader.getString("Skills.Header", LocaleLoader.getString("Effects.Effects")));
if (isLucky) {
String perkPrefix = LocaleLoader.getString("MOTD.PerksPrefix");
player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Perks.Lucky.Name"), LocaleLoader.getString("Perks.Lucky.Desc", skillName)));
}
for (String message : effectMessages) {
player.sendMessage(message);
}
} }
List<String> statsMessages = statsDisplay(player, skillValue, hasEndurance, isLucky); effectsDisplay();
if (!statsMessages.isEmpty()) { if (statsHeaderPermissions()) {
player.sendMessage(LocaleLoader.getString("Skills.Header", LocaleLoader.getString("Commands.Stats.Self"))); player.sendMessage(LocaleLoader.getString("Skills.Header", LocaleLoader.getString("Commands.Stats.Self")));
for (String message : statsMessages) {
player.sendMessage(message);
}
} }
statsDisplay();
player.sendMessage(LocaleLoader.getString("Guides.Available", skillName, skillName.toLowerCase())); player.sendMessage(LocaleLoader.getString("Guides.Available", skillName, skillName.toLowerCase()));
return true; return true;
@@ -123,11 +125,11 @@ public abstract class SkillCommand implements TabExecutor {
} }
} }
protected int calculateRank(float skillValue, int maxLevel, int rankChangeLevel) { protected int calculateRank(int maxLevel, int rankChangeLevel) {
return Math.min((int) skillValue, maxLevel) / rankChangeLevel; return Math.min((int) skillValue, maxLevel) / rankChangeLevel;
} }
protected String[] calculateAbilityDisplayValues(double chance, boolean isLucky) { protected String[] calculateAbilityDisplayValues(double chance) {
String[] displayValues = new String[2]; String[] displayValues = new String[2];
displayValues[0] = percent.format(Math.min(chance, 100.0D) / 100.0D); displayValues[0] = percent.format(Math.min(chance, 100.0D) / 100.0D);
@@ -136,12 +138,12 @@ public abstract class SkillCommand implements TabExecutor {
return displayValues; return displayValues;
} }
protected String[] calculateAbilityDisplayValues(float skillValue, int maxBonusLevel, double maxChance, boolean isLucky) { protected String[] calculateAbilityDisplayValues(int maxBonusLevel, double maxChance) {
return calculateAbilityDisplayValues((maxChance / maxBonusLevel) * Math.min(skillValue, maxBonusLevel), isLucky); return calculateAbilityDisplayValues((maxChance / maxBonusLevel) * Math.min(skillValue, maxBonusLevel));
} }
protected String[] calculateLengthDisplayValues(Player player, float skillValue) { protected String[] calculateLengthDisplayValues() {
int maxLength = skill.getAbility().getMaxLength(); int maxLength = skill.getAbility().getMaxTicks();
int length = 2 + (int) (skillValue / AdvancedConfig.getInstance().getAbilityLength()); int length = 2 + (int) (skillValue / AdvancedConfig.getInstance().getAbilityLength());
int enduranceLength = PerksUtils.handleActivationPerks(player, length, maxLength); int enduranceLength = PerksUtils.handleActivationPerks(player, length, maxLength);
@@ -152,11 +154,22 @@ public abstract class SkillCommand implements TabExecutor {
return new String[] { String.valueOf(length), String.valueOf(enduranceLength) }; return new String[] { String.valueOf(length), String.valueOf(enduranceLength) };
} }
protected abstract void dataCalculations(Player player, float skillValue, boolean isLucky); protected void luckyEffectsDisplay() {
if (isLucky) {
String perkPrefix = LocaleLoader.getString("MOTD.PerksPrefix");
player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Perks.lucky.name"), LocaleLoader.getString("Perks.lucky.desc", skillName)));
}
}
protected abstract void permissionsCheck(Player player); protected abstract void dataCalculations();
protected abstract List<String> effectsDisplay(); protected abstract void permissionsCheck();
protected abstract List<String> statsDisplay(Player player, float skillValue, boolean hasEndurance, boolean isLucky); protected abstract boolean effectsHeaderPermissions();
protected abstract void effectsDisplay();
protected abstract boolean statsHeaderPermissions();
protected abstract void statsDisplay();
} }

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,19 @@ 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 = LocaleLoader.getString("Guides.Page.Invalid"); private String invalidPage;
public SkillGuideCommand(SkillType skill) { public SkillGuideCommand(SkillType skillType) {
header = LocaleLoader.getString("Guides.Header", skill.getName()); header = LocaleLoader.getString("Guides.Header", SkillUtils.getSkillName(skillType));
guide = getGuide(skill); guide = LocaleLoader.getString("Guides." + StringUtils.getCapitalized(skillType.toString())).split("\n");
invalidPage = LocaleLoader.getString("Guides.Page.Invalid");
} }
@Override @Override
@@ -57,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) {
@@ -66,46 +68,23 @@ public class SkillGuideCommand implements CommandExecutor {
} }
} }
private ArrayList<String> grabPageContents(int page) { private ArrayList<String> grabPageContents(int pagenum) {
int pageIndexStart = 8 * (page - 1); // Determine what string to start at int pageIndexStart = 8 * (pagenum - 1); // Determine what string to start at
ArrayList<String> allStrings = new ArrayList<String>(); ArrayList<String> allStrings = new ArrayList<String>();
allStrings.add(header); allStrings.add(header);
// 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 " + page + " of " + getTotalPageNumber()); allStrings.add("Page " + pagenum + " of " + getTotalPageNumber());
return allStrings; return allStrings;
} }
private ArrayList<String> getGuide(SkillType skill) {
ArrayList<String> guide = new ArrayList<String>();
for (int i = 0; i < 10; i++) {
String[] section = LocaleLoader.getString("Guides." + StringUtils.getCapitalized(skill.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

@@ -1,17 +1,10 @@
package com.gmail.nossr50.commands.skills; package com.gmail.nossr50.commands.skills;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.entity.Player;
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.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;
import com.gmail.nossr50.util.player.UserManager;
public class SmeltingCommand extends SkillCommand { public class SmeltingCommand extends SkillCommand {
private String burnTimeModifier; private String burnTimeModifier;
@@ -30,7 +23,7 @@ public class SmeltingCommand extends SkillCommand {
} }
@Override @Override
protected void dataCalculations(Player player, float skillValue, boolean isLucky) { protected void dataCalculations() {
// FUEL EFFICIENCY // FUEL EFFICIENCY
if (canFuelEfficiency) { if (canFuelEfficiency) {
burnTimeModifier = decimal.format(1 + ((skillValue / Smelting.burnModifierMaxLevel) * Smelting.burnTimeMultiplier)); burnTimeModifier = decimal.format(1 + ((skillValue / Smelting.burnModifierMaxLevel) * Smelting.burnTimeMultiplier));
@@ -38,21 +31,21 @@ public class SmeltingCommand extends SkillCommand {
// SECOND SMELT // SECOND SMELT
if (canSecondSmelt) { if (canSecondSmelt) {
String[] secondSmeltStrings = calculateAbilityDisplayValues(skillValue, Smelting.secondSmeltMaxLevel, Smelting.secondSmeltMaxChance, isLucky); String[] secondSmeltStrings = calculateAbilityDisplayValues(Smelting.secondSmeltMaxLevel, Smelting.secondSmeltMaxChance);
secondSmeltChance = secondSmeltStrings[0]; secondSmeltChance = secondSmeltStrings[0];
secondSmeltChanceLucky = secondSmeltStrings[1]; secondSmeltChanceLucky = secondSmeltStrings[1];
} }
// FLUX MINING // FLUX MINING
if (canFluxMine) { if (canFluxMine) {
String[] fluxMiningStrings = calculateAbilityDisplayValues(Smelting.fluxMiningChance, isLucky); String[] fluxMiningStrings = calculateAbilityDisplayValues(Smelting.fluxMiningChance);
fluxMiningChance = fluxMiningStrings[0]; fluxMiningChance = fluxMiningStrings[0];
fluxMiningChanceLucky = fluxMiningStrings[1]; fluxMiningChanceLucky = fluxMiningStrings[1];
} }
} }
@Override @Override
protected void permissionsCheck(Player player) { protected void permissionsCheck() {
canFuelEfficiency = Permissions.fuelEfficiency(player); canFuelEfficiency = Permissions.fuelEfficiency(player);
canSecondSmelt = Permissions.doubleDrops(player, skill); canSecondSmelt = Permissions.doubleDrops(player, skill);
canFluxMine = Permissions.fluxMining(player); canFluxMine = Permissions.fluxMining(player);
@@ -60,60 +53,64 @@ public class SmeltingCommand extends SkillCommand {
} }
@Override @Override
protected List<String> effectsDisplay() { protected boolean effectsHeaderPermissions() {
List<String> messages = new ArrayList<String>(); return canFluxMine || canFuelEfficiency || canSecondSmelt || canVanillaXPBoost;
if (canFuelEfficiency) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Smelting.Effect.0"), LocaleLoader.getString("Smelting.Effect.1")));
}
if (canSecondSmelt) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Smelting.Effect.2"), LocaleLoader.getString("Smelting.Effect.3")));
}
if (canVanillaXPBoost) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Smelting.Effect.4"), LocaleLoader.getString("Smelting.Effect.5")));
}
if (canFluxMine) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Smelting.Effect.6"), LocaleLoader.getString("Smelting.Effect.7")));
}
return messages;
} }
@Override @Override
protected List<String> statsDisplay(Player player, float skillValue, boolean hasEndurance, boolean isLucky) { protected void effectsDisplay() {
List<String> messages = new ArrayList<String>(); luckyEffectsDisplay();
if (canFuelEfficiency) { if (canFuelEfficiency) {
messages.add(LocaleLoader.getString("Smelting.Ability.FuelEfficiency", burnTimeModifier)); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Smelting.Effect.0"), LocaleLoader.getString("Smelting.Effect.1")));
} }
if (canSecondSmelt) { if (canSecondSmelt) {
messages.add(LocaleLoader.getString("Smelting.Ability.SecondSmelt", secondSmeltChance) + (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", secondSmeltChanceLucky) : "")); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Smelting.Effect.2"), LocaleLoader.getString("Smelting.Effect.3")));
} }
if (canVanillaXPBoost) { if (canVanillaXPBoost) {
int unlockLevel = AdvancedConfig.getInstance().getSmeltingRankLevel(Tier.ONE); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Smelting.Effect.4"), LocaleLoader.getString("Smelting.Effect.5")));
}
if (canFluxMine) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Smelting.Effect.6"), LocaleLoader.getString("Smelting.Effect.7")));
}
}
@Override
protected boolean statsHeaderPermissions() {
return canFluxMine || canFuelEfficiency || canSecondSmelt || canVanillaXPBoost;
}
@Override
protected void statsDisplay() {
if (canFuelEfficiency) {
player.sendMessage(LocaleLoader.getString("Smelting.Ability.FuelEfficiency", burnTimeModifier));
}
if (canSecondSmelt) {
player.sendMessage(LocaleLoader.getString("Smelting.Ability.SecondSmelt", secondSmeltChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", secondSmeltChanceLucky) : ""));
}
if (canVanillaXPBoost) {
int unlockLevel = AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank1Level();
if (skillValue < unlockLevel) { if (skillValue < unlockLevel) {
messages.add(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)));
} }
else { else {
messages.add(LocaleLoader.getString("Smelting.Ability.VanillaXPBoost", UserManager.getPlayer(player).getSmeltingManager().getVanillaXpMultiplier())); player.sendMessage(LocaleLoader.getString("Smelting.Ability.VanillaXPBoost", mcMMOPlayer.getSmeltingManager().getVanillaXpMultiplier()));
} }
} }
if (canFluxMine) { if (canFluxMine) {
if (skillValue < Smelting.fluxMiningUnlockLevel) { if (skillValue < Smelting.fluxMiningUnlockLevel) {
messages.add(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Smelting.Ability.Locked.1", Smelting.fluxMiningUnlockLevel))); player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Smelting.Ability.Locked.1", Smelting.fluxMiningUnlockLevel)));
} }
else { else {
messages.add(LocaleLoader.getString("Smelting.Ability.FluxMining", fluxMiningChance) + (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", fluxMiningChanceLucky) : "")); player.sendMessage(LocaleLoader.getString("Smelting.Ability.FluxMining", fluxMiningChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", fluxMiningChanceLucky) : ""));
} }
} }
return messages;
} }
} }

View File

@@ -1,10 +1,5 @@
package com.gmail.nossr50.commands.skills; package com.gmail.nossr50.commands.skills;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.entity.Player;
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.swords.Swords; import com.gmail.nossr50.skills.swords.Swords;
@@ -28,10 +23,10 @@ public class SwordsCommand extends SkillCommand {
} }
@Override @Override
protected void dataCalculations(Player player, float skillValue, boolean isLucky) { protected void dataCalculations() {
// SERRATED STRIKES // SERRATED STRIKES
if (canSerratedStrike) { if (canSerratedStrike) {
String[] serratedStrikesStrings = calculateLengthDisplayValues(player, skillValue); String[] serratedStrikesStrings = calculateLengthDisplayValues();
serratedStrikesLength = serratedStrikesStrings[0]; serratedStrikesLength = serratedStrikesStrings[0];
serratedStrikesLengthEndurance = serratedStrikesStrings[1]; serratedStrikesLengthEndurance = serratedStrikesStrings[1];
} }
@@ -40,64 +35,68 @@ public class SwordsCommand extends SkillCommand {
if (canBleed) { if (canBleed) {
bleedLength = (skillValue >= Swords.bleedMaxBonusLevel) ? Swords.bleedMaxTicks : Swords.bleedBaseTicks; bleedLength = (skillValue >= Swords.bleedMaxBonusLevel) ? Swords.bleedMaxTicks : Swords.bleedBaseTicks;
String[] bleedStrings = calculateAbilityDisplayValues(skillValue, Swords.bleedMaxBonusLevel, Swords.bleedMaxChance, isLucky); String[] bleedStrings = calculateAbilityDisplayValues(Swords.bleedMaxBonusLevel, Swords.bleedMaxChance);
bleedChance = bleedStrings[0]; bleedChance = bleedStrings[0];
bleedChanceLucky = bleedStrings[1]; bleedChanceLucky = bleedStrings[1];
} }
// COUNTER ATTACK // COUNTER ATTACK
if (canCounter) { if (canCounter) {
String[] counterAttackStrings = calculateAbilityDisplayValues(skillValue, Swords.counterAttackMaxBonusLevel, Swords.counterAttackMaxChance, isLucky); String[] counterAttackStrings = calculateAbilityDisplayValues(Swords.counterAttackMaxBonusLevel, Swords.counterAttackMaxChance);
counterAttackChance = counterAttackStrings[0]; counterAttackChance = counterAttackStrings[0];
counterAttackChanceLucky = counterAttackStrings[1]; counterAttackChanceLucky = counterAttackStrings[1];
} }
} }
@Override @Override
protected void permissionsCheck(Player player) { protected void permissionsCheck() {
canBleed = Permissions.bleed(player); canBleed = Permissions.bleed(player);
canCounter = Permissions.counterAttack(player); canCounter = Permissions.counterAttack(player);
canSerratedStrike = Permissions.serratedStrikes(player); canSerratedStrike = Permissions.serratedStrikes(player);
} }
@Override @Override
protected List<String> effectsDisplay() { protected boolean effectsHeaderPermissions() {
List<String> messages = new ArrayList<String>(); return canBleed || canCounter || canSerratedStrike;
if (canCounter) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Swords.Effect.0"), LocaleLoader.getString("Swords.Effect.1", percent.format(1.0D / Swords.counterAttackModifier))));
}
if (canSerratedStrike) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Swords.Effect.2"), LocaleLoader.getString("Swords.Effect.3", percent.format(1.0D / Swords.serratedStrikesModifier))));
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Swords.Effect.4"), LocaleLoader.getString("Swords.Effect.5", Swords.serratedStrikesBleedTicks)));
}
if (canBleed) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Swords.Effect.6"), LocaleLoader.getString("Swords.Effect.7")));
}
return messages;
} }
@Override @Override
protected List<String> statsDisplay(Player player, float skillValue, boolean hasEndurance, boolean isLucky) { protected void effectsDisplay() {
List<String> messages = new ArrayList<String>(); luckyEffectsDisplay();
if (canCounter) { if (canCounter) {
messages.add(LocaleLoader.getString("Swords.Combat.Counter.Chance", counterAttackChance) + (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", counterAttackChanceLucky) : "")); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Swords.Effect.0"), LocaleLoader.getString("Swords.Effect.1", percent.format(1.0D / Swords.counterAttackModifier))));
}
if (canBleed) {
messages.add(LocaleLoader.getString("Swords.Combat.Bleed.Length", bleedLength));
messages.add(LocaleLoader.getString("Swords.Combat.Bleed.Note"));
messages.add(LocaleLoader.getString("Swords.Combat.Bleed.Chance", bleedChance) + (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", bleedChanceLucky) : ""));
} }
if (canSerratedStrike) { if (canSerratedStrike) {
messages.add(LocaleLoader.getString("Swords.SS.Length", serratedStrikesLength) + (hasEndurance ? LocaleLoader.getString("Perks.ActivationTime.Bonus", serratedStrikesLengthEndurance) : "")); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Swords.Effect.2"), LocaleLoader.getString("Swords.Effect.3", percent.format(1.0D / Swords.serratedStrikesModifier))));
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Swords.Effect.4"), LocaleLoader.getString("Swords.Effect.5", Swords.serratedStrikesBleedTicks)));
} }
return messages; if (canBleed) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Swords.Effect.6"), LocaleLoader.getString("Swords.Effect.7")));
}
}
@Override
protected boolean statsHeaderPermissions() {
return canBleed || canCounter || canSerratedStrike;
}
@Override
protected void statsDisplay() {
if (canCounter) {
player.sendMessage(LocaleLoader.getString("Swords.Combat.Counter.Chance", counterAttackChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", counterAttackChanceLucky) : ""));
}
if (canBleed) {
player.sendMessage(LocaleLoader.getString("Swords.Combat.Bleed.Length", bleedLength));
player.sendMessage(LocaleLoader.getString("Swords.Combat.Bleed.Note"));
player.sendMessage(LocaleLoader.getString("Swords.Combat.Bleed.Chance", bleedChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", bleedChanceLucky) : ""));
}
if (canSerratedStrike) {
player.sendMessage(LocaleLoader.getString("Swords.SS.Length", serratedStrikesLength) + (hasEndurance ? LocaleLoader.getString("Perks.activationtime.bonus", serratedStrikesLengthEndurance) : ""));
}
} }
} }

View File

@@ -1,11 +1,5 @@
package com.gmail.nossr50.commands.skills; package com.gmail.nossr50.commands.skills;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
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;
@@ -31,18 +25,18 @@ public class TamingCommand extends SkillCommand {
} }
@Override @Override
protected void dataCalculations(Player player, float skillValue, boolean isLucky) { protected void dataCalculations() {
if (canGore) { if (canGore) {
String[] goreStrings = calculateAbilityDisplayValues(skillValue, Taming.goreMaxBonusLevel, Taming.goreMaxChance, isLucky); String[] goreStrings = calculateAbilityDisplayValues(Taming.goreMaxBonusLevel, Taming.goreMaxChance);
goreChance = goreStrings[0]; goreChance = goreStrings[0];
goreChanceLucky = goreStrings[1]; goreChanceLucky = goreStrings[1];
} }
} }
@Override @Override
protected void permissionsCheck(Player player) { protected void permissionsCheck() {
canBeastLore = Permissions.beastLore(player); canBeastLore = Permissions.beastLore(player);
canCallWild = Permissions.callOfTheWild(player, EntityType.HORSE) || Permissions.callOfTheWild(player, EntityType.WOLF) || Permissions.callOfTheWild(player, EntityType.OCELOT); canCallWild = Permissions.callOfTheWild(player);
canEnvironmentallyAware = Permissions.environmentallyAware(player); canEnvironmentallyAware = Permissions.environmentallyAware(player);
canFastFood = Permissions.fastFoodService(player); canFastFood = Permissions.fastFoodService(player);
canGore = Permissions.gore(player); canGore = Permissions.gore(player);
@@ -53,113 +47,116 @@ public class TamingCommand extends SkillCommand {
} }
@Override @Override
protected List<String> effectsDisplay() { protected boolean effectsHeaderPermissions() {
List<String> messages = new ArrayList<String>(); return canBeastLore || canCallWild || canEnvironmentallyAware || canFastFood || canGore || canSharpenedClaws || canShockProof || canThickFur || canHolyHound;
if (canBeastLore) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Taming.Effect.0"), LocaleLoader.getString("Taming.Effect.1")));
}
if (canGore) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Taming.Effect.2"), LocaleLoader.getString("Taming.Effect.3")));
}
if (canSharpenedClaws) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Taming.Effect.4"), LocaleLoader.getString("Taming.Effect.5")));
}
if (canEnvironmentallyAware) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Taming.Effect.6"), LocaleLoader.getString("Taming.Effect.7")));
}
if (canThickFur) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Taming.Effect.8"), LocaleLoader.getString("Taming.Effect.9")));
}
if (canShockProof) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Taming.Effect.10"), LocaleLoader.getString("Taming.Effect.11")));
}
if (canFastFood) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Taming.Effect.16"), LocaleLoader.getString("Taming.Effect.17")));
}
if (canHolyHound) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Taming.Effect.18"), LocaleLoader.getString("Taming.Effect.19")));
}
if (canCallWild) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Taming.Effect.12"), LocaleLoader.getString("Taming.Effect.13")));
messages.add(LocaleLoader.getString("Taming.Effect.14", Config.getInstance().getTamingCOTWOcelotCost()));
messages.add(LocaleLoader.getString("Taming.Effect.15", Config.getInstance().getTamingCOTWWolfCost()));
messages.add(LocaleLoader.getString("Taming.Effect.20", Config.getInstance().getTamingCOTWHorseCost()));
}
return messages;
} }
@Override @Override
protected List<String> statsDisplay(Player player, float skillValue, boolean hasEndurance, boolean isLucky) { protected void effectsDisplay() {
List<String> messages = new ArrayList<String>(); luckyEffectsDisplay();
if (canBeastLore) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Taming.Effect.0"), LocaleLoader.getString("Taming.Effect.1")));
}
if (canGore) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Taming.Effect.2"), LocaleLoader.getString("Taming.Effect.3")));
}
if (canSharpenedClaws) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Taming.Effect.4"), LocaleLoader.getString("Taming.Effect.5")));
}
if (canEnvironmentallyAware) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Taming.Effect.6"), LocaleLoader.getString("Taming.Effect.7")));
}
if (canThickFur) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Taming.Effect.8"), LocaleLoader.getString("Taming.Effect.9")));
}
if (canShockProof) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Taming.Effect.10"), LocaleLoader.getString("Taming.Effect.11")));
}
if (canFastFood) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Taming.Effect.16"), LocaleLoader.getString("Taming.Effect.17")));
}
if (canHolyHound) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Taming.Effect.18"), LocaleLoader.getString("Taming.Effect.19")));
}
if (canCallWild) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Taming.Effect.12"), LocaleLoader.getString("Taming.Effect.13")));
player.sendMessage(LocaleLoader.getString("Taming.Effect.14", Config.getInstance().getTamingCOTWOcelotCost()));
player.sendMessage(LocaleLoader.getString("Taming.Effect.15", Config.getInstance().getTamingCOTWWolfCost()));
}
}
@Override
protected boolean statsHeaderPermissions() {
return canEnvironmentallyAware || canFastFood || canGore || canSharpenedClaws || canShockProof || canThickFur || canHolyHound;
}
@Override
protected void statsDisplay() {
if (canFastFood) { if (canFastFood) {
if (skillValue < Taming.fastFoodServiceUnlockLevel) { if (skillValue < Taming.fastFoodServiceUnlockLevel) {
messages.add(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Taming.Ability.Locked.4", Taming.fastFoodServiceUnlockLevel))); player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Taming.Ability.Locked.4", Taming.fastFoodServiceUnlockLevel)));
} }
else { else {
messages.add(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Taming.Ability.Bonus.8"), LocaleLoader.getString("Taming.Ability.Bonus.9", percent.format(Taming.fastFoodServiceActivationChance / 100D)))); player.sendMessage(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Taming.Ability.Bonus.8"), LocaleLoader.getString("Taming.Ability.Bonus.9", percent.format(Taming.fastFoodServiceActivationChance / 100D))));
} }
} }
if (canEnvironmentallyAware) { if (canEnvironmentallyAware) {
if (skillValue < Taming.environmentallyAwareUnlockLevel) { if (skillValue < Taming.environmentallyAwareUnlockLevel) {
messages.add(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Taming.Ability.Locked.0", Taming.environmentallyAwareUnlockLevel))); player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Taming.Ability.Locked.0", Taming.environmentallyAwareUnlockLevel)));
} }
else { else {
messages.add(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Taming.Ability.Bonus.0"), LocaleLoader.getString("Taming.Ability.Bonus.1"))); player.sendMessage(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Taming.Ability.Bonus.0"), LocaleLoader.getString("Taming.Ability.Bonus.1")));
} }
} }
if (canThickFur) { if (canThickFur) {
if (skillValue < Taming.thickFurUnlockLevel) { if (skillValue < Taming.thickFurUnlockLevel) {
messages.add(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Taming.Ability.Locked.1", Taming.thickFurUnlockLevel))); player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Taming.Ability.Locked.1", Taming.thickFurUnlockLevel)));
} }
else { else {
messages.add(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Taming.Ability.Bonus.2"), LocaleLoader.getString("Taming.Ability.Bonus.3", Taming.thickFurModifier))); player.sendMessage(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Taming.Ability.Bonus.2"), LocaleLoader.getString("Taming.Ability.Bonus.3", Taming.thickFurModifier)));
} }
} }
if (canHolyHound) { if (canHolyHound) {
if (skillValue < Taming.holyHoundUnlockLevel) { if (skillValue < Taming.holyHoundUnlockLevel) {
messages.add(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Taming.Ability.Locked.5", Taming.holyHoundUnlockLevel))); player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Taming.Ability.Locked.5", Taming.holyHoundUnlockLevel)));
} }
else { else {
messages.add(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Taming.Ability.Bonus.10"), LocaleLoader.getString("Taming.Ability.Bonus.11"))); player.sendMessage(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Taming.Ability.Bonus.10"), LocaleLoader.getString("Taming.Ability.Bonus.11")));
} }
} }
if (canShockProof) { if (canShockProof) {
if (skillValue < Taming.shockProofUnlockLevel) { if (skillValue < Taming.shockProofUnlockLevel) {
messages.add(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Taming.Ability.Locked.2", Taming.shockProofUnlockLevel))); player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Taming.Ability.Locked.2", Taming.shockProofUnlockLevel)));
} }
else { else {
messages.add(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Taming.Ability.Bonus.4"), LocaleLoader.getString("Taming.Ability.Bonus.5", Taming.shockProofModifier))); player.sendMessage(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Taming.Ability.Bonus.4"), LocaleLoader.getString("Taming.Ability.Bonus.5", Taming.shockProofModifier)));
} }
} }
if (canSharpenedClaws) { if (canSharpenedClaws) {
if (skillValue < Taming.sharpenedClawsUnlockLevel) { if (skillValue < Taming.sharpenedClawsUnlockLevel) {
messages.add(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Taming.Ability.Locked.3", Taming.sharpenedClawsUnlockLevel))); player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Taming.Ability.Locked.3", Taming.sharpenedClawsUnlockLevel)));
} }
else { else {
messages.add(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Taming.Ability.Bonus.6"), LocaleLoader.getString("Taming.Ability.Bonus.7", Taming.sharpenedClawsBonusDamage))); player.sendMessage(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Taming.Ability.Bonus.6"), LocaleLoader.getString("Taming.Ability.Bonus.7", Taming.sharpenedClawsBonusDamage)));
} }
} }
if (canGore) { if (canGore) {
messages.add(LocaleLoader.getString("Taming.Combat.Chance.Gore", goreChance) + (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", goreChanceLucky) : "")); player.sendMessage(LocaleLoader.getString("Taming.Combat.Chance.Gore", goreChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", goreChanceLucky) : ""));
} }
return messages;
} }
} }

View File

@@ -1,10 +1,5 @@
package com.gmail.nossr50.commands.skills; package com.gmail.nossr50.commands.skills;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.entity.Player;
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.unarmed.Unarmed; import com.gmail.nossr50.skills.unarmed.Unarmed;
@@ -19,7 +14,7 @@ public class UnarmedCommand extends SkillCommand {
private String disarmChanceLucky; private String disarmChanceLucky;
private String ironGripChance; private String ironGripChance;
private String ironGripChanceLucky; private String ironGripChanceLucky;
private double ironArmBonus; private int ironArmBonus;
private boolean canBerserk; private boolean canBerserk;
private boolean canDisarm; private boolean canDisarm;
@@ -32,24 +27,24 @@ public class UnarmedCommand extends SkillCommand {
} }
@Override @Override
protected void dataCalculations(Player player, float skillValue, boolean isLucky) { protected void dataCalculations() {
// BERSERK // BERSERK
if (canBerserk) { if (canBerserk) {
String[] berserkStrings = calculateLengthDisplayValues(player, skillValue); String[] berserkStrings = calculateLengthDisplayValues();
berserkLength = berserkStrings[0]; berserkLength = berserkStrings[0];
berserkLengthEndurance = berserkStrings[1]; berserkLengthEndurance = berserkStrings[1];
} }
// DISARM // DISARM
if (canDisarm) { if (canDisarm) {
String[] disarmStrings = calculateAbilityDisplayValues(skillValue, Unarmed.disarmMaxBonusLevel, Unarmed.disarmMaxChance, isLucky); String[] disarmStrings = calculateAbilityDisplayValues(Unarmed.disarmMaxBonusLevel, Unarmed.disarmMaxChance);
disarmChance = disarmStrings[0]; disarmChance = disarmStrings[0];
disarmChanceLucky = disarmStrings[1]; disarmChanceLucky = disarmStrings[1];
} }
// DEFLECT // DEFLECT
if (canDeflect) { if (canDeflect) {
String[] deflectStrings = calculateAbilityDisplayValues(skillValue, Unarmed.deflectMaxBonusLevel, Unarmed.deflectMaxChance, isLucky); String[] deflectStrings = calculateAbilityDisplayValues(Unarmed.deflectMaxBonusLevel, Unarmed.deflectMaxChance);
deflectChance = deflectStrings[0]; deflectChance = deflectStrings[0];
deflectChanceLucky = deflectStrings[1]; deflectChanceLucky = deflectStrings[1];
} }
@@ -61,14 +56,14 @@ public class UnarmedCommand extends SkillCommand {
// IRON GRIP // IRON GRIP
if (canIronGrip) { if (canIronGrip) {
String[] ironGripStrings = calculateAbilityDisplayValues(skillValue, Unarmed.ironGripMaxBonusLevel, Unarmed.ironGripMaxChance, isLucky); String[] ironGripStrings = calculateAbilityDisplayValues(Unarmed.ironGripMaxBonusLevel, Unarmed.ironGripMaxChance);
ironGripChance = ironGripStrings[0]; ironGripChance = ironGripStrings[0];
ironGripChanceLucky = ironGripStrings[1]; ironGripChanceLucky = ironGripStrings[1];
} }
} }
@Override @Override
protected void permissionsCheck(Player player) { protected void permissionsCheck() {
canBerserk = Permissions.berserk(player); canBerserk = Permissions.berserk(player);
canBonusDamage = Permissions.bonusDamage(player, skill); canBonusDamage = Permissions.bonusDamage(player, skill);
canDeflect = Permissions.arrowDeflect(player); canDeflect = Permissions.arrowDeflect(player);
@@ -77,56 +72,60 @@ public class UnarmedCommand extends SkillCommand {
} }
@Override @Override
protected List<String> effectsDisplay() { protected boolean effectsHeaderPermissions() {
List<String> messages = new ArrayList<String>(); return canBerserk || canBonusDamage || canDeflect || canDisarm || canIronGrip;
if (canBerserk) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Unarmed.Effect.0"), LocaleLoader.getString("Unarmed.Effect.1")));
}
if (canDisarm) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Unarmed.Effect.2"), LocaleLoader.getString("Unarmed.Effect.3")));
}
if (canBonusDamage) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Unarmed.Effect.4"), LocaleLoader.getString("Unarmed.Effect.5")));
}
if (canDeflect) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Unarmed.Effect.6"), LocaleLoader.getString("Unarmed.Effect.7")));
}
if (canIronGrip) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Unarmed.Effect.8"), LocaleLoader.getString("Unarmed.Effect.9")));
}
return messages;
} }
@Override @Override
protected List<String> statsDisplay(Player player, float skillValue, boolean hasEndurance, boolean isLucky) { protected void effectsDisplay() {
List<String> messages = new ArrayList<String>(); luckyEffectsDisplay();
if (canBonusDamage) { if (canBerserk) {
messages.add(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Unarmed.Ability.Bonus.0"), LocaleLoader.getString("Unarmed.Ability.Bonus.1", ironArmBonus))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Unarmed.Effect.0"), LocaleLoader.getString("Unarmed.Effect.1")));
}
if (canDeflect) {
messages.add(LocaleLoader.getString("Unarmed.Ability.Chance.ArrowDeflect", deflectChance) + (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", deflectChanceLucky) : ""));
} }
if (canDisarm) { if (canDisarm) {
messages.add(LocaleLoader.getString("Unarmed.Ability.Chance.Disarm", disarmChance) + (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", disarmChanceLucky) : "")); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Unarmed.Effect.2"), LocaleLoader.getString("Unarmed.Effect.3")));
}
if (canBonusDamage) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Unarmed.Effect.4"), LocaleLoader.getString("Unarmed.Effect.5")));
}
if (canDeflect) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Unarmed.Effect.6"), LocaleLoader.getString("Unarmed.Effect.7")));
} }
if (canIronGrip) { if (canIronGrip) {
messages.add(LocaleLoader.getString("Unarmed.Ability.Chance.IronGrip", ironGripChance) + (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", ironGripChanceLucky) : "")); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Unarmed.Effect.8"), LocaleLoader.getString("Unarmed.Effect.9")));
}
}
@Override
protected boolean statsHeaderPermissions() {
return canBerserk || canBonusDamage || canDeflect || canDisarm || canIronGrip;
}
@Override
protected void statsDisplay() {
if (canBonusDamage) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Unarmed.Ability.Bonus.0"), LocaleLoader.getString("Unarmed.Ability.Bonus.1", ironArmBonus)));
}
if (canDeflect) {
player.sendMessage(LocaleLoader.getString("Unarmed.Ability.Chance.ArrowDeflect", deflectChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", deflectChanceLucky) : ""));
}
if (canDisarm) {
player.sendMessage(LocaleLoader.getString("Unarmed.Ability.Chance.Disarm", disarmChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", disarmChanceLucky) : ""));
}
if (canIronGrip) {
player.sendMessage(LocaleLoader.getString("Unarmed.Ability.Chance.IronGrip", ironGripChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", ironGripChanceLucky) : ""));
} }
if (canBerserk) { if (canBerserk) {
messages.add(LocaleLoader.getString("Unarmed.Ability.Berserk.Length", berserkLength) + (hasEndurance ? LocaleLoader.getString("Perks.ActivationTime.Bonus", berserkLengthEndurance) : "")); player.sendMessage(LocaleLoader.getString("Unarmed.Ability.Berserk.Length", berserkLength) + (hasEndurance ? LocaleLoader.getString("Perks.activationtime.bonus", berserkLengthEndurance) : ""));
} }
return messages;
} }
} }

View File

@@ -1,10 +1,5 @@
package com.gmail.nossr50.commands.skills; package com.gmail.nossr50.commands.skills;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.entity.Player;
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;
@@ -26,71 +21,75 @@ public class WoodcuttingCommand extends SkillCommand {
} }
@Override @Override
protected void dataCalculations(Player player, float skillValue, boolean isLucky) { protected void dataCalculations() {
// TREE FELLER // TREE FELLER
if (canTreeFell) { if (canTreeFell) {
String[] treeFellerStrings = calculateLengthDisplayValues(player, skillValue); String[] treeFellerStrings = calculateLengthDisplayValues();
treeFellerLength = treeFellerStrings[0]; treeFellerLength = treeFellerStrings[0];
treeFellerLengthEndurance = treeFellerStrings[1]; treeFellerLengthEndurance = treeFellerStrings[1];
} }
// DOUBLE DROPS // DOUBLE DROPS
if (canDoubleDrop) { if (canDoubleDrop) {
String[] doubleDropStrings = calculateAbilityDisplayValues(skillValue, Woodcutting.doubleDropsMaxLevel, Woodcutting.doubleDropsMaxChance, isLucky); String[] doubleDropStrings = calculateAbilityDisplayValues(Woodcutting.doubleDropsMaxLevel, Woodcutting.doubleDropsMaxChance);
doubleDropChance = doubleDropStrings[0]; doubleDropChance = doubleDropStrings[0];
doubleDropChanceLucky = doubleDropStrings[1]; doubleDropChanceLucky = doubleDropStrings[1];
} }
} }
@Override @Override
protected void permissionsCheck(Player player) { protected void permissionsCheck() {
canTreeFell = Permissions.treeFeller(player); canTreeFell = Permissions.treeFeller(player);
canDoubleDrop = Permissions.doubleDrops(player, skill) && !skill.getDoubleDropsDisabled(); canDoubleDrop = Permissions.doubleDrops(player, skill) && !skill.getDoubleDropsDisabled();
canLeafBlow = Permissions.leafBlower(player); canLeafBlow = Permissions.leafBlower(player);
} }
@Override @Override
protected List<String> effectsDisplay() { protected boolean effectsHeaderPermissions() {
List<String> messages = new ArrayList<String>(); return canDoubleDrop || canLeafBlow || canTreeFell;
if (canTreeFell) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Woodcutting.Effect.0"), LocaleLoader.getString("Woodcutting.Effect.1")));
}
if (canLeafBlow) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Woodcutting.Effect.2"), LocaleLoader.getString("Woodcutting.Effect.3")));
}
if (canDoubleDrop) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Woodcutting.Effect.4"), LocaleLoader.getString("Woodcutting.Effect.5")));
}
return messages;
} }
@Override @Override
protected List<String> statsDisplay(Player player, float skillValue, boolean hasEndurance, boolean isLucky) { protected void effectsDisplay() {
List<String> messages = new ArrayList<String>(); luckyEffectsDisplay();
if (canTreeFell) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Woodcutting.Effect.0"), LocaleLoader.getString("Woodcutting.Effect.1")));
}
if (canLeafBlow) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Woodcutting.Effect.2"), LocaleLoader.getString("Woodcutting.Effect.3")));
}
if (canDoubleDrop) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Woodcutting.Effect.4"), LocaleLoader.getString("Woodcutting.Effect.5")));
}
}
@Override
protected boolean statsHeaderPermissions() {
return canDoubleDrop || canLeafBlow || canTreeFell;
}
@Override
protected void statsDisplay() {
if (canLeafBlow) { if (canLeafBlow) {
int leafBlowerUnlockLevel = AdvancedConfig.getInstance().getLeafBlowUnlockLevel(); int leafBlowerUnlockLevel = AdvancedConfig.getInstance().getLeafBlowUnlockLevel();
if (skillValue < leafBlowerUnlockLevel) { if (skillValue < leafBlowerUnlockLevel) {
messages.add(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Woodcutting.Ability.Locked.0", leafBlowerUnlockLevel))); player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Woodcutting.Ability.Locked.0", leafBlowerUnlockLevel)));
} }
else { else {
messages.add(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Woodcutting.Ability.0"), LocaleLoader.getString("Woodcutting.Ability.1"))); player.sendMessage(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Woodcutting.Ability.0"), LocaleLoader.getString("Woodcutting.Ability.1")));
} }
} }
if (canDoubleDrop) { if (canDoubleDrop) {
messages.add(LocaleLoader.getString("Woodcutting.Ability.Chance.DDrop", doubleDropChance) + (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", doubleDropChanceLucky) : "")); player.sendMessage(LocaleLoader.getString("Woodcutting.Ability.Chance.DDrop", doubleDropChance) + (isLucky ? LocaleLoader.getString("Perks.lucky.bonus", doubleDropChanceLucky) : ""));
} }
if (canTreeFell) { if (canTreeFell) {
messages.add(LocaleLoader.getString("Woodcutting.Ability.Length", treeFellerLength) + (hasEndurance ? LocaleLoader.getString("Perks.ActivationTime.Bonus", treeFellerLengthEndurance) : "")); player.sendMessage(LocaleLoader.getString("Woodcutting.Ability.Length", treeFellerLength) + (hasEndurance ? LocaleLoader.getString("Perks.activationtime.bonus", treeFellerLengthEndurance) : ""));
} }
return messages;
} }
} }

View File

@@ -0,0 +1,57 @@
package com.gmail.nossr50.commands.spout;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.util.StringUtil;
import com.gmail.nossr50.datatypes.spout.huds.HudType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.google.common.collect.ImmutableList;
public class MchudCommand extends SpoutCommand {
private static final List<String> HUD_TYPES;
static {
ArrayList<String> types = new ArrayList<String>();
for (HudType type : HudType.values()) {
types.add(type.toString());
}
Collections.sort(types);
HUD_TYPES = ImmutableList.copyOf(types);
}
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
switch (args.length) {
case 1:
return StringUtil.copyPartialMatches(args[0], HUD_TYPES, new ArrayList<String>(HUD_TYPES.size()));
default:
return ImmutableList.of();
}
}
@Override
protected boolean noArguments(Command command, CommandSender sender, String[] args) {
return false;
}
@Override
protected boolean oneArgument(Command command, CommandSender sender, String[] args) {
try {
playerProfile.setHudType(HudType.valueOf(args[0].toUpperCase().trim()));
spoutHud.initializeXpBar();
spoutHud.updateXpBar();
return true;
}
catch (IllegalArgumentException ex) {
sender.sendMessage(LocaleLoader.getString("Commands.mchud.Invalid"));
return true;
}
}
}

View File

@@ -0,0 +1,54 @@
package com.gmail.nossr50.commands.spout;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.spout.SpoutConfig;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.spout.huds.McMMOHud;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager;
public abstract class SpoutCommand implements TabExecutor {
protected PlayerProfile playerProfile;
protected McMMOHud spoutHud;
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (CommandUtils.noConsoleUsage(sender)) {
return true;
}
if (!mcMMO.isSpoutEnabled() || !SpoutConfig.getInstance().getXPBarEnabled()) {
sender.sendMessage(LocaleLoader.getString("Commands.Disabled"));
return true;
}
playerProfile = UserManager.getPlayer((Player) sender).getProfile();
spoutHud = playerProfile.getSpoutHud();
if (spoutHud == null) {
sender.sendMessage(LocaleLoader.getString("Commands.Disabled"));
return true;
}
switch (args.length) {
case 0:
return noArguments(command, sender, args);
case 1:
return oneArgument(command, sender, args);
default:
return false;
}
}
protected abstract boolean noArguments(Command command, CommandSender sender, String[] args);
protected abstract boolean oneArgument(Command command, CommandSender sender, String[] args);
}

View File

@@ -0,0 +1,89 @@
package com.gmail.nossr50.commands.spout;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.util.StringUtil;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.skills.SkillUtils;
import com.google.common.collect.ImmutableList;
public class XplockCommand extends SpoutCommand {
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
switch (args.length) {
case 1:
List<String> matches = StringUtil.copyPartialMatches(args[0], CommandUtils.TRUE_FALSE_OPTIONS, new ArrayList<String>(CommandUtils.TRUE_FALSE_OPTIONS.size()));
if (matches.size() == 0) {
return StringUtil.copyPartialMatches(args[0], SkillType.SKILL_NAMES, new ArrayList<String>(SkillType.SKILL_NAMES.size()));
}
return matches;
default:
return ImmutableList.of();
}
}
@Override
protected boolean noArguments(Command command, CommandSender sender, String[] args) {
if (spoutHud.getXpBarLocked()) {
unlockXpBar(sender);
return true;
}
lockXpBar(sender, spoutHud.getLastGained());
return true;
}
@Override
protected boolean oneArgument(Command command, CommandSender sender, String[] args) {
if (CommandUtils.shouldEnableToggle(args[0])) {
lockXpBar(sender, spoutHud.getLastGained());
return true;
}
if (CommandUtils.shouldDisableToggle(args[0])) {
unlockXpBar(sender);
return true;
}
if (CommandUtils.isInvalidSkill(sender, args[0])) {
return true;
}
SkillType skill = SkillType.getSkill(args[0]);
if (CommandUtils.isChildSkill(sender, skill)) {
return true;
}
if (!Permissions.xplock(sender, skill)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
lockXpBar(sender, skill);
return true;
}
private void lockXpBar(CommandSender sender, SkillType skill) {
if (skill != null) {
spoutHud.setXpBarLocked(true);
spoutHud.setSkillLock(skill);
spoutHud.updateXpBar();
sender.sendMessage(LocaleLoader.getString("Commands.xplock.locked", SkillUtils.getSkillName(skill)));
}
}
private void unlockXpBar(CommandSender sender) {
spoutHud.setXpBarLocked(false);
sender.sendMessage(LocaleLoader.getString("Commands.xplock.unlocked"));
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -63,7 +63,7 @@ public abstract class AutoUpdateConfigLoader extends ConfigLoader {
output = output.replace(" ", " "); output = output.replace(" ", " ");
// Rip out Bukkit's attempt to save comments at the top of the file // Rip out Bukkit's attempt to save comments at the top of the file
while (output.replaceAll("[//s]", "").startsWith("#")) { while (output.indexOf('#') != -1) {
output = output.substring(output.indexOf('\n', output.indexOf('#')) + 1); output = output.substring(output.indexOf('\n', output.indexOf('#')) + 1);
} }
@@ -90,7 +90,7 @@ public abstract class AutoUpdateConfigLoader extends ConfigLoader {
// Dump to the new one // Dump to the new one
for (String key : comments.keySet()) { for (String key : comments.keySet()) {
if (output.contains(key)) { if (output.indexOf(key) != -1) {
output = output.substring(0, output.indexOf(key)) + comments.get(key) + output.substring(output.indexOf(key)); output = output.substring(0, output.indexOf(key)) + comments.get(key) + output.substring(output.indexOf(key));
} }
} }

View File

@@ -1,7 +1,5 @@
package com.gmail.nossr50.config; package com.gmail.nossr50.config;
import java.util.ArrayList;
import java.util.List;
import java.util.Set; import java.util.Set;
import org.bukkit.Material; import org.bukkit.Material;
@@ -18,7 +16,6 @@ public class Config extends AutoUpdateConfigLoader {
private Config() { private Config() {
super("config.yml"); super("config.yml");
validate();
} }
public static Config getInstance() { public static Config getInstance() {
@@ -29,167 +26,6 @@ public class Config extends AutoUpdateConfigLoader {
return instance; return instance;
} }
@Override
protected boolean validateKeys() {
// Validate all the settings!
List<String> reason = new ArrayList<String>();
/* General Settings */
if (getSaveInterval() <= 0) {
reason.add("General.Save_Interval should be greater than 0!");
}
/* Mob Healthbar */
if (getMobHealthbarTime() == 0) {
reason.add("Mob_Healthbar.Display_Time cannot be 0! Set to -1 to disable or set a valid value.");
}
/* Scoreboards */
if (getRankScoreboardTime() != -1 && getRankScoreboardTime() <= 0) {
reason.add("Scoreboard.Types.Rank.Display_Time should be greater than 0, or -1!");
}
if (getStatsScoreboardTime() != -1 && getStatsScoreboardTime() <= 0) {
reason.add("Scoreboard.Types.Stats.Display_Time should be greater than 0, or -1!");
}
if (getTopScoreboardTime() != -1 && getTopScoreboardTime() <= 0) {
reason.add("Scoreboard.Types.Top.Display_Time should be greater than 0, or -1!");
}
if (getInspectScoreboardTime() != -1 && getInspectScoreboardTime() <= 0) {
reason.add("Scoreboard.Types.Inspect.Display_Time should be greater than 0, or -1!");
}
if (getSkillScoreboardTime() != -1 && getSkillScoreboardTime() <= 0) {
reason.add("Scoreboard.Types.Skill.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 */
if (getPurgeInterval() < -1) {
reason.add("Database_Purging.Purge_Interval should be greater than, or equal to -1!");
}
if (getOldUsersCutoff() != -1 && getOldUsersCutoff() <= 0) {
reason.add("Database_Purging.Old_User_Cutoff should be greater than 0 or -1!");
}
/* Hardcore Mode */
if (getHardcoreDeathStatPenaltyPercentage() < 0.01 || getHardcoreDeathStatPenaltyPercentage() > 100) {
reason.add("Hardcore.Death_Stat_Loss.Penalty_Percentage only accepts values from 0.01 to 100!");
}
if (getHardcoreVampirismStatLeechPercentage() < 0.01 || getHardcoreVampirismStatLeechPercentage() > 100) {
reason.add("Hardcore.Vampirism.Leech_Percentage only accepts values from 0.01 to 100!");
}
/* Items */
if (getChimaeraUseCost() < 1 || getChimaeraUseCost() > 64) {
reason.add("Items.Chimaera_Wing.Use_Cost only accepts values from 1 to 64!");
}
if (getChimaeraRecipeCost() < 1 || getChimaeraRecipeCost() > 9) {
reason.add("Items.Chimaera_Wing.Recipe_Cost only accepts values from 1 to 64!");
}
if (getChimaeraItem() == null) {
reason.add("Items.Chimaera_Wing.Item_Name is invalid!");
}
/* Particles */
if (getLevelUpEffectsTier() < 1) {
reason.add("Particles.LevelUp_Tier should be at least 1!");
}
/* PARTY SETTINGS */
if (getAutoPartyKickInterval() < -1) {
reason.add("Party.AutoKick_Interval should be at least -1!");
}
if (getAutoPartyKickTime() < 0) {
reason.add("Party.Old_Party_Member_Cutoff should be at least 0!");
}
if (getPartyShareBonusBase() <= 0) {
reason.add("Party.Sharing.ExpShare_bonus_base should be greater than 0!");
}
if (getPartyShareBonusIncrease() < 0) {
reason.add("Party.Sharing.ExpShare_bonus_increase should be at least 0!");
}
if (getPartyShareBonusCap() <= 0) {
reason.add("Party.Sharing.ExpShare_bonus_cap should be greater than 0!");
}
if (getPartyShareRange() <= 0) {
reason.add("Party.Sharing.Range should be greater than 0!");
}
/* Inspect command distance */
if (getInspectDistance() <= 0) {
reason.add("Commands.inspect.Max_Distance should be greater than 0!");
}
if (getTreeFellerThreshold() <= 0) {
reason.add("Abilities.Limits.Tree_Feller_Threshold should be greater than 0!");
}
if (getDetonatorItem() == null) {
reason.add("Skills.Mining.Detonator_Item is invalid!");
}
if (getRepairAnvilMaterial() == null) {
reason.add("Skills.Repair.Anvil_Type is invalid!!");
}
if (getSalvageAnvilMaterial() == null) {
reason.add("Skills.Repair.Salvage_Anvil_Type is invalid!");
}
if (getRepairAnvilMaterial() == getSalvageAnvilMaterial()) {
reason.add("Cannot use the same item for Repair and Salvage anvils!");
}
if (getTamingCOTWWolfCost() < 1) {
reason.add("Skills.Taming.Call_Of_The_Wild.Bones_Required should be at least 1!");
}
if (getTamingCOTWOcelotCost() < 1) {
reason.add("Skills.Taming.Call_Of_The_Wild.Fish_Required should be at least 1!");
}
if (getTamingCOTWAmount(EntityType.OCELOT) <= 0) {
reason.add("Skills.Taming.Call_Of_The_Wild.Ocelot_Amount should be greater than 0!");
}
if (getTamingCOTWAmount(EntityType.WOLF) <= 0) {
reason.add("Skills.Taming.Call_Of_The_Wild.Wolf_Amount should be greater than 0!");
}
return noErrorsInConfig(reason);
}
@Override @Override
protected void loadKeys() {} protected void loadKeys() {}
@@ -205,19 +41,13 @@ public class Config extends AutoUpdateConfigLoader {
public boolean getStatsTrackingEnabled() { return config.getBoolean("General.Stats_Tracking", true); } public boolean getStatsTrackingEnabled() { return config.getBoolean("General.Stats_Tracking", true); }
public boolean getUpdateCheckEnabled() { return config.getBoolean("General.Update_Check", true); } public boolean getUpdateCheckEnabled() { return config.getBoolean("General.Update_Check", true); }
public boolean getPreferBeta() { return config.getBoolean("General.Prefer_Beta", false); } public boolean getPreferBeta() { return config.getBoolean("General.Prefer_Beta", false); }
public boolean getEventCallbackEnabled() { return config.getBoolean("General.Event_Callback", true); }
public boolean getBackupsEnabled() { return config.getBoolean("General.Generate_Backups", true); }
public boolean getVerboseLoggingEnabled() { return config.getBoolean("General.Verbose_Logging", false); } public boolean getVerboseLoggingEnabled() { return config.getBoolean("General.Verbose_Logging", false); }
public boolean getConfigOverwriteEnabled() { return config.getBoolean("General.Config_Update_Overwrite", true); } public boolean getConfigOverwriteEnabled() { return config.getBoolean("General.Config_Update_Overwrite", true); }
public String getPartyChatPrefix() { return config.getString("Commands.partychat.Chat_Prefix_Format", "[[GREEN]]([[WHITE]]{0}[[GREEN]])"); } public boolean getPartyDisplayNames() { return config.getBoolean("Commands.p.Use_Display_Names", true); }
public boolean getPartyChatColorLeaderName() { return config.getBoolean("Commands.partychat.Gold_Leader_Name", true); } public boolean getAdminDisplayNames() { return config.getBoolean("Commands.a.Use_Display_Names", true); }
public boolean getPartyDisplayNames() { return config.getBoolean("Commands.partychat.Use_Display_Names", true); }
public String getAdminChatPrefix() { return config.getString("Commands.adminchat.Chat_Prefix_Format", "[[AQUA]][[[WHITE]]{0}[[AQUA]]]"); }
public boolean getAdminDisplayNames() { return config.getBoolean("Commands.adminchat.Use_Display_Names", true); }
public boolean getMatchOfflinePlayers() { return config.getBoolean("Commands.Generic.Match_OfflinePlayers", false); }
public boolean getLevelUpSoundsEnabled() { return config.getBoolean("General.LevelUp_Sounds", true); }
/* Mob Healthbar */ /* Mob Healthbar */
public MobHealthbarType getMobHealthbarDefault() { public MobHealthbarType getMobHealthbarDefault() {
@@ -232,97 +62,84 @@ 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); }
public int getOldUsersCutoff() { return config.getInt("Database_Purging.Old_User_Cutoff", 6); } public int getOldUsersCutoff() { return config.getInt("Database_Purging.Old_User_Cutoff", 6); }
/* Backups */
public boolean getBackupsEnabled() { return config.getBoolean("Backups.Enabled", true); }
public boolean getKeepLast24Hours() { return config.getBoolean("Backups.Keep.Last_24_Hours", true); }
public boolean getKeepDailyLastWeek() { return config.getBoolean("Backups.Keep.Daily_Last_Week", true); }
public boolean getKeepWeeklyPastMonth() { return config.getBoolean("Backups.Keep.Weekly_Past_Months", true); }
/* mySQL */ /* mySQL */
public boolean getUseMySQL() { return config.getBoolean("MySQL.Enabled", false); } public boolean getUseMySQL() { return config.getBoolean("MySQL.Enabled", false); }
public String getMySQLTablePrefix() { return config.getString("MySQL.Database.TablePrefix", "mcmmo_"); } public String getMySQLTablePrefix() { return config.getString("MySQL.Database.TablePrefix", "mcmmo_"); }
public String getMySQLDatabaseName() { return getStringIncludingInts("MySQL.Database.Name"); } public String getMySQLDatabaseName() { return getStringIncludingInts(config, "MySQL.Database.Name"); }
public String getMySQLUserName() { return getStringIncludingInts("MySQL.Database.User_Name"); } public String getMySQLUserName() { return getStringIncludingInts(config, "MySQL.Database.User_Name"); }
public int getMySQLServerPort() { return config.getInt("MySQL.Server.Port", 3306); } public int getMySQLServerPort() { return config.getInt("MySQL.Server.Port", 3306); }
public String getMySQLServerName() { return config.getString("MySQL.Server.Address", "localhost"); } public String getMySQLServerName() { return config.getString("MySQL.Server.Address", "localhost"); }
public String getMySQLUserPassword() { return getStringIncludingInts("MySQL.Database.User_Password"); }
private String getStringIncludingInts(String key) { public String getMySQLUserPassword() {
String str = config.getString(key); if (getStringIncludingInts(config, "MySQL.Database.User_Password") != null) {
return getStringIncludingInts(config, "MySQL.Database.User_Password");
if (str == null) {
str = String.valueOf(config.getInt(key));
} }
if (str.equals("0")) { return "";
}
private static String getStringIncludingInts(ConfigurationSection cfg, String key) {
String str = cfg.getString(key);
if (str == null) {
str = String.valueOf(cfg.getInt(key));
}
if (str == "0") {
str = "No value set for '" + key + "'"; str = "No value set for '" + key + "'";
} }
return str; return str;
} }
/* Hardcore Mode */ /* Hardcore Mode */
public boolean getHardcoreStatLossEnabled(SkillType skillType) { return config.getBoolean("Hardcore.Death_Stat_Loss.Enabled." + StringUtils.getCapitalized(skillType.toString()), false); } public boolean getHardcoreEnabled() { return config.getBoolean("Hardcore.Enabled", false); }
public void setHardcoreStatLossEnabled(SkillType skillType, boolean enabled) { config.set("Hardcore.Death_Stat_Loss.Enabled." + StringUtils.getCapitalized(skillType.toString()), enabled); } public void setHardcoreEnabled(boolean enabled) { config.set("Hardcore.Enabled", enabled); }
public double getHardcoreDeathStatPenaltyPercentage() { return config.getDouble("Hardcore.Death_Stat_Loss.Penalty_Percentage", 75.0D); } public double getHardcoreDeathStatPenaltyPercentage() { return config.getDouble("Hardcore.Death_Stat_Loss_Penalty_Percentage", 75.0); }
public void setHardcoreDeathStatPenaltyPercentage(double value) { config.set("Hardcore.Death_Stat_Loss.Penalty_Percentage", value); } public void setHardcoreDeathStatPenaltyPercentage(double value) { config.set("Hardcore.Death_Stat_Loss_Penalty_Percentage", value); }
public boolean getHardcoreVampirismEnabled(SkillType skillType) { return config.getBoolean("Hardcore.Vampirism.Enabled." + StringUtils.getCapitalized(skillType.toString()), false); } public double getHardcoreVampirismStatLeechPercentage() { return config.getDouble("Hardcore.Vampirism_Stat_Leech_Percentage", 5.0); }
public void setHardcoreVampirismEnabled(SkillType skillType, boolean enabled) { config.set("Hardcore.Vampirism.Enabled." + StringUtils.getCapitalized(skillType.toString()), enabled); } public void setHardcoreVampirismStatLeechPercentage(double value) { config.set("Hardcore.Vampirism_Stat_Leech_Percentage", value); }
public double getHardcoreVampirismStatLeechPercentage() { return config.getDouble("Hardcore.Vampirism.Leech_Percentage", 5.0D); } public boolean getHardcoreVampirismEnabled() { return config.getBoolean("Hardcore.Vampirism", false); }
public void setHardcoreVampirismStatLeechPercentage(double value) { config.set("Hardcore.Vampirism.Leech_Percentage", value); } public void setHardcoreVampirismEnabled(boolean enabled) { config.set("Hardcore.Vampirism", enabled); }
/* 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); }
/* Items */ /* Items */
public int getChimaeraUseCost() { return config.getInt("Items.Chimaera_Wing.Use_Cost", 1); } public int getChimaeraUseCost() { return config.getInt("Items.Chimaera_Wing.Use_Cost", 1); }
public int getChimaeraRecipeCost() { return config.getInt("Items.Chimaera_Wing.Recipe_Cost", 5); } public int getChimaeraRecipeCost() { return config.getInt("Items.Chimaera_Wing.Recipe_Cost", 5); }
public Material getChimaeraItem() { return Material.matchMaterial(config.getString("Items.Chimaera_Wing.Item_Name", "Feather")); } public int getChimaeraItemId() { return config.getInt("Items.Chimaera_Wing.Item_ID", 288); }
public boolean getChimaeraEnabled() { return config.getBoolean("Items.Chimaera_Wing.Enabled", true); } public boolean getChimaeraEnabled() { return config.getBoolean("Items.Chimaera_Wing.Enabled", true); }
public boolean getChimaeraPreventUseUnderground() { return config.getBoolean("Items.Chimaera_Wing.Prevent_Use_Underground", true); } public boolean getChimaeraPreventUseUnderground() { return config.getBoolean("Items.Chimaera_Wing.Prevent_Use_Underground", true); }
public int getChimaeraCooldown() { return config.getInt("Items.Chimaera_Wing.Cooldown", 240); } public int getChimaeraCooldown() { return config.getInt("Items.Chimaera_Wing.Cooldown", 240); }
public int getChimaeraWarmup() { return config.getInt("Items.Chimaera_Wing.Warmup", 5); } public int getChimaeraWarmup() { return config.getInt("Items.Chimaera_Wing.Warmup", 5); }
public int getChimaeraRecentlyHurtCooldown() { return config.getInt("Items.Chimaera_Wing.RecentlyHurt_Cooldown", 60); } public int getChimaeraRecentlyHurtCooldown() { return config.getInt("Items.Chimaera_Wing.RecentlyHurt_Cooldown", 60); }
public boolean getChimaeraSoundEnabled() { return config.getBoolean("Items.Chimaera_Wing.Sound_Enabled", true); }
/* Particles */ /* Particles */
public boolean getAbilityActivationEffectEnabled() { return config.getBoolean("Particles.Ability_Activation", true); } public boolean getAbilityActivationEffectEnabled() { return config.getBoolean("Particles.Ability_Activation", true); }
@@ -338,11 +155,11 @@ public class Config extends AutoUpdateConfigLoader {
public int getAutoPartyKickInterval() { return config.getInt("Party.AutoKick_Interval", 12); } public int getAutoPartyKickInterval() { return config.getInt("Party.AutoKick_Interval", 12); }
public int getAutoPartyKickTime() { return config.getInt("Party.Old_Party_Member_Cutoff", 7); } public int getAutoPartyKickTime() { return config.getInt("Party.Old_Party_Member_Cutoff", 7); }
public boolean getExpShareEnabled() { return config.getBoolean("Party.Sharing.ExpShare_enabled", true); } public boolean getExpShareEnabled() { return config.getBoolean("Party.Sharing.ExpShare_enabled", true); }
public double getPartyShareBonusBase() { return config.getDouble("Party.Sharing.ExpShare_bonus_base", 1.1D); } public double getPartyShareBonusBase() { return config.getDouble("Party.Sharing.ExpShare_bonus_base", 1.1); }
public double getPartyShareBonusIncrease() { return config.getDouble("Party.Sharing.ExpShare_bonus_increase", 0.05D); } public double getPartyShareBonusIncrease() { return config.getDouble("Party.Sharing.ExpShare_bonus_increase", 0.05); }
public double getPartyShareBonusCap() { return config.getDouble("Party.Sharing.ExpShare_bonus_cap", 1.5D); } public double getPartyShareBonusCap() { return config.getDouble("Party.Sharing.ExpShare_bonus_cap", 1.5); }
public boolean getItemShareEnabled() { return config.getBoolean("Party.Sharing.ItemShare_enabled", true); } public boolean getItemShareEnabled() { return config.getBoolean("Party.Sharing.ItemShare_enabled", true); }
public double getPartyShareRange() { return config.getDouble("Party.Sharing.Range", 75.0D); } public double getPartyShareRange() { return config.getDouble("Party.Sharing.Range", 75.0); }
/* Party Teleport Settings */ /* Party Teleport Settings */
public int getPTPCommandCooldown() { return config.getInt("Commands.ptp.Cooldown", 120); } public int getPTPCommandCooldown() { return config.getInt("Commands.ptp.Cooldown", 120); }
@@ -353,7 +170,7 @@ public class Config extends AutoUpdateConfigLoader {
public boolean getPTPCommandWorldPermissions() { return config.getBoolean("Commands.ptp.World_Based_Permissions", false); } public boolean getPTPCommandWorldPermissions() { return config.getBoolean("Commands.ptp.World_Based_Permissions", false); }
/* Inspect command distance */ /* Inspect command distance */
public double getInspectDistance() { return config.getDouble("Commands.inspect.Max_Distance", 30.0D); } public double getInspectDistance() { return config.getDouble("Commands.inspect.Max_Distance", 30); }
/* /*
* ABILITY SETTINGS * ABILITY SETTINGS
@@ -365,10 +182,11 @@ public class Config extends AutoUpdateConfigLoader {
public boolean getAbilitiesOnlyActivateWhenSneaking() { return config.getBoolean("Abilities.Activation.Only_Activate_When_Sneaking", false); } public boolean getAbilitiesOnlyActivateWhenSneaking() { return config.getBoolean("Abilities.Activation.Only_Activate_When_Sneaking", false); }
public int getCooldown(AbilityType ability) { return config.getInt("Abilities.Cooldowns." + ability.toString()); } public int getCooldown(AbilityType ability) { return config.getInt("Abilities.Cooldowns." + ability.toString()); }
public int getMaxLength(AbilityType ability) { return config.getInt("Abilities.Max_Seconds." + ability.toString()); } public int getMaxTicks(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 boolean getAbilitiesDamageTools() { return config.getBoolean("Abilities.Tools.Durability_Loss_Enabled", true); }
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); }
@@ -376,6 +194,8 @@ public class Config extends AutoUpdateConfigLoader {
/* /*
* SKILL SETTINGS * SKILL SETTINGS
*/ */
public int getXp(SkillType skill, Material material) { return config.getInt("Experience." + StringUtils.getCapitalized(skill.toString()) + "." + StringUtils.getPrettyItemString(material).replace(" ", "_")); }
public boolean getDoubleDropsEnabled(SkillType skill, Material material) { return config.getBoolean("Double_Drops." + StringUtils.getCapitalized(skill.toString()) + "." + StringUtils.getPrettyItemString(material).replace(" ", "_")); } public boolean getDoubleDropsEnabled(SkillType skill, Material material) { return config.getBoolean("Double_Drops." + StringUtils.getCapitalized(skill.toString()) + "." + StringUtils.getPrettyItemString(material).replace(" ", "_")); }
public boolean getDoubleDropsDisabled(SkillType skill) { public boolean getDoubleDropsDisabled(SkillType skill) {
@@ -396,20 +216,18 @@ public class Config extends AutoUpdateConfigLoader {
/* Acrobatics */ /* Acrobatics */
public boolean getDodgeLightningDisabled() { return config.getBoolean("Skills.Acrobatics.Prevent_Dodge_Lightning", false); } public boolean getDodgeLightningDisabled() { return config.getBoolean("Skills.Acrobatics.Prevent_Dodge_Lightning", false); }
public boolean getPreventXPAfterTeleport() { return config.getBoolean("Skills.Acrobatics.Prevent_XP_After_Teleport", true); }
/* Fishing */ /* Fishing */
public int getFishingBaseXP() { return config.getInt("Experience.Fishing.Base", 800); }
public boolean getFishingDropsEnabled() { return config.getBoolean("Skills.Fishing.Drops_Enabled", true); } public boolean getFishingDropsEnabled() { return config.getBoolean("Skills.Fishing.Drops_Enabled", true); }
/* Mining */ /* Mining */
public Material getDetonatorItem() { return Material.matchMaterial(config.getString("Skills.Mining.Detonator_Name", "FLINT_AND_STEEL")); } public int getDetonatorItemID() { return config.getInt("Skills.Mining.Detonator_ID", 259); }
/* Repair */ /* Repair */
public boolean getRepairAnvilMessagesEnabled() { return config.getBoolean("Skills.Repair.Anvil_Messages", true); } public boolean getRepairAnvilMessagesEnabled() { return config.getBoolean("Skills.Repair.Anvil_Messages", true); }
public boolean getRepairAnvilPlaceSoundsEnabled() { return config.getBoolean("Skills.Repair.Anvil_Placed_Sounds", true); } public int getRepairAnvilId() { return config.getInt("Skills.Repair.Anvil_ID", 42); }
public boolean getRepairAnvilUseSoundsEnabled() { return config.getBoolean("Skills.Repair.Anvil_Use_Sounds", true); } public int getSalvageAnvilId() { return config.getInt("Skills.Repair.Salvage_Anvil_ID", 41); }
public Material getRepairAnvilMaterial() { return Material.matchMaterial(config.getString("Skills.Repair.Anvil_Material", "IRON_BLOCK")); }
public Material getSalvageAnvilMaterial() { return Material.matchMaterial(config.getString("Skills.Repair.Salvage_Anvil_Material", "GOLD_BLOCK")); }
public boolean getSalvageTools() { return config.getBoolean("Skills.Repair.Salvage_tools", true); } public boolean getSalvageTools() { return config.getBoolean("Skills.Repair.Salvage_tools", true); }
public boolean getSalvageArmor() { return config.getBoolean("Skills.Repair.Salvage_armor", true); } public boolean getSalvageArmor() { return config.getBoolean("Skills.Repair.Salvage_armor", true); }
public boolean getRepairConfirmRequired() { return config.getBoolean("Skills.Repair.Confirm_Required", true); } public boolean getRepairConfirmRequired() { return config.getBoolean("Skills.Repair.Confirm_Required", true); }
@@ -418,23 +236,27 @@ public class Config extends AutoUpdateConfigLoader {
public boolean getUnarmedBlockCrackerSmoothbrickToCracked() { return config.getBoolean("Skills.Unarmed.Block_Cracker.SmoothBrick_To_CrackedBrick", true); } public boolean getUnarmedBlockCrackerSmoothbrickToCracked() { return config.getBoolean("Skills.Unarmed.Block_Cracker.SmoothBrick_To_CrackedBrick", true); }
/* Taming */ /* Taming */
public int getTamingCOTWHorseCost() { return config.getInt("Skills.Taming.Call_Of_The_Wild.Apples_Required", 10); } public int getTamingXPWolf() { return config.getInt("Experience.Taming.Animal_Taming.Wolf", 250); }
public int getTamingXPOcelot() { return config.getInt("Experience.Taming.Animal_Taming.Ocelot", 500); }
public int getTamingCOTWWolfCost() { return config.getInt("Skills.Taming.Call_Of_The_Wild.Bones_Required", 10); } public int getTamingCOTWWolfCost() { return config.getInt("Skills.Taming.Call_Of_The_Wild.Bones_Required", 10); }
public int getTamingCOTWOcelotCost() { return config.getInt("Skills.Taming.Call_Of_The_Wild.Fish_Required", 10); } public int getTamingCOTWOcelotCost() { return config.getInt("Skills.Taming.Call_Of_The_Wild.Fish_Required", 10); }
public double getTamingCOTWRange() { return config.getDouble("Skills.Taming.Call_Of_The_Wild.Range", 40.0D); }
public int getTamingCOTWAmount(EntityType type) { return config.getInt("Skills.Taming.Call_Of_The_Wild." + StringUtils.getPrettyEntityTypeString(type)+ "_Amount"); }
/* Woodcutting */ /* Woodcutting */
public int getWoodcuttingXPOak() { return config.getInt("Experience.Woodcutting.Oak", 70); }
public int getWoodcuttingXPBirch() { return config.getInt("Experience.Woodcutting.Birch", 90); }
public int getWoodcuttingXPSpruce() { return config.getInt("Experience.Woodcutting.Spruce", 80); }
public int getWoodcuttingXPJungle() { return config.getInt("Experience.Woodcutting.Jungle", 100); }
public int getWoodcuttingXPHugeBrownMushroom() { return config.getInt("Experience.Woodcutting.Huge_Mushroom_Brown", 70); }
public int getWoodcuttingXPHugeRedMushroom() { return config.getInt("Experience.Woodcutting.Huge_Mushroom_Red", 70); }
public boolean getOakDoubleDropsEnabled() { return config.getBoolean("Double_Drops.Woodcutting.Oak", true); } public boolean getOakDoubleDropsEnabled() { return config.getBoolean("Double_Drops.Woodcutting.Oak", true); }
public boolean getBirchDoubleDropsEnabled() { return config.getBoolean("Double_Drops.Woodcutting.Birch", true); } public boolean getBirchDoubleDropsEnabled() { return config.getBoolean("Double_Drops.Woodcutting.Birch", true); }
public boolean getSpruceDoubleDropsEnabled() { return config.getBoolean("Double_Drops.Woodcutting.Spruce", true); } public boolean getSpruceDoubleDropsEnabled() { return config.getBoolean("Double_Drops.Woodcutting.Spruce", true); }
public boolean getJungleDoubleDropsEnabled() { return config.getBoolean("Double_Drops.Woodcutting.Jungle", true); } public boolean getJungleDoubleDropsEnabled() { return config.getBoolean("Double_Drops.Woodcutting.Jungle", true); }
public boolean getTreeFellerSoundsEnabled() { return config.getBoolean("Skills.Woodcutting.Tree_Feller_Sounds", 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() {
@@ -450,4 +272,27 @@ public class Config extends AutoUpdateConfigLoader {
/* PVP & PVE Settings */ /* PVP & PVE Settings */
public boolean getPVPEnabled(SkillType skill) { return config.getBoolean("Skills." + StringUtils.getCapitalized(skill.toString()) + ".Enabled_For_PVP", true); } public boolean getPVPEnabled(SkillType skill) { return config.getBoolean("Skills." + StringUtils.getCapitalized(skill.toString()) + ".Enabled_For_PVP", true); }
public boolean getPVEEnabled(SkillType skill) { return config.getBoolean("Skills." + StringUtils.getCapitalized(skill.toString()) + ".Enabled_For_PVE", true); } public boolean getPVEEnabled(SkillType skill) { return config.getBoolean("Skills." + StringUtils.getCapitalized(skill.toString()) + ".Enabled_For_PVE", true); }
/*
* XP SETTINGS
*/
/* General Settings */
public boolean getExperienceGainsPlayerVersusPlayerEnabled() { return config.getBoolean("Experience.PVP.Rewards", true); }
public double getExperienceGainsGlobalMultiplier() { return config.getDouble("Experience.Gains.Multiplier.Global", 1.0); }
public void setExperienceGainsGlobalMultiplier(double value) { config.set("Experience.Gains.Multiplier.Global", value); }
/* Combat XP Multipliers */
public double getPlayerVersusPlayerXP() { return config.getDouble("Experience.Gains.Multiplier.PVP", 1.0); }
public double getCombatXP(EntityType entity) { return config.getDouble("Experience.Combat.Multiplier." + StringUtils.getPrettyEntityTypeString(entity).replace(" ", "_")); }
public double getAnimalsXP() { return config.getDouble("Experience.Combat.Multiplier.Animals", 1.0); }
public double getWitherSkeletonXP() { return config.getDouble("Experience.Combat.Multiplier.Wither_Skeleton", 4.0); }
public double getSpawnedMobXpMultiplier() { return config.getDouble("Experience.Gains.Mobspawners.Multiplier", 0.0); }
/* XP Formula Multiplier */
public int getFormulaMultiplierCurve() { return config.getInt("Experience.Formula.Curve_Modifier", 20); }
public double getFormulaSkillModifier(SkillType skill) { return config.getDouble("Experience.Formula.Modifier." + StringUtils.getCapitalized(skill.toString())); }
} }

View File

@@ -1,7 +1,11 @@
package com.gmail.nossr50.config; package com.gmail.nossr50.config;
import java.io.File; import java.io.File;
import java.util.List; import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
@@ -11,7 +15,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 +33,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,45 +44,50 @@ public abstract class ConfigLoader {
protected abstract void loadKeys(); protected abstract void loadKeys();
protected boolean validateKeys() { protected void createFile() {
return true; configFile.getParentFile().mkdirs();
}
protected boolean noErrorsInConfig(List<String> issues) { InputStream inputStream = plugin.getResource(fileName);
for (String issue : issues) {
plugin.getLogger().warning(issue); if (inputStream == null) {
plugin.getLogger().severe("Missing resource file: '" + fileName + "' please notify the plugin authors");
return;
} }
return issues.isEmpty(); OutputStream outputStream = null;
}
protected void validate() { try {
if (validateKeys()) { outputStream = new FileOutputStream(configFile);
plugin.debug("No errors found in " + fileName + "!");
int read;
byte[] bytes = new byte[1024];
while ((read = inputStream.read(bytes)) != -1) {
outputStream.write(bytes, 0, read);
}
} }
else { catch (FileNotFoundException e) {
plugin.getLogger().warning("Errors were found in " + fileName + "! mcMMO was disabled!"); e.printStackTrace();
plugin.getServer().getPluginManager().disablePlugin(plugin);
plugin.noErrorsInConfigFiles = false;
} }
} catch (IOException e) {
e.printStackTrace();
public File getFile() {
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);
} }
finally {
if (outputStream != null) {
try {
outputStream.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
plugin.getLogger().warning("Reloading " + fileName + " with new values..."); try {
loadFile(); inputStream.close();
loadKeys(); }
catch (IOException e) {
e.printStackTrace();
}
}
} }
} }

View File

@@ -1,222 +0,0 @@
package com.gmail.nossr50.config.experience;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import com.gmail.nossr50.config.AutoUpdateConfigLoader;
import com.gmail.nossr50.datatypes.experience.FormulaType;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.skills.repair.repairables.RepairMaterialType;
import com.gmail.nossr50.util.StringUtils;
public class ExperienceConfig extends AutoUpdateConfigLoader {
private static ExperienceConfig instance;
private ExperienceConfig() {
super("experience.yml");
validate();
}
public static ExperienceConfig getInstance() {
if (instance == null) {
instance = new ExperienceConfig();
}
return instance;
}
@Override
protected void loadKeys() {}
@Override
protected boolean validateKeys() {
List<String> reason = new ArrayList<String>();
/*
* FORMULA SETTINGS
*/
/* Curve values */
if (getMultiplier(FormulaType.EXPONENTIAL) <= 0) {
reason.add("Experience_Formula.Exponential_Values.multiplier should be greater than 0!");
}
if (getMultiplier(FormulaType.LINEAR) <= 0) {
reason.add("Experience_Formula.Linear_Values.multiplier should be greater than 0!");
}
if (getExponent(FormulaType.EXPONENTIAL) <= 0) {
reason.add("Experience_Formula.Exponential_Values.exponent should be greater than 0!");
}
/* Global modifier */
if (getExperienceGainsGlobalMultiplier() <= 0) {
reason.add("Experience_Formula.Multiplier.Global should be greater than 0!");
}
/* PVP modifier */
if (getPlayerVersusPlayerXP() < 0) {
reason.add("Experience_Formula.Multiplier.PVP should be at least 0!");
}
/* Spawned Mob modifier */
if (getSpawnedMobXpMultiplier() < 0) {
reason.add("Experience_Formula.Mobspawners.Multiplier should be at least 0!");
}
/* Conversion */
if (getExpModifier() <= 0) {
reason.add("Conversion.Exp_Modifier should be greater than 0!");
}
/*
* XP SETTINGS
*/
/* Combat XP Multipliers */
if (getAnimalsXP() < 0) {
reason.add("Experience.Combat.Multiplier.Animals should be at least 0!");
}
if (getWitherSkeletonXP() < 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 */
if (getFishingBaseXP() <= 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 */
if (getRepairXPBase() <= 0) {
reason.add("Experience.Repair.Base should be greater than 0!");
}
/* Taming */
if (getTamingXPWolf() <= 0) {
reason.add("Experience.Taming.Animal_Taming.Wolf should be greater than 0!");
}
if (getTamingXPOcelot() <= 0) {
reason.add("Experience.Taming.Animal_Taming.Ocelot should be greater than 0!");
}
/* Woodcutting */
if (getWoodcuttingXPOak() <= 0) {
reason.add("Experience.Woodcutting.Oak should be greater than 0!");
}
if (getWoodcuttingXPBirch() <= 0) {
reason.add("Experience.Woodcutting.Birch should be greater than 0!");
}
if (getWoodcuttingXPSpruce() <= 0) {
reason.add("Experience.Woodcutting.Spruce should be greater than 0!");
}
if (getWoodcuttingXPJungle() <= 0) {
reason.add("Experience.Woodcutting.Jungle should be greater than 0!");
}
if (getWoodcuttingXPHugeBrownMushroom() <= 0) {
reason.add("Experience.Woodcutting.Huge_Mushroom_Brown should be greater than 0!");
}
if (getWoodcuttingXPHugeRedMushroom() <= 0) {
reason.add("Experience.Woodcutting.Huge_Mushroom_Red should be greater than 0!");
}
return noErrorsInConfig(reason);
}
/*
* FORMULA SETTINGS
*/
/* Curve settings */
public FormulaType getFormulaType() { return FormulaType.getFormulaType(config.getString("Experience_Formula.Curve")); }
public boolean getCumulativeCurveEnabled() { return config.getBoolean("Experience_Formula.Cumulative_Curve", false); }
/* Curve values */
public double getMultiplier(FormulaType type) { return config.getDouble("Experience_Formula." + StringUtils.getCapitalized(type.toString()) + "_Values.multiplier"); }
public int getBase(FormulaType type) { return config.getInt("Experience_Formula." + StringUtils.getCapitalized(type.toString()) + "_Values.base"); }
public double getExponent(FormulaType type) { return config.getDouble("Experience_Formula." + StringUtils.getCapitalized(type.toString()) +"_Values.exponent"); }
/* Global modifier */
public double getExperienceGainsGlobalMultiplier() { return config.getDouble("Experience_Formula.Multiplier.Global", 1.0); }
public void setExperienceGainsGlobalMultiplier(double value) { config.set("Experience_Formula.Multiplier.Global", value); }
/* PVP modifier */
public double getPlayerVersusPlayerXP() { return config.getDouble("Experience_Formula.Multiplier.PVP", 1.0); }
/* Spawned Mob modifier */
public double getSpawnedMobXpMultiplier() { return config.getDouble("Experience_Formula.Mobspawners.Multiplier", 0.0); }
/* Skill modifiers */
public double getFormulaSkillModifier(SkillType skill) { return config.getDouble("Experience_Formula.Modifier." + StringUtils.getCapitalized(skill.toString())); }
/* Conversion */
public double getExpModifier() { return config.getDouble("Conversion.Exp_Modifier", 1); }
/*
* XP SETTINGS
*/
/* General Settings */
public boolean getExperienceGainsPlayerVersusPlayerEnabled() { return config.getBoolean("Experience.PVP.Rewards", true); }
/* Combat XP Multipliers */
public double getCombatXP(EntityType entity) { return config.getDouble("Experience.Combat.Multiplier." + StringUtils.getPrettyEntityTypeString(entity).replace(" ", "_")); }
public double getAnimalsXP() { return config.getDouble("Experience.Combat.Multiplier.Animals", 1.0); }
public double getWitherSkeletonXP() { return config.getDouble("Experience.Combat.Multiplier.Wither_Skeleton", 4.0); }
/* Materials */
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 */
public int getFishingBaseXP() { return config.getInt("Experience.Fishing.Base", 800); }
public int getFishingShakeXP() { return config.getInt("Experience.Fishing.Shake", 50); }
/* Repair */
public double getRepairXPBase() { return config.getDouble("Experience.Repair.Base", 1000.0); }
public double getRepairXP(RepairMaterialType repairMaterialType) { return config.getDouble("Experience.Repair." + StringUtils.getCapitalized(repairMaterialType.toString())); }
/* Taming */
public int getTamingXPHorse() { return config.getInt("Experience.Taming.Animal_Taming.Horse", 1000); }
public int getTamingXPWolf() { return config.getInt("Experience.Taming.Animal_Taming.Wolf", 250); }
public int getTamingXPOcelot() { return config.getInt("Experience.Taming.Animal_Taming.Ocelot", 500); }
/* Woodcutting */
public int getWoodcuttingXPOak() { return config.getInt("Experience.Woodcutting.Oak", 70); }
public int getWoodcuttingXPBirch() { return config.getInt("Experience.Woodcutting.Birch", 90); }
public int getWoodcuttingXPSpruce() { return config.getInt("Experience.Woodcutting.Spruce", 80); }
public int getWoodcuttingXPJungle() { return config.getInt("Experience.Woodcutting.Jungle", 100); }
public int getWoodcuttingXPHugeBrownMushroom() { return config.getInt("Experience.Woodcutting.Huge_Mushroom_Brown", 70); }
public int getWoodcuttingXPHugeRedMushroom() { return config.getInt("Experience.Woodcutting.Huge_Mushroom_Red", 70); }
}

View File

@@ -1,34 +1,33 @@
package com.gmail.nossr50.config.mods; package com.gmail.nossr50.config.mods;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
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.datatypes.mods.CustomItem;
import com.gmail.nossr50.skills.repair.repairables.RepairItemType; import com.gmail.nossr50.skills.repair.Repairable;
import com.gmail.nossr50.skills.repair.repairables.RepairMaterialType; import com.gmail.nossr50.skills.repair.RepairableFactory;
import com.gmail.nossr50.skills.repair.repairables.Repairable;
import com.gmail.nossr50.skills.repair.repairables.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>(); public List<Integer> customBootIDs = new ArrayList<Integer>();
private List<Material> customChestplates = new ArrayList<Material>(); public List<Integer> customChestplateIDs = new ArrayList<Integer>();
private List<Material> customHelmets = new ArrayList<Material>(); public List<Integer> customHelmetIDs = new ArrayList<Integer>();
private List<Material> customLeggings = new ArrayList<Material>(); public List<Integer> customLeggingIDs = new ArrayList<Integer>();
public List<Integer> customIDs = new ArrayList<Integer>();
public List<CustomItem> customArmorList = new ArrayList<CustomItem>();
public HashMap<Integer, CustomItem> customArmor = new HashMap<Integer, CustomItem>();
public CustomArmorConfig() { public CustomArmorConfig() {
super("mods", "armor.yml"); super("ModConfigs", "armor.yml");
loadKeys(); loadKeys();
} }
@@ -52,22 +51,13 @@ public class CustomArmorConfig extends ConfigLoader {
protected void loadKeys() { protected void loadKeys() {
repairables = new ArrayList<Repairable>(); repairables = new ArrayList<Repairable>();
loadArmor("Boots", customBoots); loadArmor("Boots", customBootIDs);
loadArmor("Chestplates", customChestplates); loadArmor("Chestplates", customChestplateIDs);
loadArmor("Helmets", customHelmets); loadArmor("Helmets", customHelmetIDs);
loadArmor("Leggings", customLeggings); loadArmor("Leggings", customLeggingIDs);
if (needsUpdate) {
needsUpdate = false;
backup();
}
} }
private void loadArmor(String armorType, List<Material> materialList) { private void loadArmor(String armorType, List<Integer> idList) {
if (needsUpdate) {
return;
}
ConfigurationSection armorSection = config.getConfigurationSection(armorType); ConfigurationSection armorSection = config.getConfigurationSection(armorType);
if (armorSection == null) { if (armorSection == null) {
@@ -77,60 +67,35 @@ 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")) { int id = config.getInt(armorType + "." + armorName + ".ID", 0);
needsUpdate = true; boolean repairable = config.getBoolean(armorType + "." + armorName + ".Repairable");
return; int repairID = config.getInt(armorType + "." + armorName + ".Repair_Material_ID", 0);
} byte repairData = (byte) config.getInt(armorType + "." + armorName + ".Repair_Material_Data_Value", 0);
int repairQuantity = config.getInt(armorType + "." + armorName + ".Repair_Material_Quantity", 0);
short durability = (short) config.getInt(armorType + "." + armorName + ".Durability", 0);
Material armorMaterial = Material.matchMaterial(armorName); if (id == 0) {
plugin.getLogger().warning("Missing ID. This item will be skipped.");
if (armorMaterial == null) {
plugin.getLogger().warning("Invalid material name. This item will be skipped. - " + armorName);
continue; continue;
} }
boolean repairable = config.getBoolean(armorType + "." + armorName + ".Repairable"); if (repairable && (repairID == 0 || repairQuantity == 0 || durability == 0)) {
Material repairMaterial = Material.matchMaterial(config.getString(armorType + "." + armorName + ".Repair_Material", "")); plugin.getLogger().warning("Incomplete repair information. This item will be unrepairable.");
if (repairMaterial == null) {
plugin.getLogger().warning("Incomplete repair information. This item will be unrepairable. - " + armorName);
repairable = false; repairable = false;
} }
CustomItem armor;
if (repairable) { if (repairable) {
byte repairData = (byte) config.getInt(armorType + "." + armorName + ".Repair_Material_Data_Value", -1); repairables.add(RepairableFactory.getRepairable(id, repairID, repairData, repairQuantity, durability));
int repairQuantity = Repair.getRepairAndSalvageQuantities(new ItemStack(armorMaterial), repairMaterial, repairData);
if (repairQuantity == 0) {
repairQuantity = config.getInt(armorType + "." + armorName + ".Repair_Material_Data_Quantity", 2);
}
short durability = armorMaterial.getMaxDurability();
if (durability == 0) {
durability = (short) config.getInt(armorType + "." + armorName + ".Durability", 70);
}
repairables.add(RepairableFactory.getRepairable(armorMaterial, repairMaterial, repairData, 0, repairQuantity, durability, RepairItemType.ARMOR, RepairMaterialType.OTHER, 1.0));
} }
materialList.add(armorMaterial); armor = new CustomItem(id, durability);
idList.add(id);
customIDs.add(id);
customArmorList.add(armor);
customArmor.put(id, armor);
} }
} }
public boolean isCustomBoots(Material material) {
return customBoots.contains(material);
}
public boolean isCustomChestplate(Material material) {
return customChestplates.contains(material);
}
public boolean isCustomHelmet(Material material) {
return customHelmets.contains(material);
}
public boolean isCustomLeggings(Material material) {
return customLeggings.contains(material);
}
} }

View File

@@ -1,12 +1,11 @@
package com.gmail.nossr50.config.mods; package com.gmail.nossr50.config.mods;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
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,21 +14,20 @@ 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; public List<ItemStack> customExcavationBlocks = new ArrayList<ItemStack>();
public List<ItemStack> customHerbalismBlocks = new ArrayList<ItemStack>();
public List<ItemStack> customMiningBlocks = new ArrayList<ItemStack>();
public List<ItemStack> customWoodcuttingBlocks = new ArrayList<ItemStack>();
public List<ItemStack> customOres = new ArrayList<ItemStack>();
public List<ItemStack> customLogs = new ArrayList<ItemStack>();
public List<ItemStack> customLeaves = new ArrayList<ItemStack>();
public List<ItemStack> customAbilityBlocks = new ArrayList<ItemStack>();
public List<ItemStack> customItems = new ArrayList<ItemStack>();
private List<MaterialData> customExcavationBlocks = new ArrayList<MaterialData>(); public List<CustomBlock> customBlocks = new ArrayList<CustomBlock>();
private List<MaterialData> customHerbalismBlocks = new ArrayList<MaterialData>();
private List<MaterialData> customMiningBlocks = new ArrayList<MaterialData>();
private List<MaterialData> customWoodcuttingBlocks = new ArrayList<MaterialData>();
private List<MaterialData> customOres = new ArrayList<MaterialData>();
private List<MaterialData> customLogs = new ArrayList<MaterialData>();
private List<MaterialData> customLeaves = new ArrayList<MaterialData>();
private List<MaterialData> customAbilityBlocks = new ArrayList<MaterialData>();
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 +46,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<ItemStack> blockList) {
if (needsUpdate) {
return;
}
ConfigurationSection skillSection = config.getConfigurationSection(skillType); ConfigurationSection skillSection = config.getConfigurationSection(skillType);
if (skillSection == null) { if (skillSection == null) {
@@ -69,82 +58,63 @@ 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")) { int id = config.getInt(skillType + "." + blockName + ".ID", 0);
needsUpdate = true; byte data = (byte) config.getInt(skillType + "." + blockName + ".Data_Value", 0);
return; int xp = config.getInt(skillType + "." + blockName + ".XP_Gain", 0);
} int tier = config.getInt(skillType + "." + blockName + ".Tier", 1);
boolean dropItem = config.getBoolean(skillType + "." + blockName + ".Drop_Item", false);
int dropID = config.getInt(skillType + "." + blockName + ".Drop_Item_ID", 0);
byte dropData = (byte) config.getInt(skillType + "." + blockName + ".Drop_Item_Data_Value", 0);
int minimumDropAmount = config.getInt(skillType + "." + blockName + ".Min_Drop_Item_Amount", 1);
int maxiumDropAmount = config.getInt(skillType + "." + blockName + ".Max_Drop_Item_Amount", 1);
String[] blockInfo = blockName.split("[|]"); CustomBlock block;
ItemStack itemDrop;
ItemStack blockItem;
Material blockMaterial = Material.matchMaterial(blockInfo[0]); if (id == 0) {
plugin.getLogger().warning("Missing ID. This block will be skipped.");
if (blockMaterial == null) {
plugin.getLogger().warning("Invalid material name. This item will be skipped. - " + blockInfo[0]);
continue; continue;
} }
byte blockData = Byte.valueOf(blockInfo[1]);
MaterialData blockMaterialData = new MaterialData(blockMaterial, blockData);
blockList.add(blockMaterialData);
if (skillType.equals("Ability_Blocks")) { if (skillType.equals("Ability_Blocks")) {
blockItem = (new MaterialData(id, data)).toItemStack(1);
blockList.add(blockItem);
continue; continue;
} }
int xp = config.getInt(skillType + "." + blockName + ".XP_Gain"); if (dropItem && dropID == 0) {
int smeltingXp = 0; plugin.getLogger().warning("Incomplete item drop information. This block will drop itself.");
dropItem = false;
}
if (dropItem) {
itemDrop = (new MaterialData(dropID, dropData)).toItemStack(1);
}
else {
itemDrop = (new MaterialData(id, data)).toItemStack(1);
}
block = new CustomBlock(minimumDropAmount, maxiumDropAmount, itemDrop, tier, xp, data, id);
blockItem = (new MaterialData(id, data)).toItemStack(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(blockItem);
smeltingXp = config.getInt(skillType + "." + blockName + ".Smelting_XP_Gain", xp / 10);
} }
else if (skillType.equals("Woodcutting")) { else if (skillType.equals("Woodcutting")) {
if (config.getBoolean(skillType + "." + blockName + ".Is_Log")) { if (config.getBoolean(skillType + "." + blockName + ".Is_Log")) {
customLogs.add(blockMaterialData); customLogs.add(blockItem);
} }
else { else {
customLeaves.add(blockMaterialData); customLeaves.add(blockItem);
xp = 0; // Leaves don't grant XP block.setXpGain(0); // Leaves don't grant XP
} }
} }
customBlockMap.put(blockMaterialData, new CustomBlock(xp, config.getBoolean(skillType + "." + blockName + ".Double_Drops_Enabled"), smeltingXp)); blockList.add(blockItem);
customItems.add(blockItem);
customBlocks.add(block);
} }
} }
public CustomBlock getCustomBlock(MaterialData data) {
return customBlockMap.get(data);
}
public boolean isCustomOre(MaterialData data) {
return customOres.contains(data);
}
public boolean isCustomLog(MaterialData data) {
return customLogs.contains(data);
}
public boolean isCustomLeaf(MaterialData data) {
return customLeaves.contains(data);
}
public boolean isCustomAbilityBlock(MaterialData data) {
return customAbilityBlocks.contains(data);
}
public boolean isCustomExcavationBlock(MaterialData data) {
return customExcavationBlocks.contains(data);
}
public boolean isCustomHerbalismBlock(MaterialData data) {
return customHerbalismBlocks.contains(data);
}
public boolean isCustomMiningBlock(MaterialData data) {
return customMiningBlocks.contains(data);
}
public boolean isCustomWoodcuttingBlock(MaterialData data) {
return customWoodcuttingBlocks.contains(data);
}
} }

View File

@@ -1,24 +1,29 @@
package com.gmail.nossr50.config.mods; package com.gmail.nossr50.config.mods;
import java.util.HashMap; import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType;
import org.bukkit.material.MaterialData; import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.config.ConfigLoader; import com.gmail.nossr50.config.ConfigLoader;
import com.gmail.nossr50.datatypes.mods.CustomEntity; import com.gmail.nossr50.datatypes.mods.CustomEntity;
import org.apache.commons.lang.ClassUtils;
public class CustomEntityConfig extends ConfigLoader { public class CustomEntityConfig extends ConfigLoader {
private static CustomEntityConfig instance; private static CustomEntityConfig instance;
private HashMap<String, CustomEntity> customEntityClassMap = new HashMap<String, CustomEntity>(); public List<Integer> customEntityIds = new ArrayList<Integer>();
private HashMap<String, CustomEntity> customEntityTypeMap = new HashMap<String, CustomEntity>(); public List<Integer> customHostileEntityIds = new ArrayList<Integer>();
public List<Integer> customNeutralEntityIds = new ArrayList<Integer>();
public List<Integer> customPassiveEntityIds = new ArrayList<Integer>();
public List<EntityType> customEntityTypes = new ArrayList<EntityType>();
public List<CustomEntity> customEntities = new ArrayList<CustomEntity>();
public CustomEntityConfig() { public CustomEntityConfig() {
super("mods", "entities.yml"); super("ModConfigs", "entities.yml");
loadKeys(); loadKeys();
} }
@@ -32,86 +37,48 @@ public class CustomEntityConfig extends ConfigLoader {
@Override @Override
protected void loadKeys() { protected void loadKeys() {
if (config.getConfigurationSection("Hostile") != null) { loadMobs("Hostile", customHostileEntityIds);
backup(); loadMobs("Neutral", customNeutralEntityIds);
loadMobs("Passive", customPassiveEntityIds);
}
private void loadMobs(String entityType, List<Integer> entityIdList) {
ConfigurationSection entitySection = config.getConfigurationSection(entityType);
if (entitySection == null) {
return; return;
} }
for (String entityName : config.getKeys(false)) { Set<String> entityConfigSet = entitySection.getKeys(false);
Class<?> clazz = null;
String className = config.getString(entityName + ".Class", "");
try { for (String entityName : entityConfigSet) {
clazz = ClassUtils.getClass(className); int id = config.getInt(entityType + "." + entityName + ".ID", 0);
} EntityType type = EntityType.fromId(id);
catch (ClassNotFoundException e) { double xpMultiplier = config.getDouble(entityType + "." + entityName + ".XP_Multiplier", 1.0D);
plugin.getLogger().warning("Invalid class (" + className + ") detected for " + entityName + "."); boolean canBeTamed = config.getBoolean(entityType + "." + entityName + ".Tameable", false);
plugin.getLogger().warning("This custom entity may not function properly."); int tamingXp = config.getInt(entityType + "." + entityName + "Taming_XP", 0);
boolean canBeSummoned = config.getBoolean(entityType + "." + entityName + "CanBeSummoned", false);
int callOfTheWildId = config.getInt(entityType + "." + entityName + "COTW_Material_ID", 0);
int callOfTheWildData = config.getInt(entityType + "." + entityName + "COTW_Material_Data", 0);
int callOfTheWildAmount = config.getInt(entityType + "." + entityName + "COTW_Material_Amount", 0);
CustomEntity entity;
if (id == 0) {
plugin.getLogger().warning("Missing ID. This block will be skipped.");
continue;
} }
String entityTypeName = entityName.replace("_", "."); if (canBeSummoned && (callOfTheWildId == 0 || callOfTheWildAmount == 0)) {
double xpMultiplier = config.getDouble(entityName + ".XP_Multiplier", 1.0D); plugin.getLogger().warning("Incomplete Call of the Wild information. This enitity will not be able to be summoned by Call of the Wild.");
boolean canBeTamed = config.getBoolean(entityName + ".Tameable");
int tamingXp = config.getInt(entityName + ".Taming_XP");
boolean canBeSummoned = config.getBoolean(entityName + ".CanBeSummoned");
Material callOfTheWildMaterial = Material.matchMaterial(config.getString(entityName + ".COTW_Material", ""));
byte callOfTheWildData = (byte) config.getInt(entityName + ".COTW_Material_Data");
int callOfTheWildAmount = config.getInt(entityName + ".COTW_Material_Amount");
if (canBeSummoned && (callOfTheWildMaterial == null || callOfTheWildAmount == 0)) {
plugin.getLogger().warning("Incomplete Call of the Wild information. This entity will not be able to be summoned by Call of the Wild.");
canBeSummoned = false; canBeSummoned = false;
} }
CustomEntity entity = new CustomEntity(xpMultiplier, canBeTamed, tamingXp, canBeSummoned, (canBeSummoned ? new MaterialData(callOfTheWildMaterial, callOfTheWildData).toItemStack(1) : null), callOfTheWildAmount); entity = new CustomEntity(id, type, xpMultiplier, canBeTamed, tamingXp, canBeSummoned, new ItemStack(callOfTheWildId, callOfTheWildData), callOfTheWildAmount);
customEntityTypeMap.put(entityTypeName, entity); entityIdList.add(id);
customEntityClassMap.put(clazz == null ? null : clazz.getName(), entity); customEntityTypes.add(type);
customEntities.add(entity);
} }
} }
public boolean isCustomEntity(Entity entity) {
if (customEntityTypeMap.containsKey(entity.getType().toString())) {
return true;
}
try {
return customEntityClassMap.containsKey(((Class<?>) entity.getClass().getDeclaredField("entityClass").get(entity)).getName());
}
catch (Exception e) {
if (e instanceof NoSuchFieldException || e instanceof IllegalArgumentException || e instanceof IllegalAccessException) {
return customEntityClassMap.containsKey(entity.getClass().getName());
}
e.printStackTrace();
return false;
}
}
public CustomEntity getCustomEntity(Entity entity) {
CustomEntity customEntity = customEntityTypeMap.get(entity.getType().toString());
if (customEntity == null) {
try {
customEntity = customEntityClassMap.get(((Class<?>) entity.getClass().getDeclaredField("entityClass").get(entity)).getName());
}
catch (Exception e) {
if (e instanceof NoSuchFieldException || e instanceof IllegalArgumentException || e instanceof IllegalAccessException) {
customEntity = customEntityClassMap.get(entity.getClass().getName());
}
else {
e.printStackTrace();
}
}
}
return customEntity;
}
public void addEntity(CustomEntity customEntity, String className, String entityName) {
customEntityTypeMap.put(entityName, customEntity);
customEntityClassMap.put(className, customEntity);
}
} }

View File

@@ -5,36 +5,28 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
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.Repairable;
import com.gmail.nossr50.skills.repair.repairables.RepairItemType; import com.gmail.nossr50.skills.repair.RepairableFactory;
import com.gmail.nossr50.skills.repair.repairables.RepairMaterialType;
import com.gmail.nossr50.skills.repair.repairables.Repairable;
import com.gmail.nossr50.skills.repair.repairables.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;
public List<Integer> customAxeIDs = new ArrayList<Integer>();
private List<Material> customAxes = new ArrayList<Material>(); public List<Integer> customBowIDs = new ArrayList<Integer>();
private List<Material> customBows = new ArrayList<Material>(); public List<Integer> customHoeIDs = new ArrayList<Integer>();
private List<Material> customHoes = new ArrayList<Material>(); public List<Integer> customPickaxeIDs = new ArrayList<Integer>();
private List<Material> customPickaxes = new ArrayList<Material>(); public List<Integer> customShovelIDs = new ArrayList<Integer>();
private List<Material> customShovels = new ArrayList<Material>(); public List<Integer> customSwordIDs = new ArrayList<Integer>();
private List<Material> customSwords = new ArrayList<Material>(); public List<Integer> customIDs = new ArrayList<Integer>();
public List<CustomTool> customToolList = new ArrayList<CustomTool>();
private HashMap<Material, CustomTool> customToolMap = new HashMap<Material, CustomTool>(); public HashMap<Integer, CustomTool> customTools = new HashMap<Integer, CustomTool>();
private CustomToolConfig() { private CustomToolConfig() {
super("mods", "tools.yml"); super("ModConfigs", "tools.yml");
loadKeys(); loadKeys();
} }
@@ -58,24 +50,15 @@ public class CustomToolConfig extends ConfigLoader {
protected void loadKeys() { protected void loadKeys() {
repairables = new ArrayList<Repairable>(); repairables = new ArrayList<Repairable>();
loadTool("Axes", customAxes); loadTool("Axes", customAxeIDs);
loadTool("Bows", customBows); loadTool("Bows", customBowIDs);
loadTool("Hoes", customHoes); loadTool("Hoes", customHoeIDs);
loadTool("Pickaxes", customPickaxes); loadTool("Pickaxes", customPickaxeIDs);
loadTool("Shovels", customShovels); loadTool("Shovels", customShovelIDs);
loadTool("Swords", customSwords); loadTool("Swords", customSwordIDs);
if (needsUpdate) {
needsUpdate = false;
backup();
}
} }
private void loadTool(String toolType, List<Material> materialList) { private void loadTool(String toolType, List<Integer> idList) {
if (needsUpdate) {
return;
}
ConfigurationSection toolSection = config.getConfigurationSection(toolType); ConfigurationSection toolSection = config.getConfigurationSection(toolType);
if (toolSection == null) { if (toolSection == null) {
@@ -85,83 +68,38 @@ 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")) { int id = config.getInt(toolType + "." + toolName + ".ID", 0);
needsUpdate = true;
return;
}
Material toolMaterial = Material.matchMaterial(toolName);
if (toolMaterial == null) {
plugin.getLogger().warning("Invalid material name. This item will be skipped. - " + toolName);
continue;
}
boolean repairable = config.getBoolean(toolType + "." + toolName + ".Repairable");
Material repairMaterial = Material.matchMaterial(config.getString(toolType + "." + toolName + ".Repair_Material", ""));
if (repairMaterial == null) {
plugin.getLogger().warning("Incomplete repair information. This item will be unrepairable. - " + toolName);
repairable = false;
}
if (repairable) {
byte repairData = (byte) config.getInt(toolType + "." + toolName + ".Repair_Material_Data_Value", -1);
int repairQuantity = Repair.getRepairAndSalvageQuantities(new ItemStack(toolMaterial), repairMaterial, repairData);
if (repairQuantity == 0) {
repairQuantity = config.getInt(toolType + "." + toolName + ".Repair_Material_Data_Quantity", 2);
}
short durability = toolMaterial.getMaxDurability();
if (durability == 0) {
durability = (short) config.getInt(toolType + "." + toolName + ".Durability", 60);
}
repairables.add(RepairableFactory.getRepairable(toolMaterial, repairMaterial, repairData, 0, repairQuantity, durability, RepairItemType.TOOL, RepairMaterialType.OTHER, 1.0));
}
double multiplier = config.getDouble(toolType + "." + toolName + ".XP_Modifier", 1.0); double multiplier = config.getDouble(toolType + "." + toolName + ".XP_Modifier", 1.0);
boolean abilityEnabled = config.getBoolean(toolType + "." + toolName + ".Ability_Enabled", true); boolean abilityEnabled = config.getBoolean(toolType + "." + toolName + ".Ability_Enabled", true);
int tier = config.getInt(toolType + "." + toolName + ".Tier", 1); int tier = config.getInt(toolType + "." + toolName + ".Tier", 1);
boolean repairable = config.getBoolean(toolType + "." + toolName + ".Repairable");
int repairID = config.getInt(toolType + "." + toolName + ".Repair_Material_ID", 0);
byte repairData = (byte) config.getInt(toolType + "." + toolName + ".Repair_Material_Data_Value", 0);
int repairQuantity = config.getInt(toolType + "." + toolName + ".Repair_Material_Quantity", 0);
short durability = (short) config.getInt(toolType + "." + toolName + ".Durability", 0);
CustomTool tool = new CustomTool(tier, abilityEnabled, multiplier); if (id == 0) {
plugin.getLogger().warning("Missing ID. This item will be skipped.");
continue;
}
materialList.add(toolMaterial); if (repairable && (repairID == 0 || repairQuantity == 0 || durability == 0)) {
customToolMap.put(toolMaterial, tool); plugin.getLogger().warning("Incomplete repair information. This item will be unrepairable.");
repairable = false;
}
CustomTool tool;
if (repairable) {
repairables.add(RepairableFactory.getRepairable(id, repairID, repairData, repairQuantity, durability));
}
tool = new CustomTool(tier, abilityEnabled, multiplier, durability, id);
idList.add(id);
customIDs.add(id);
customToolList.add(tool);
customTools.put(id, tool);
} }
} }
public boolean isCustomAxe(Material material) {
return customAxes.contains(material);
}
public boolean isCustomBow(Material material) {
return customBows.contains(material);
}
public boolean isCustomHoe(Material material) {
return customHoes.contains(material);
}
public boolean isCustomPickaxe(Material material) {
return customPickaxes.contains(material);
}
public boolean isCustomShovel(Material material) {
return customShovels.contains(material);
}
public boolean isCustomSword(Material material) {
return customSwords.contains(material);
}
public boolean isCustomTool(Material material) {
return customToolMap.containsKey(material);
}
public CustomTool getCustomTool(Material material) {
return customToolMap.get(material);
}
} }

View File

@@ -0,0 +1,75 @@
package com.gmail.nossr50.config.spout;
import org.getspout.spoutapi.keyboard.Keyboard;
import com.gmail.nossr50.config.ConfigLoader;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.datatypes.spout.huds.HudType;
public class SpoutConfig extends ConfigLoader {
private static SpoutConfig instance;
private SpoutConfig() {
super("spout.yml");
}
public static SpoutConfig getInstance() {
if (instance == null) {
instance = new SpoutConfig();
}
return instance;
}
@Override
protected void loadKeys() {
// Setup default HUD
}
public HudType getDefaultHudType() {
try {
return HudType.valueOf(config.getString("Spout.HUD.Default", "STANDARD").toUpperCase().trim());
}
catch (IllegalArgumentException ex) {
return HudType.STANDARD;
}
}
public boolean getShowPowerLevel() { return config.getBoolean("HUD.Show_Power_Level", true); }
public Keyboard getMenuKey() {
try {
return Keyboard.valueOf(config.getString("Menu.Key", "KEY_M").toUpperCase().trim());
}
catch (IllegalArgumentException ex) {
return Keyboard.KEY_M;
}
}
/* XP Bar */
public boolean getXPBarEnabled() { return config.getBoolean("XP.Bar.Enabled", true); }
public void setXPBarEnabled(boolean enabled) { config.set("XP.Bar.Enabled", enabled); }
public boolean getXPBarIconEnabled() { return config.getBoolean("XP.Icon.Enabled", true); }
public int getXPBarXPosition() { return config.getInt("XP.Bar.X_POS", 95); }
public int getXPBarYPosition() { return config.getInt("XP.Bar.Y_POS", 6); }
public int getXPIconXPosition() { return config.getInt("XP.Icon.X_POS", 78); }
public int getXPIconYPosition() { return config.getInt("XP.Icon.Y_POS", 2); }
/* HUD Colors */
public double getRetroHUDXPBorderRed() { return config.getDouble("HUD.Retro.Colors.Border.RED", 0.0); }
public double getRetroHUDXPBorderGreen() { return config.getDouble("HUD.Retro.Colors.Border.GREEN", 0.0); }
public double getRetroHUDXPBorderBlue() { return config.getDouble("HUD.Retro.Colors.Border.BLUE", 0.0); }
public double getRetroHUDXPBackgroundRed() { return config.getDouble("HUD.Retro.Colors.Background.RED", 0.75); }
public double getRetroHUDXPBackgroundGreen() { return config.getDouble("HUD.Retro.Colors.Background.GREEN", 0.75); }
public double getRetroHUDXPBackgroundBlue() { return config.getDouble("HUD.Retro.Colors.Background.BLUE", 0.75); }
public double getRetroHUDRed(SkillType skill) { return config.getDouble("HUD.Retro.Colors." + skill.toString().toLowerCase() +".RED", 0.3); }
public double getRetroHUDGreen(SkillType skill) { return config.getDouble("HUD.Retro.Colors." + skill.toString().toLowerCase() +".RED", 0.3); }
public double getRetroHUDBlue(SkillType skill) { return config.getDouble("HUD.Retro.Colors." + skill.toString().toLowerCase() +".RED", 0.3); }
/* Notification Tiers */
public int getNotificationTier1() { return config.getInt("Notifications.Tier1", 200); }
public int getNotificationTier2() { return config.getInt("Notifications.Tier2", 400); }
public int getNotificationTier3() { return config.getInt("Notifications.Tier3", 600); }
public int getNotificationTier4() { return config.getInt("Notifications.Tier4", 800); }
}

View File

@@ -3,38 +3,35 @@ package com.gmail.nossr50.config.treasure;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
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.material.MaterialData;
import org.bukkit.material.Dye;
import org.bukkit.potion.Potion; 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; import com.gmail.nossr50.datatypes.treasure.Treasure;
public class TreasureConfig extends ConfigLoader { public class TreasureConfig extends ConfigLoader {
private static TreasureConfig instance; private static TreasureConfig instance;
public List<ExcavationTreasure> excavationFromDirt = new ArrayList<ExcavationTreasure>(); public List<ExcavationTreasure> excavationFromDirt = new ArrayList<ExcavationTreasure>();
public List<ExcavationTreasure> excavationFromGrass = new ArrayList<ExcavationTreasure>(); public List<ExcavationTreasure> excavationFromGrass = new ArrayList<ExcavationTreasure>();
public List<ExcavationTreasure> excavationFromSand = new ArrayList<ExcavationTreasure>(); public List<ExcavationTreasure> excavationFromSand = new ArrayList<ExcavationTreasure>();
public List<ExcavationTreasure> excavationFromGravel = new ArrayList<ExcavationTreasure>(); public List<ExcavationTreasure> excavationFromGravel = new ArrayList<ExcavationTreasure>();
public List<ExcavationTreasure> excavationFromClay = new ArrayList<ExcavationTreasure>(); public List<ExcavationTreasure> excavationFromClay = new ArrayList<ExcavationTreasure>();
public List<ExcavationTreasure> excavationFromMycel = new ArrayList<ExcavationTreasure>(); public List<ExcavationTreasure> excavationFromMycel = new ArrayList<ExcavationTreasure>();
public List<ExcavationTreasure> excavationFromSoulSand = new ArrayList<ExcavationTreasure>(); public List<ExcavationTreasure> excavationFromSoulSand = new ArrayList<ExcavationTreasure>();
public List<ExcavationTreasure> excavationFromSnow = new ArrayList<ExcavationTreasure>();
public List<HylianTreasure> hylianFromBushes = new ArrayList<HylianTreasure>(); public List<HylianTreasure> hylianFromBushes = new ArrayList<HylianTreasure>();
public List<HylianTreasure> hylianFromFlowers = new ArrayList<HylianTreasure>(); public List<HylianTreasure> hylianFromFlowers = new ArrayList<HylianTreasure>();
@@ -48,7 +45,6 @@ public class TreasureConfig extends ConfigLoader {
public List<ShakeTreasure> shakeFromCreeper = new ArrayList<ShakeTreasure>(); public List<ShakeTreasure> shakeFromCreeper = new ArrayList<ShakeTreasure>();
public List<ShakeTreasure> shakeFromEnderman = new ArrayList<ShakeTreasure>(); public List<ShakeTreasure> shakeFromEnderman = new ArrayList<ShakeTreasure>();
public List<ShakeTreasure> shakeFromGhast = new ArrayList<ShakeTreasure>(); public List<ShakeTreasure> shakeFromGhast = new ArrayList<ShakeTreasure>();
public List<ShakeTreasure> shakeFromHorse = new ArrayList<ShakeTreasure>();
public List<ShakeTreasure> shakeFromIronGolem = new ArrayList<ShakeTreasure>(); public List<ShakeTreasure> shakeFromIronGolem = new ArrayList<ShakeTreasure>();
public List<ShakeTreasure> shakeFromMagmaCube = new ArrayList<ShakeTreasure>(); public List<ShakeTreasure> shakeFromMagmaCube = new ArrayList<ShakeTreasure>();
public List<ShakeTreasure> shakeFromMushroomCow = new ArrayList<ShakeTreasure>(); public List<ShakeTreasure> shakeFromMushroomCow = new ArrayList<ShakeTreasure>();
@@ -62,13 +58,11 @@ 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");
loadKeys(); loadKeys();
validate();
} }
public static TreasureConfig getInstance() { public static TreasureConfig getInstance() {
@@ -79,349 +73,379 @@ public class TreasureConfig extends ConfigLoader {
return instance; return instance;
} }
@Override
protected boolean validateKeys() {
// Validate all the settings!
List<String> reason = new ArrayList<String>();
for (String tier : config.getConfigurationSection("Enchantment_Drop_Rates").getKeys(false)) {
double totalEnchantDropRate = 0;
double totalItemDropRate = 0;
for (Rarity rarity : Rarity.values()) {
double enchantDropRate = config.getDouble("Enchantment_Drop_Rates." + tier + "." + rarity.toString());
double itemDropRate = config.getDouble("Item_Drop_Rates." + tier + "." + rarity.toString());
if ((enchantDropRate < 0.0 || enchantDropRate > 100.0) && rarity != Rarity.TRAP && rarity != Rarity.RECORD) {
reason.add("The enchant drop rate for " + tier + " items that are " + rarity.toString() + "should be between 0.0 and 100.0!");
}
if (itemDropRate < 0.0 || itemDropRate > 100.0) {
reason.add("The item drop rate for " + tier + " items that are " + rarity.toString() + "should be between 0.0 and 100.0!");
}
totalEnchantDropRate += enchantDropRate;
totalItemDropRate += itemDropRate;
}
if (totalEnchantDropRate < 0 || totalEnchantDropRate > 100.0) {
reason.add("The total enchant drop rate for " + tier + " should be between 0.0 and 100.0!");
}
if (totalItemDropRate < 0 || totalItemDropRate > 100.0) {
reason.add("The total item drop rate for " + tier + " should be between 0.0 and 100.0!");
}
}
return noErrorsInConfig(reason);
}
@Override @Override
protected void loadKeys() { protected void loadKeys() {
if (config.getConfigurationSection("Treasures") != null) { Map<String, Treasure> treasures = new HashMap<String, Treasure>();
backup(); ConfigurationSection treasureSection = config.getConfigurationSection("Treasures");
return;
}
loadTreaures("Fishing");
loadTreaures("Excavation");
loadTreaures("Hylian_Luck");
loadEnchantments();
for (EntityType entity : EntityType.values()) {
if (entity.isAlive()) {
loadTreaures("Shake." + entity.toString());
}
}
}
private void loadTreaures(String type) {
boolean isFishing = type.equals("Fishing");
boolean isShake = type.contains("Shake");
boolean isExcavation = type.equals("Excavation");
boolean isHylian = type.equals("Hylian_Luck");
ConfigurationSection treasureSection = config.getConfigurationSection(type);
if (treasureSection == null) { if (treasureSection == null) {
return; return;
} }
// Initialize fishing HashMap Set<String> treasureConfigSet = treasureSection.getKeys(false);
for (Rarity rarity : Rarity.values()) {
if (!fishingRewards.containsKey(rarity)) { for (String treasureName : treasureConfigSet) {
fishingRewards.put(rarity, (new ArrayList<FishingTreasure>()));
}
}
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>();
/* /*
* Material, Amount, and Data * ID, Amount, and Data
*/ */
Material material;
if (treasureName.contains("POTION")) { if (!config.contains("Treasures." + treasureName + ".ID")) {
material = Material.POTION; reason.add("Missing ID");
}
else if (treasureName.contains("INK_SACK")) {
material = Material.INK_SACK;
}
else {
material = Material.matchMaterial(treasureName);
} }
int amount = config.getInt(type + "." + treasureName + ".Amount"); if (!config.contains("Treasures." + treasureName + ".Amount")) {
int data = config.getInt(type + "." + treasureName + ".Data"); reason.add("Missing Amount");
if (material == null) {
reason.add("Invalid material: " + treasureName);
} }
if (amount <= 0) { if (!config.contains("Treasures." + treasureName + ".Data")) {
reason.add("Amount of " + treasureName + " must be greater than 0! " + amount); reason.add("Missing Data");
} }
if (material != null && material.isBlock() && (data > 127 || data < -128)) { int id = config.getInt("Treasures." + treasureName + ".ID");
reason.add("Data of " + treasureName + " is invalid! " + data); int amount = config.getInt("Treasures." + treasureName + ".Amount");
int data = config.getInt("Treasures." + treasureName + ".Data");
if (Material.getMaterial(id) == null) {
reason.add("Invalid id: " + id);
}
if (amount < 1) {
reason.add("Invalid amount: " + amount);
}
if (id < 256 && (data > 127 || data < -128)) {
reason.add("Invalid data: " + data);
} }
/* /*
* XP, Drop Chance, and Drop Level * XP, Drop Chance, and Drop Level
*/ */
int xp = config.getInt(type + "." + treasureName + ".XP"); if (!config.contains("Treasures." + treasureName + ".XP")) {
double dropChance = config.getDouble(type + "." + treasureName + ".Drop_Chance"); reason.add("Missing XP");
int dropLevel = config.getInt(type + "." + treasureName + ".Drop_Level");
if (xp < 0) {
reason.add(treasureName + " has an invalid XP value: " + xp);
} }
if (dropChance < 0.0D) { if (!config.contains("Treasures." + treasureName + ".Drop_Chance")) {
reason.add(treasureName + " has an invalid Drop_Chance: " + dropChance); reason.add("Missing Drop_Chance");
}
if (!config.contains("Treasures." + treasureName + ".Drop_Level")) {
reason.add("Missing Drop_Level");
}
int xp = config.getInt("Treasures." + treasureName + ".XP");
Double dropChance = config.getDouble("Treasures." + treasureName + ".Drop_Chance");
int dropLevel = config.getInt("Treasures." + treasureName + ".Drop_Level");
if (xp < 0) {
reason.add("Invalid xp: " + xp);
}
if (dropChance < 0) {
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 * Potions
*/ */
Rarity rarity = null;
if (isFishing) {
rarity = Rarity.getRarity(config.getString(type + "." + treasureName + ".Rarity"));
if (rarity == null) {
reason.add("Invalid Rarity for item: " + treasureName);
}
}
/*
* Itemstack
*/
ItemStack item = null; ItemStack item = null;
if (treasureName.contains("POTION")) { if (config.contains("Treasures." + treasureName + ".Potion_Type")) {
String potionType = treasureName.substring(7); String potionType = config.getString("Treasures." + treasureName + ".Potion_Type");
try { try {
item = new Potion(PotionType.valueOf(potionType.toUpperCase().trim())).toItemStack(amount); item = new Potion(PotionType.valueOf(potionType.toUpperCase())).toItemStack(amount);
} }
catch (IllegalArgumentException ex) { catch (IllegalArgumentException ex) {
reason.add("Invalid Potion_Type: " + potionType); reason.add("Invalid Potion_Type: " + potionType);
} }
} }
else if (treasureName.contains("INK_SACK")) { else {
String color = treasureName.substring(9); item = (new MaterialData(id, (byte) data)).toItemStack(amount);
}
/*
* Drops From & Max Level
*/
if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Fishing", false)) {
if (config.getConfigurationSection("Treasures." + treasureName + ".Drops_From").getKeys(false).size() != 1) {
reason.add("This can only be a fishing drop.");
}
if (!config.contains("Treasures." + treasureName + ".Max_Level")) {
reason.add("Missing Max_Level");
}
int maxLevel = config.getInt("Treasures." + treasureName + ".Max_Level");
if (noErrorsInTreasure(reason)) {
FishingTreasure fTreasure = new FishingTreasure(item, xp, dropChance, dropLevel, maxLevel);
treasures.put(treasureName, fTreasure);
}
}
else if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Shake", false)) {
if (config.getConfigurationSection("Treasures." + treasureName + ".Drops_From").getKeys(false).size() != 1) {
reason.add("This can only be a shake drop.");
}
if (!config.contains("Treasures." + treasureName + ".Mob")) {
reason.add("Missing Mob");
}
String mobType = config.getString("Treasures." + treasureName + ".Mob");
EntityType mob = null;
try { try {
Dye dye = new Dye(); mob = EntityType.valueOf(mobType.toUpperCase().trim());
dye.setColor(DyeColor.valueOf(color.toUpperCase().trim()));
item = dye.toItemStack(amount);
} }
catch (IllegalArgumentException ex) { catch (IllegalArgumentException ex){
reason.add("Invalid Dye_Color: " + color); reason.add("Invalid Mob: " + mobType);
}
if (noErrorsInTreasure(reason)) {
ShakeTreasure sTreasure = new ShakeTreasure(item, xp, dropChance, dropLevel, mob);
treasures.put(treasureName, sTreasure);
} }
} }
else if (material != null) { else {
item = new ItemStack(material, amount, (short) data); ExcavationTreasure eTreasure = new ExcavationTreasure(item, xp, dropChance, dropLevel);
HylianTreasure hTreasure = new HylianTreasure(item, xp, dropChance, dropLevel);
if (config.contains(type + "." + treasureName + ".Custom_Name")) { if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Dirt", false)) {
ItemMeta itemMeta = item.getItemMeta(); eTreasure.setDropsFromDirt();
itemMeta.setDisplayName(config.getString(type + "." + treasureName + "Custom_Name"));
item.setItemMeta(itemMeta);
} }
if (config.contains(type + "." + treasureName + ".Lore")) { if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Grass", false)) {
ItemMeta itemMeta = item.getItemMeta(); eTreasure.setDropsFromGrass();
itemMeta.setLore(config.getStringList(type + "." + treasureName + "Custom_Name"));
item.setItemMeta(itemMeta);
} }
}
if (noErrorsInConfig(reason)) { if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Sand", false)) {
if (isFishing) { eTreasure.setDropsFromSand();
fishingRewards.get(rarity).add(new FishingTreasure(item, xp));
} }
else if (isShake) {
ShakeTreasure shakeTreasure = new ShakeTreasure(item, xp, dropChance, dropLevel);
if (type.equals("Shake.BLAZE")) { if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Gravel", false)) {
shakeFromBlaze.add(shakeTreasure); eTreasure.setDropsFromGravel();
}
else if (type.equals("Shake.CAVE_SPIDER")) {
shakeFromCaveSpider.add(shakeTreasure);
}
else if (type.equals("Shake.CHICKEN")) {
shakeFromChicken.add(shakeTreasure);
}
else if (type.equals("Shake.COW")) {
shakeFromCow.add(shakeTreasure);
}
else if (type.equals("Shake.CREEPER")) {
shakeFromCreeper.add(shakeTreasure);
}
else if (type.equals("Shake.ENDERMAN")) {
shakeFromEnderman.add(shakeTreasure);
}
else if (type.equals("Shake.GHAST")) {
shakeFromGhast.add(shakeTreasure);
}
else if (type.equals("Shake.HORSE")) {
shakeFromHorse.add(shakeTreasure);
}
else if (type.equals("Shake.IRON_GOLEM")) {
shakeFromIronGolem.add(shakeTreasure);
}
else if (type.equals("Shake.MAGMA_CUBE")) {
shakeFromMagmaCube.add(shakeTreasure);
}
else if (type.equals("Shake.MUSHROOM_COW")) {
shakeFromMushroomCow.add(shakeTreasure);
}
else if (type.equals("Shake.PIG")) {
shakeFromPig.add(shakeTreasure);
}
else if (type.equals("Shake.PIG_ZOMBIE")) {
shakeFromPigZombie.add(shakeTreasure);
}
else if (type.equals("Shake.SHEEP")) {
shakeFromSheep.add(shakeTreasure);
}
else if (type.equals("Shake.SKELETON")) {
shakeFromSkeleton.add(shakeTreasure);
}
else if (type.equals("Shake.SLIME")) {
shakeFromSlime.add(shakeTreasure);
}
else if (type.equals("Shake.SPIDER")) {
shakeFromSpider.add(shakeTreasure);
}
else if (type.equals("Shake.SNOWMAN")) {
shakeFromSnowman.add(shakeTreasure);
}
else if (type.equals("Shake.SQUID")) {
shakeFromSquid.add(shakeTreasure);
}
else if (type.equals("Shake.WITCH")) {
shakeFromWitch.add(shakeTreasure);
}
else if (type.equals("Shake.ZOMBIE")) {
shakeFromZombie.add(shakeTreasure);
}
} }
else if (isExcavation) {
ExcavationTreasure excavationTreasure = new ExcavationTreasure(item, xp, dropChance, dropLevel);
List<String> dropList = config.getStringList(type + "." + treasureName + ".Drops_From");
if (dropList.contains("Dirt")) { if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Clay", false)) {
excavationFromDirt.add(excavationTreasure); eTreasure.setDropsFromClay();
}
if (dropList.contains("Grass")) {
excavationFromGrass.add(excavationTreasure);
}
if (dropList.contains("Sand")) {
excavationFromSand.add(excavationTreasure);
}
if (dropList.contains("Gravel")) {
excavationFromGravel.add(excavationTreasure);
}
if (dropList.contains("Clay")) {
excavationFromClay.add(excavationTreasure);
}
if (dropList.contains("Mycelium")) {
excavationFromMycel.add(excavationTreasure);
}
if (dropList.contains("Soul_Sand")) {
excavationFromSoulSand.add(excavationTreasure);
}
if (dropList.contains("Snow")) {
excavationFromSnow.add(excavationTreasure);
}
} }
else if (isHylian) {
HylianTreasure hylianTreasure = new HylianTreasure(item, xp, dropChance, dropLevel);
List<String> dropList = config.getStringList(type + "." + treasureName + ".Drops_From");
if (dropList.contains("Bushes")) { if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Mycelium", false)) {
hylianFromBushes.add(hylianTreasure); eTreasure.setDropsFromMycel();
} }
if (dropList.contains("Flowers")) { if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Soul_Sand", false)) {
hylianFromFlowers.add(hylianTreasure); eTreasure.setDropsFromSoulSand();
} }
if (dropList.contains("Pots")) { if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Bushes", false)) {
hylianFromPots.add(hylianTreasure); hTreasure.setDropsFromBushes();
} }
if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Flowers", false)) {
hTreasure.setDropsFromFlowers();
}
if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Pots", false)) {
hTreasure.setDropsFromPots();
}
if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Fishing", false)) {
reason.add("This cannot also be a fishing drop.");
}
if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Shake", false)) {
reason.add("This cannot also be a shake drop.");
}
if (noErrorsInTreasure(reason) && hTreasure.getDropsFrom() == (byte) 0x0) {
treasures.put(treasureName, eTreasure);
}
else if (noErrorsInTreasure(reason) && eTreasure.getDropsFrom() == (byte) 0x0) {
treasures.put(treasureName, hTreasure);
} }
} }
} }
}
private void loadEnchantments() { List<String> excavationTreasures = config.getStringList("Excavation.Treasure");
for (Rarity rarity : Rarity.values()) { List<String> fishingTreasures = config.getStringList("Fishing.Treasure");
if (rarity == Rarity.TRAP || rarity == Rarity.RECORD) { List<String> hylianTreasures = config.getStringList("Hylian_Luck.Treasure");
continue; List<String> shakeTreasures = config.getStringList("Shake.Treasure");
}
if (!fishingEnchantments.containsKey(rarity)) { for (Entry<String, Treasure> nextEntry : treasures.entrySet()) {
fishingEnchantments.put(rarity, (new ArrayList<EnchantmentTreasure>())); String treasureKey = nextEntry.getKey();
} Treasure treasure = nextEntry.getValue();
ConfigurationSection enchantmentSection = config.getConfigurationSection("Enchantments_Rarity." + rarity.toString()); if (treasure instanceof FishingTreasure) {
if (fishingTreasures == null || !fishingTreasures.contains(treasureKey)) {
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; continue;
} }
fishingEnchantments.get(rarity).add(new EnchantmentTreasure(enchantment, level)); fishingRewards.add((FishingTreasure) treasure);
}
else if (treasure instanceof ShakeTreasure) {
if (shakeTreasures == null || !shakeTreasures.contains(treasureKey)) {
continue;
}
ShakeTreasure e = (ShakeTreasure) treasure;
switch (e.getMob()) {
case BLAZE:
shakeFromBlaze.add(e);
break;
case CAVE_SPIDER:
shakeFromCaveSpider.add(e);
break;
case CHICKEN:
shakeFromChicken.add(e);
break;
case COW:
shakeFromCow.add(e);
break;
case CREEPER:
shakeFromCreeper.add(e);
break;
case ENDERMAN:
shakeFromEnderman.add(e);
break;
case GHAST:
shakeFromGhast.add(e);
break;
case IRON_GOLEM:
shakeFromIronGolem.add(e);
break;
case MAGMA_CUBE:
shakeFromMagmaCube.add(e);
break;
case MUSHROOM_COW:
shakeFromMushroomCow.add(e);
break;
case PIG:
shakeFromPig.add(e);
break;
case PIG_ZOMBIE:
shakeFromPigZombie.add(e);
break;
case SHEEP:
shakeFromSheep.add(e);
break;
case SKELETON:
shakeFromSkeleton.add(e);
break;
case SLIME:
shakeFromSlime.add(e);
break;
case SPIDER:
shakeFromSpider.add(e);
break;
case SNOWMAN:
shakeFromSnowman.add(e);
break;
case SQUID:
shakeFromSquid.add(e);
break;
case WITCH:
shakeFromWitch.add(e);
break;
case ZOMBIE:
shakeFromZombie.add(e);
break;
default:
break;
}
}
else if (treasure instanceof HylianTreasure) {
if (hylianTreasures == null || !hylianTreasures.contains(treasureKey)) {
continue;
}
HylianTreasure hTreasure = (HylianTreasure) treasure;
if (hTreasure.getDropsFromBushes()) {
hylianFromBushes.add(hTreasure);
}
if (hTreasure.getDropsFromFlowers()) {
hylianFromFlowers.add(hTreasure);
}
if (hTreasure.getDropsFromPots()) {
hylianFromPots.add(hTreasure);
}
}
else if (treasure instanceof ExcavationTreasure) {
if (excavationTreasures == null || !excavationTreasures.contains(treasureKey)) {
continue;
}
ExcavationTreasure eTreasure = (ExcavationTreasure) treasure;
if (eTreasure.getDropsFromDirt()) {
excavationFromDirt.add(eTreasure);
}
if (eTreasure.getDropsFromGrass()) {
excavationFromGrass.add(eTreasure);
}
if (eTreasure.getDropsFromSand()) {
excavationFromSand.add(eTreasure);
}
if (eTreasure.getDropsFromGravel()) {
excavationFromGravel.add(eTreasure);
}
if (eTreasure.getDropsFromClay()) {
excavationFromClay.add(eTreasure);
}
if (eTreasure.getDropsFromMycel()) {
excavationFromMycel.add(eTreasure);
}
if (eTreasure.getDropsFromSoulSand()) {
excavationFromSoulSand.add(eTreasure);
}
} }
} }
} }
public double getItemDropRate(int tier, Rarity rarity) { return config.getDouble("Item_Drop_Rates.Tier_" + tier + "." + rarity.toString()); } private boolean noErrorsInTreasure(List<String> issues) {
public double getEnchantmentDropRate(int tier, Rarity rarity) { return config.getDouble("Enchantment_Drop_Rates.Tier_" + tier + "." + rarity.toString()); } for (String issue : issues) {
plugin.getLogger().warning(issue);
}
return issues.isEmpty();
}
} }

View File

@@ -4,16 +4,11 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
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
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 +32,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 +43,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.
@@ -73,32 +64,16 @@ public interface DatabaseManager {
* Load a player from the database. * Load a player from the database.
* *
* @param playerName The name of the player to load from the database * @param playerName The name of the player to load from the database
* @param createNew Whether to create a new record if the player is not * @return The player's data
* found
* @return The player's data, or an unloaded PlayerProfile if not found
* and createNew is false
*/ */
public PlayerProfile loadPlayerProfile(String playerName, boolean createNew); public List<String> loadPlayerData(String playerName);
/** /**
* Get all users currently stored in the database. * Convert player data to a different storage format.
* *
* @return list of playernames * @param data The player's data
* @return true if the conversion was successful, false otherwise
* @throws Exception
*/ */
public List<String> getStoredUsers(); public boolean convert(String[] data) throws Exception;
/**
* Convert all users from this database to the provided database using
* {@link #saveUser(PlayerProfile)}.
*
* @param destination The DatabaseManager to save to
*/
public void convertUsers(DatabaseManager destination);
/**
* Retrieve the type of database in use. Custom databases should return CUSTOM.
*
* @return The type of database
*/
public DatabaseType getDatabaseType();
} }

View File

@@ -1,87 +1,9 @@
package com.gmail.nossr50.database; package com.gmail.nossr50.database;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.database.DatabaseType;
public class DatabaseManagerFactory { public class DatabaseManagerFactory {
private static Class<? extends DatabaseManager> customManager = null;
public static DatabaseManager getDatabaseManager() { public static DatabaseManager getDatabaseManager() {
if (customManager != null) {
try {
return createDefaultCustomDatabaseManager();
}
catch (Exception e) {
mcMMO.p.debug("Could not create custom database manager");
e.printStackTrace();
}
catch (Throwable e) {
mcMMO.p.debug("Failed to create custom database manager");
e.printStackTrace();
}
mcMMO.p.debug("Falling back on " + (Config.getInstance().getUseMySQL() ? "SQL" : "Flatfile") + " database");
}
return Config.getInstance().getUseMySQL() ? new SQLDatabaseManager() : new FlatfileDatabaseManager(); return Config.getInstance().getUseMySQL() ? new SQLDatabaseManager() : new FlatfileDatabaseManager();
} }
/**
* Sets the custom DatabaseManager class for mcMMO to use. This should be
* called prior to mcMMO enabling.
* <p/>
* The provided class must have an empty constructor, which is the one
* that will be used.
* <p/>
* 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
* versions.
*
* @param clazz the DatabaseManager class to use
*
* @throws IllegalArgumentException if the provided class does not have
* an empty constructor
*/
public static void setCustomDatabaseManagerClass(Class<? extends DatabaseManager> clazz) {
try {
clazz.getConstructor((Class<?>) null);
customManager = clazz;
}
catch (Throwable e) {
throw new IllegalArgumentException("Provided database manager class must have an empty constructor", e);
}
}
public static Class<? extends DatabaseManager> getCustomDatabaseManagerClass() {
return customManager;
}
public static DatabaseManager createDatabaseManager(DatabaseType type) {
switch (type) {
case FLATFILE:
return new FlatfileDatabaseManager();
case SQL:
return new SQLDatabaseManager();
case CUSTOM:
try {
return createDefaultCustomDatabaseManager();
}
catch (Throwable e) {
e.printStackTrace();
}
default:
return null;
}
}
public static DatabaseManager createDefaultCustomDatabaseManager() throws Throwable {
return customManager.getConstructor((Class<?>) null).newInstance((Object[]) null);
}
public static DatabaseManager createCustomDatabaseManager(Class<? extends DatabaseManager> clazz) throws Throwable {
return clazz.getConstructor((Class<?>) null).newInstance((Object[]) null);
}
} }

View File

@@ -5,7 +5,6 @@ import java.sql.DriverManager;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
@@ -16,15 +15,15 @@ import java.util.Properties;
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.MobHealthbarType; import com.gmail.nossr50.datatypes.MobHealthbarType;
import com.gmail.nossr50.datatypes.database.DatabaseType;
import com.gmail.nossr50.datatypes.database.DatabaseUpdateType; import com.gmail.nossr50.datatypes.database.DatabaseUpdateType;
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.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.datatypes.spout.huds.HudType;
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;
import com.gmail.nossr50.util.StringUtils;
public final class SQLDatabaseManager implements DatabaseManager { public final class SQLDatabaseManager implements DatabaseManager {
private String connectionString; private String connectionString;
@@ -50,16 +49,11 @@ public final class SQLDatabaseManager implements DatabaseManager {
private int reconnectAttempt = 0; private int reconnectAttempt = 0;
protected SQLDatabaseManager() { protected SQLDatabaseManager() {
checkStructure(); checkConnected();
createStructure();
new SQLDatabaseKeepaliveTask(this).runTaskTimerAsynchronously(mcMMO.p, 10, 60L * 60 * Misc.TICK_CONVERSION_FACTOR);
} }
public void purgePowerlessUsers() { public void purgePowerlessUsers() {
if (!checkConnected()) {
return;
}
mcMMO.p.getLogger().info("Purging powerless users..."); mcMMO.p.getLogger().info("Purging powerless users...");
Collection<ArrayList<String>> usernames = read("SELECT u.user FROM " + tablePrefix + "skills AS s, " + tablePrefix + "users AS u WHERE s.user_id = u.id AND (s.taming+s.mining+s.woodcutting+s.repair+s.unarmed+s.herbalism+s.excavation+s.archery+s.swords+s.axes+s.acrobatics+s.fishing) = 0").values(); Collection<ArrayList<String>> usernames = read("SELECT u.user FROM " + tablePrefix + "skills AS s, " + tablePrefix + "users AS u WHERE s.user_id = u.id AND (s.taming+s.mining+s.woodcutting+s.repair+s.unarmed+s.herbalism+s.excavation+s.archery+s.swords+s.axes+s.acrobatics+s.fishing) = 0").values();
@@ -76,10 +70,6 @@ public final class SQLDatabaseManager implements DatabaseManager {
} }
public void purgeOldUsers() { public void purgeOldUsers() {
if (!checkConnected()) {
return;
}
long currentTime = System.currentTimeMillis(); long currentTime = System.currentTimeMillis();
mcMMO.p.getLogger().info("Purging old users..."); mcMMO.p.getLogger().info("Purging old users...");
@@ -94,14 +84,10 @@ 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) {
if (!checkConnected()) {
return false;
}
boolean success = update("DELETE FROM u, e, h, s, c " + boolean success = update("DELETE FROM u, e, h, s, c " +
"USING " + tablePrefix + "users u " + "USING " + tablePrefix + "users u " +
"JOIN " + tablePrefix + "experience e ON (u.id = e.user_id) " + "JOIN " + tablePrefix + "experience e ON (u.id = e.user_id) " +
@@ -115,39 +101,28 @@ public final class SQLDatabaseManager implements DatabaseManager {
return success; return success;
} }
public boolean saveUser(PlayerProfile profile) { public void saveUser(PlayerProfile profile) {
if (!checkConnected()) {
return false;
}
int userId = readId(profile.getPlayerName()); int userId = readId(profile.getPlayerName());
if (userId == -1) {
newUser(profile.getPlayerName());
userId = readId(profile.getPlayerName());
if (userId == -1) {
return false;
}
}
boolean success = true;
MobHealthbarType mobHealthbarType = profile.getMobHealthbarType(); MobHealthbarType mobHealthbarType = profile.getMobHealthbarType();
HudType hudType = profile.getHudType();
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, (hudType == null ? "STANDARD" : hudType.toString()), (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 = ?"
+ ", axes = ?, blast_mining = ? WHERE user_id = ?", + ", axes = ?, blast_mining = ? WHERE user_id = ?",
userId, userId,
profile.getAbilityDATS(AbilityType.SUPER_BREAKER), profile.getSkillDATS(AbilityType.SUPER_BREAKER),
profile.getAbilityDATS(AbilityType.TREE_FELLER), profile.getSkillDATS(AbilityType.TREE_FELLER),
profile.getAbilityDATS(AbilityType.BERSERK), profile.getSkillDATS(AbilityType.BERSERK),
profile.getAbilityDATS(AbilityType.GREEN_TERRA), profile.getSkillDATS(AbilityType.GREEN_TERRA),
profile.getAbilityDATS(AbilityType.GIGA_DRILL_BREAKER), profile.getSkillDATS(AbilityType.GIGA_DRILL_BREAKER),
profile.getAbilityDATS(AbilityType.SERRATED_STRIKES), profile.getSkillDATS(AbilityType.SERRATED_STRIKES),
profile.getAbilityDATS(AbilityType.SKULL_SPLITTER), profile.getSkillDATS(AbilityType.SKULL_SPLITTER),
profile.getAbilityDATS(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 +141,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 +160,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 +204,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 +236,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 +273,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;
} }
} }
@@ -315,20 +289,15 @@ public final class SQLDatabaseManager implements DatabaseManager {
} }
public void newUser(String playerName) { public void newUser(String playerName) {
if (!checkConnected()) {
return;
}
PreparedStatement statement = null; PreparedStatement statement = null;
try { try {
statement = connection.prepareStatement("INSERT INTO " + tablePrefix + "users (user, lastlogin) VALUES (?, ?)", Statement.RETURN_GENERATED_KEYS); statement = connection.prepareStatement("INSERT INTO " + tablePrefix + "users (user, lastlogin) VALUES (?, ?)");
statement.setString(1, playerName); statement.setString(1, playerName);
statement.setLong(2, System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR); statement.setLong(2, System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR);
statement.execute(); statement.execute();
int id = readId(playerName); writeMissingRows(readId(playerName));
writeMissingRows(id);
} }
catch (SQLException ex) { catch (SQLException ex) {
printErrors(ex); printErrors(ex);
@@ -345,15 +314,8 @@ public final class SQLDatabaseManager implements DatabaseManager {
} }
} }
public PlayerProfile loadPlayerProfile(String playerName, boolean create) { public List<String> loadPlayerData(String playerName) {
return loadPlayerProfile(playerName, create, true); List<String> playerData = null;
}
private PlayerProfile loadPlayerProfile(String playerName, boolean create, boolean retry) {
if (!checkConnected()) {
return new PlayerProfile(playerName, false); // return fake profile if not connected
}
PreparedStatement statement = null; PreparedStatement statement = null;
try { try {
@@ -362,7 +324,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
+ "s.taming, s.mining, s.repair, s.woodcutting, s.unarmed, s.herbalism, s.excavation, s.archery, s.swords, s.axes, s.acrobatics, s.fishing, " + "s.taming, s.mining, s.repair, s.woodcutting, s.unarmed, s.herbalism, s.excavation, s.archery, s.swords, s.axes, s.acrobatics, s.fishing, "
+ "e.taming, e.mining, e.repair, e.woodcutting, e.unarmed, e.herbalism, e.excavation, e.archery, e.swords, e.axes, e.acrobatics, e.fishing, " + "e.taming, e.mining, e.repair, e.woodcutting, e.unarmed, e.herbalism, e.excavation, e.archery, e.swords, e.axes, e.acrobatics, e.fishing, "
+ "c.taming, c.mining, c.repair, c.woodcutting, c.unarmed, c.herbalism, c.excavation, c.archery, c.swords, c.axes, c.acrobatics, c.blast_mining, " + "c.taming, c.mining, c.repair, c.woodcutting, c.unarmed, c.herbalism, c.excavation, c.archery, c.swords, c.axes, c.acrobatics, c.blast_mining, "
+ "h.mobhealthbar " + "h.hudtype, h.mobhealthbar, NOW() "
+ "FROM " + tablePrefix + "users u " + "FROM " + tablePrefix + "users u "
+ "JOIN " + tablePrefix + "skills s ON (u.id = s.user_id) " + "JOIN " + tablePrefix + "skills s ON (u.id = s.user_id) "
+ "JOIN " + tablePrefix + "experience e ON (u.id = e.user_id) " + "JOIN " + tablePrefix + "experience e ON (u.id = e.user_id) "
@@ -371,18 +333,22 @@ public final class SQLDatabaseManager implements DatabaseManager {
+ "WHERE u.user = ?"); + "WHERE u.user = ?");
statement.setString(1, playerName); statement.setString(1, playerName);
ResultSet result = statement.executeQuery(); playerData = readRow(statement);
if (result.next()) { if (playerData == null || playerData.size() == 0) {
try { int userId = readId(playerName);
PlayerProfile ret = loadFromResult(playerName, result);
result.close(); // Check if user doesn't exist
return ret; if (userId == 0) {
} return playerData;
catch (SQLException e) {
} }
// Write missing table rows
writeMissingRows(userId);
// Re-read data
playerData = loadPlayerData(playerName);
} }
result.close();
} }
catch (SQLException ex) { catch (SQLException ex) {
printErrors(ex); printErrors(ex);
@@ -397,87 +363,106 @@ public final class SQLDatabaseManager implements DatabaseManager {
} }
} }
} }
return playerData;
// 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
int id = readId(playerName);
if (id == -1) {
// There is no such user
if (create) {
newUser(playerName);
return loadPlayerProfile(playerName, false, false);
}
// Return unloaded profile if can't create
return new PlayerProfile(playerName, false);
}
// There is such a user
writeMissingRows(id);
// Retry, and abort on re-failure
return loadPlayerProfile(playerName, create, false);
} }
public void convertUsers(DatabaseManager destination) { public boolean convert(String[] data) throws Exception {
if (!checkConnected()) { String playerName = data[0];
return;
// Check for things we don't want put in the DB
if (playerName == null || playerName.equalsIgnoreCase("null") || playerName.length() > 16) {
return false;
} }
PreparedStatement statement = null; String mining = (data.length > 1) ? data[1] : null;
String woodcutting = (data.length > 5) ? data[5] : null;
String repair = (data.length > 7) ? data[7] : null;
String unarmed = (data.length > 8) ? data[8] : null;
String herbalism = (data.length > 9) ? data[9] : null;
String excavation = (data.length > 10) ? data[10] : null;
String archery = (data.length > 11) ? data[11] : null;
String swords = (data.length > 12) ? data[12] : null;
String axes = (data.length > 13) ? data[13] : null;
String acrobatics = (data.length > 14) ? data[14] : null;
String taming = (data.length > 24) ? data[24] : null;
String fishing = (data.length > 34) ? data[34] : null;
try { String miningXP = (data.length > 4) ? data[4] : null;
statement = connection.prepareStatement( String woodCuttingXP = (data.length > 6) ? data[6] : null;;
"SELECT " String repairXP = (data.length > 15) ? data[15] : null;
+ "s.taming, s.mining, s.repair, s.woodcutting, s.unarmed, s.herbalism, s.excavation, s.archery, s.swords, s.axes, s.acrobatics, s.fishing, " String unarmedXP = (data.length > 16) ? data[16] : null;
+ "e.taming, e.mining, e.repair, e.woodcutting, e.unarmed, e.herbalism, e.excavation, e.archery, e.swords, e.axes, e.acrobatics, e.fishing, " String herbalismXP = (data.length > 17) ? data[17] : null;
+ "c.taming, c.mining, c.repair, c.woodcutting, c.unarmed, c.herbalism, c.excavation, c.archery, c.swords, c.axes, c.acrobatics, c.blast_mining, " String excavationXP = (data.length > 18) ? data[18] : null;
+ "h.mobhealthbar " String archeryXP = (data.length > 19) ? data[19] : null;
+ "FROM " + tablePrefix + "users u " String swordsXP = (data.length > 20) ? data[20] : null;
+ "JOIN " + tablePrefix + "skills s ON (u.id = s.user_id) " String axesXP = (data.length > 21) ? data[21] : null;
+ "JOIN " + tablePrefix + "experience e ON (u.id = e.user_id) " String acrobaticsXP = (data.length > 22) ? data[22] : null;
+ "JOIN " + tablePrefix + "cooldowns c ON (u.id = c.user_id) " String tamingXP = (data.length > 25) ? data[25] : null;
+ "JOIN " + tablePrefix + "huds h ON (u.id = h.user_id) " String fishingXP = (data.length > 35) ? data[35] : null;
+ "WHERE u.user = ?");
List<String> usernames = getStoredUsers(); String superBreakerCooldown = (data.length > 32) ? data[32] : null;
ResultSet result = null; String treeFellerCooldown = (data.length > 28) ? data[28] : null;
int convertedUsers = 0; String berserkCooldown = (data.length > 26) ? data[26] : null;
long startMillis = System.currentTimeMillis(); String greenTerraCooldown = (data.length > 29) ? data[29] : null;
for (String playerName : usernames) { String gigaDrillBreakerCooldown = (data.length > 27) ? data[27] : null;
statement.setString(1, playerName); String serratedStrikesCooldown = (data.length > 30) ? data[30] : null;
try { String skullSplitterCooldown = (data.length > 31) ? data[31] : null;
result = statement.executeQuery(); String blastMiningCooldown = (data.length > 36) ? data[36] : null;
result.next();
destination.saveUser(loadFromResult(playerName, result)); String hudType = (data.length > 33) ? data[33] : null;
result.close(); String mobHealthbarType = (data.length > 38 ? data[38] : null);
} long lastLogin = mcMMO.p.getServer().getOfflinePlayer(playerName).getLastPlayed();
catch (SQLException e) {
// Ignore int id = readId(playerName); // Check to see if the user is in the DB
}
convertedUsers++; // Create the user if they don't exist
Misc.printProgress(convertedUsers, progressInterval, startMillis); if (id == 0) {
} newUser(playerName);
} id = readId(playerName);
catch (SQLException e) {
printErrors(e);
}
finally {
if (statement != null) {
try {
statement.close();
}
catch (SQLException e) {
// Ignore
}
}
} }
saveLogin(id, lastLogin);
saveIntegers(
"UPDATE " + tablePrefix + "skills SET "
+ " taming = ?, mining = ?, repair = ?, woodcutting = ?"
+ ", unarmed = ?, herbalism = ?, excavation = ?"
+ ", archery = ?, swords = ?, axes = ?, acrobatics = ?"
+ ", fishing = ? WHERE user_id = ?",
StringUtils.getInt(taming), StringUtils.getInt(mining),
StringUtils.getInt(repair), StringUtils.getInt(woodcutting),
StringUtils.getInt(unarmed), StringUtils.getInt(herbalism),
StringUtils.getInt(excavation), StringUtils.getInt(archery),
StringUtils.getInt(swords), StringUtils.getInt(axes),
StringUtils.getInt(acrobatics), StringUtils.getInt(fishing),
id);
saveIntegers(
"UPDATE " + tablePrefix + "experience SET "
+ " taming = ?, mining = ?, repair = ?, woodcutting = ?"
+ ", unarmed = ?, herbalism = ?, excavation = ?"
+ ", archery = ?, swords = ?, axes = ?, acrobatics = ?"
+ ", fishing = ? WHERE user_id = ?",
StringUtils.getInt(tamingXP), StringUtils.getInt(miningXP),
StringUtils.getInt(repairXP), StringUtils.getInt(woodCuttingXP),
StringUtils.getInt(unarmedXP), StringUtils.getInt(herbalismXP),
StringUtils.getInt(excavationXP), StringUtils.getInt(archeryXP),
StringUtils.getInt(swordsXP), StringUtils.getInt(axesXP),
StringUtils.getInt(acrobaticsXP), StringUtils.getInt(fishingXP),
id);
saveLongs(
"UPDATE " + tablePrefix + "cooldowns SET "
+ " taming = ?, mining = ?, repair = ?, woodcutting = ?"
+ ", unarmed = ?, herbalism = ?, excavation = ?"
+ ", archery = ?, swords = ?, axes = ?, acrobatics = ?"
+ ", blast_mining = ? WHERE user_id = ?",
id,
StringUtils.getLong(null), StringUtils.getLong(superBreakerCooldown),
StringUtils.getLong(null), StringUtils.getInt(treeFellerCooldown),
StringUtils.getLong(berserkCooldown), StringUtils.getLong(greenTerraCooldown),
StringUtils.getLong(gigaDrillBreakerCooldown), StringUtils.getLong(null),
StringUtils.getLong(serratedStrikesCooldown), StringUtils.getLong(skullSplitterCooldown),
StringUtils.getLong(null), StringUtils.getLong(blastMiningCooldown));
saveHuds(id, hudType, mobHealthbarType);
return true;
} }
/** /**
@@ -570,40 +555,9 @@ public final class SQLDatabaseManager implements DatabaseManager {
return false; return false;
} }
public List<String> getStoredUsers() {
ArrayList<String> users = new ArrayList<String>();
if (checkConnected()) {
Statement stmt = null;
try {
stmt = connection.createStatement();
ResultSet result = stmt.executeQuery("SELECT user FROM " + tablePrefix + "users");
while (result.next()) {
users.add(result.getString("user"));
}
result.close();
}
catch (SQLException e) {
printErrors(e);
}
finally {
if (stmt != null) {
try {
stmt.close();
}
catch (SQLException e) {
// Ignore
}
}
}
}
return users;
}
/** /**
* Attempt to connect to the mySQL database. * Attempt to connect to the mySQL database.
*/ */
private void connect() { private void connect() {
connectionString = "jdbc:mysql://" + Config.getInstance().getMySQLServerName() + ":" + Config.getInstance().getMySQLServerPort() + "/" + Config.getInstance().getMySQLDatabaseName(); connectionString = "jdbc:mysql://" + Config.getInstance().getMySQLServerName() + ":" + Config.getInstance().getMySQLServerPort() + "/" + Config.getInstance().getMySQLDatabaseName();
@@ -625,27 +579,22 @@ public final class SQLDatabaseManager implements DatabaseManager {
connection = null; connection = null;
if (reconnectAttempt == 0 || reconnectAttempt >= 11) { if (reconnectAttempt == 0 || reconnectAttempt >= 11) {
mcMMO.p.getLogger().severe("Connection to MySQL failed!"); mcMMO.p.getLogger().info("Connection to MySQL failed!");
printErrors(ex);
} }
} }
catch (ClassNotFoundException ex) { catch (ClassNotFoundException ex) {
connection = null; connection = null;
if (reconnectAttempt == 0 || reconnectAttempt >= 11) { if (reconnectAttempt == 0 || reconnectAttempt >= 11) {
mcMMO.p.getLogger().severe("MySQL database driver not found!"); mcMMO.p.getLogger().info("MySQL database driver not found!");
} }
} }
} }
/** /**
* Checks that the database structure is present and correct * Attempt to create the database structure.
*/ */
private void checkStructure() { private void createStructure() {
if (!checkConnected()) {
return;
}
write("CREATE TABLE IF NOT EXISTS `" + tablePrefix + "users` (" write("CREATE TABLE IF NOT EXISTS `" + tablePrefix + "users` ("
+ "`id` int(10) unsigned NOT NULL AUTO_INCREMENT," + "`id` int(10) unsigned NOT NULL AUTO_INCREMENT,"
+ "`user` varchar(40) NOT NULL," + "`user` varchar(40) NOT NULL,"
@@ -654,6 +603,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
+ "UNIQUE KEY `user` (`user`)) DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;"); + "UNIQUE KEY `user` (`user`)) DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;");
write("CREATE TABLE IF NOT EXISTS `" + tablePrefix + "huds` (" write("CREATE TABLE IF NOT EXISTS `" + tablePrefix + "huds` ("
+ "`user_id` int(10) unsigned NOT NULL," + "`user_id` int(10) unsigned NOT NULL,"
+ "`hudtype` varchar(50) NOT NULL DEFAULT 'STANDARD',"
+ "`mobhealthbar` varchar(50) NOT NULL DEFAULT '" + Config.getInstance().getMobHealthbarDefault() + "'," + "`mobhealthbar` varchar(50) NOT NULL DEFAULT '" + Config.getInstance().getMobHealthbarDefault() + "',"
+ "PRIMARY KEY (`user_id`)) " + "PRIMARY KEY (`user_id`)) "
+ "DEFAULT CHARSET=latin1;"); + "DEFAULT CHARSET=latin1;");
@@ -712,10 +662,10 @@ public final class SQLDatabaseManager implements DatabaseManager {
} }
/** /**
* Check database structure for missing values. * Check database structure for missing values.
* *
* @param update Type of data to check updates for * @param update Type of data to check updates for
*/ */
private void checkDatabaseStructure(DatabaseUpdateType update) { private void checkDatabaseStructure(DatabaseUpdateType update) {
String sql = ""; String sql = "";
@@ -754,10 +704,6 @@ public final class SQLDatabaseManager implements DatabaseManager {
write("ALTER TABLE `" + tablePrefix + "users` DROP COLUMN `party` ;"); write("ALTER TABLE `" + tablePrefix + "users` DROP COLUMN `party` ;");
return; return;
case DROPPED_SPOUT:
write("ALTER TABLE `" + tablePrefix + "huds` DROP COLUMN `hudtype` ;");
return;
case KILL_ORPHANS: case KILL_ORPHANS:
mcMMO.p.getLogger().info("Killing orphans"); mcMMO.p.getLogger().info("Killing orphans");
write( write(
@@ -847,11 +793,11 @@ public final class SQLDatabaseManager implements DatabaseManager {
} }
/** /**
* Attempt to write the SQL query. * Attempt to write the SQL query.
* *
* @param sql Query to write. * @param sql Query to write.
* @return true if the query was successfully written, false otherwise. * @return true if the query was successfully written, false otherwise.
*/ */
private boolean write(String sql) { private boolean write(String sql) {
if (!checkConnected()) { if (!checkConnected()) {
return false; return false;
@@ -864,7 +810,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
return true; return true;
} }
catch (SQLException ex) { catch (SQLException ex) {
if (!sql.contains("DROP COLUMN")) { if (!sql.equalsIgnoreCase("ALTER TABLE `" + tablePrefix + "users` DROP COLUMN `party` ;")) {
printErrors(ex); printErrors(ex);
} }
return false; return false;
@@ -882,11 +828,11 @@ public final class SQLDatabaseManager implements DatabaseManager {
} }
/** /**
* Returns the number of rows affected by either a DELETE or UPDATE query * Returns the number of rows affected by either a DELETE or UPDATE query
* *
* @param sql SQL query to execute * @param sql SQL query to execute
* @return the number of rows affected * @return the number of rows affected
*/ */
private int update(String sql) { private int update(String sql) {
int rows = 0; int rows = 0;
@@ -916,11 +862,11 @@ public final class SQLDatabaseManager implements DatabaseManager {
} }
/** /**
* Read SQL query. * Read SQL query.
* *
* @param sql SQL query to read * @param sql SQL query to read
* @return the rows in this SQL query * @return the rows in this SQL query
*/ */
private HashMap<Integer, ArrayList<String>> read(String sql) { private HashMap<Integer, ArrayList<String>> read(String sql) {
HashMap<Integer, ArrayList<String>> rows = new HashMap<Integer, ArrayList<String>>(); HashMap<Integer, ArrayList<String>> rows = new HashMap<Integer, ArrayList<String>>();
@@ -960,14 +906,47 @@ public final class SQLDatabaseManager implements DatabaseManager {
return rows; return rows;
} }
private ArrayList<String> readRow(PreparedStatement statement) {
ArrayList<String> playerData = new ArrayList<String>();
if (checkConnected()) {
ResultSet resultSet = null;
try {
resultSet = statement.executeQuery();
if (resultSet.next()) {
for (int i = 1; i <= resultSet.getMetaData().getColumnCount(); i++) {
playerData.add(resultSet.getString(i));
}
}
}
catch (SQLException ex) {
printErrors(ex);
}
finally {
if (statement != null) {
try {
statement.close();
}
catch (SQLException e) {
// Ignore
}
}
}
}
return playerData;
}
/** /**
* Get the Integer. Only return first row / first field. * Get the Integer. Only return first row / first field.
* *
* @param statement SQL query to execute * @param sql SQL query to execute
* @return the value in the first row / first field * @return the value in the first row / first field
*/ */
private int readInt(PreparedStatement statement) { private int readInt(PreparedStatement statement) {
int result = -1; int result = 0;
if (checkConnected()) { if (checkConnected()) {
ResultSet resultSet = null; ResultSet resultSet = null;
@@ -1042,7 +1021,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 +1033,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 +1049,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 +1062,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) {
@@ -1103,14 +1078,8 @@ public final class SQLDatabaseManager implements DatabaseManager {
} }
} }
/**
* Retrieve the database id for a player
*
* @param playerName The name of the user to retrieve the id for
* @return the requested id or -1 if not found
*/
private int readId(String playerName) { private int readId(String playerName) {
int id = -1; int id = 0;
try { try {
PreparedStatement statement = connection.prepareStatement("SELECT id FROM " + tablePrefix + "users WHERE user = ?"); PreparedStatement statement = connection.prepareStatement("SELECT id FROM " + tablePrefix + "users WHERE user = ?");
@@ -1124,7 +1093,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 +1101,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,19 +1117,18 @@ public final class SQLDatabaseManager implements DatabaseManager {
} }
} }
private boolean saveHuds(int userId, String mobHealthBar) { private void saveHuds(int userId, String hudType, String mobHealthBar) {
PreparedStatement statement = null; PreparedStatement statement = null;
try { try {
statement = connection.prepareStatement("UPDATE " + tablePrefix + "huds SET mobhealthbar = ? WHERE user_id = ?"); statement = connection.prepareStatement("UPDATE " + tablePrefix + "huds SET hudtype = ?, mobhealthbar = ? WHERE user_id = ?");
statement.setString(1, mobHealthBar); statement.setString(1, hudType);
statement.setInt(2, userId); statement.setString(2, mobHealthBar);
statement.setInt(3, 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) {
@@ -1176,73 +1142,9 @@ public final class SQLDatabaseManager implements DatabaseManager {
} }
} }
private PlayerProfile loadFromResult(String playerName, ResultSet result) throws SQLException {
Map<SkillType, Integer> skills = new HashMap<SkillType, Integer>(); // Skill & Level
Map<SkillType, Float> skillsXp = new HashMap<SkillType, Float>(); // Skill & XP
Map<AbilityType, Integer> skillsDATS = new HashMap<AbilityType, Integer>(); // Ability & Cooldown
MobHealthbarType mobHealthbarType;
final int OFFSET_SKILLS = 0; // TODO update these numbers when the query changes (a new skill is added)
final int OFFSET_XP = 12;
final int OFFSET_DATS = 24;
final int OFFSET_OTHER = 36;
skills.put(SkillType.TAMING, result.getInt(OFFSET_SKILLS + 1));
skills.put(SkillType.MINING, result.getInt(OFFSET_SKILLS + 2));
skills.put(SkillType.REPAIR, result.getInt(OFFSET_SKILLS + 3));
skills.put(SkillType.WOODCUTTING, result.getInt(OFFSET_SKILLS + 4));
skills.put(SkillType.UNARMED, result.getInt(OFFSET_SKILLS + 5));
skills.put(SkillType.HERBALISM, result.getInt(OFFSET_SKILLS + 6));
skills.put(SkillType.EXCAVATION, result.getInt(OFFSET_SKILLS + 7));
skills.put(SkillType.ARCHERY, result.getInt(OFFSET_SKILLS + 8));
skills.put(SkillType.SWORDS, result.getInt(OFFSET_SKILLS + 9));
skills.put(SkillType.AXES, result.getInt(OFFSET_SKILLS + 10));
skills.put(SkillType.ACROBATICS, result.getInt(OFFSET_SKILLS + 11));
skills.put(SkillType.FISHING, result.getInt(OFFSET_SKILLS + 12));
skillsXp.put(SkillType.TAMING, result.getFloat(OFFSET_XP + 1));
skillsXp.put(SkillType.MINING, result.getFloat(OFFSET_XP + 2));
skillsXp.put(SkillType.REPAIR, result.getFloat(OFFSET_XP + 3));
skillsXp.put(SkillType.WOODCUTTING, result.getFloat(OFFSET_XP + 4));
skillsXp.put(SkillType.UNARMED, result.getFloat(OFFSET_XP + 5));
skillsXp.put(SkillType.HERBALISM, result.getFloat(OFFSET_XP + 6));
skillsXp.put(SkillType.EXCAVATION, result.getFloat(OFFSET_XP + 7));
skillsXp.put(SkillType.ARCHERY, result.getFloat(OFFSET_XP + 8));
skillsXp.put(SkillType.SWORDS, result.getFloat(OFFSET_XP + 9));
skillsXp.put(SkillType.AXES, result.getFloat(OFFSET_XP + 10));
skillsXp.put(SkillType.ACROBATICS, result.getFloat(OFFSET_XP + 11));
skillsXp.put(SkillType.FISHING, result.getFloat(OFFSET_XP + 12));
// Taming - Unused - result.getInt(OFFSET_DATS + 1)
skillsDATS.put(AbilityType.SUPER_BREAKER, result.getInt(OFFSET_DATS + 2));
// Repair - Unused - result.getInt(OFFSET_DATS + 3)
skillsDATS.put(AbilityType.TREE_FELLER, result.getInt(OFFSET_DATS + 4));
skillsDATS.put(AbilityType.BERSERK, result.getInt(OFFSET_DATS + 5));
skillsDATS.put(AbilityType.GREEN_TERRA, result.getInt(OFFSET_DATS + 6));
skillsDATS.put(AbilityType.GIGA_DRILL_BREAKER, result.getInt(OFFSET_DATS + 7));
// Archery - Unused - result.getInt(OFFSET_DATS + 8)
skillsDATS.put(AbilityType.SERRATED_STRIKES, result.getInt(OFFSET_DATS + 9));
skillsDATS.put(AbilityType.SKULL_SPLITTER, result.getInt(OFFSET_DATS + 10));
// Acrobatics - Unused - result.getInt(OFFSET_DATS + 11)
skillsDATS.put(AbilityType.BLAST_MINING, result.getInt(OFFSET_DATS + 12));
try {
mobHealthbarType = MobHealthbarType.valueOf(result.getString(OFFSET_OTHER + 2));
}
catch (Exception e) {
mobHealthbarType = Config.getInstance().getMobHealthbarDefault();
}
return new PlayerProfile(playerName, skills, skillsXp, skillsDATS, mobHealthbarType);
}
private void printErrors(SQLException ex) { private void printErrors(SQLException ex) {
mcMMO.p.getLogger().severe("SQLException: " + ex.getMessage()); mcMMO.p.getLogger().severe("SQLException: " + ex.getMessage());
mcMMO.p.getLogger().severe("SQLState: " + ex.getSQLState()); mcMMO.p.getLogger().severe("SQLState: " + ex.getSQLState());
mcMMO.p.getLogger().severe("VendorError: " + ex.getErrorCode()); mcMMO.p.getLogger().severe("VendorError: " + ex.getErrorCode());
} }
}
public DatabaseType getDatabaseType() {
return DatabaseType.SQL;
}
}

View File

@@ -1,24 +0,0 @@
package com.gmail.nossr50.datatypes.chat;
import com.gmail.nossr50.locale.LocaleLoader;
public enum ChatMode {
ADMIN(LocaleLoader.getString("Commands.AdminChat.On"), LocaleLoader.getString("Commands.AdminChat.Off")),
PARTY(LocaleLoader.getString("Commands.Party.Chat.On"), LocaleLoader.getString("Commands.Party.Chat.Off"));
private String enabledMessage;
private String disabledMessage;
private ChatMode(String enabledMessage, String disabledMessage) {
this.enabledMessage = enabledMessage;
this.disabledMessage = disabledMessage;
}
public String getEnabledMessage() {
return enabledMessage;
}
public String getDisabledMessage() {
return disabledMessage;
}
}

View File

@@ -1,24 +0,0 @@
package com.gmail.nossr50.datatypes.database;
public enum DatabaseType {
FLATFILE,
SQL,
CUSTOM;
public static DatabaseType getDatabaseType(String typeName) {
for (DatabaseType type : values()) {
if (type.name().equalsIgnoreCase(typeName)) {
return type;
}
}
if (typeName.equalsIgnoreCase("file")) {
return FLATFILE;
}
else if (typeName.equalsIgnoreCase("mysql")) {
return SQL;
}
return CUSTOM;
}
}

View File

@@ -5,8 +5,7 @@ public enum DatabaseUpdateType {
BLAST_MINING, BLAST_MINING,
INDEX, INDEX,
MOB_HEALTHBARS, MOB_HEALTHBARS,
PARTY_NAMES, PARTY_NAMES,
KILL_ORPHANS, KILL_ORPHANS,
DROPPED_SPOUT
; ;
} }

View File

@@ -1,16 +0,0 @@
package com.gmail.nossr50.datatypes.experience;
public enum FormulaType {
LINEAR,
EXPONENTIAL,
UNKNOWN;
public static FormulaType getFormulaType(String string) {
try {
return valueOf(string);
}
catch (IllegalArgumentException ex) {
return UNKNOWN;
}
}
};

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