Merge pull request #1 from mcMMO-Dev/master

updating
This commit is contained in:
Mike Pulli 2013-03-05 09:28:16 -08:00
commit 1c9d852b83
325 changed files with 25751 additions and 25399 deletions

4
.gitattributes vendored Normal file
View File

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

File diff suppressed because it is too large Load Diff

View File

@ -1,28 +0,0 @@
== mcMMO
**The RPG lovers mod**
=== Dev builds
http://ci.mcmmo.info Download the latest dev build of mcMMO here.
=== Brief Description
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 Developer
I've always wanted to make games and in the last year I decided to take a swing at developing Minecraft mods as a platform to teach myself programming, the biggest project I have made to date is mcMMO. I went from knowing nothing about Java to what I know now purely from modding Minecraft, and I plan to move onto game development in the not so distant future.
I take design very seriously, I am not the kind of person who can be satisfied giving a project anything less than my all. As you will see reflected in the quality of the mods I make, I take great care in my work.
Hearing that people enjoy mcMMO and seeing the daily youtube videos about my mod has become a joy, I really can't believe how popular my mod has gotten!
=== Compiling
Required Libraries:
* Spout API
* JUnit
Required to Run:
* Bukkit
http://dev.bukkit.org/server-mods/mcmmo for more up to date information.

47
README.md Normal file
View File

@ -0,0 +1,47 @@
# mcMMO
## The RPG lovers mod
### Dev builds
Our latest development builds are available [here](http://ci.mcmmo.info).
### Brief Description
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
mcMMO is currently developed by a team of individuals from all over the world.
### Glorious Leader
[![gmcferrin](http://www.gravatar.com/avatar/b64c52daf25d206b27650788b5813b7b.png)]
(https://github.com/gmcferrin)
### Developers
[![bm01](http://www.gravatar.com/avatar/ec8146f5358177f12e9a252271bbc391.png)]
(https://github.com/bm01)
[![Glitchfinder](http://www.gravatar.com/avatar/5aa4cce22f72ae9c002ecec30f061d00.png)]
(https://github.com/Glitchfinder)
[![nossr50](http://www.gravatar.com/avatar/f2ee41eedfd645fb4a3a2c8f6cb1b18c.png)]
(https://github.com/nossr50)
[![NuclearW](http://www.gravatar.com/avatar/90926bdcf1c8a75918df5ea5fa801ce6.png)]
(https://github.com/NuclearW)
[![shatteredbeam](http://www.gravatar.com/avatar/cad3b5d7d39cf5387afb87f494389610.png)]
(https://github.com/shatteredbeam)
[![TfT_02](http://www.gravatar.com/avatar/b8914f9970e1f6ffd5281ce4770e20a7.png)]
(https://github.com/TfT-02)
[![t00thpick1](http://www.gravatar.com/avatar/??.png)]
(https://github.com/t00thpick1)
## Compiling
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
Required Libraries:
* Spout API
* JUnit
* Metrics
* Bukkit
http://dev.bukkit.org/server-mods/mcmmo for more up to date information.

379
pom.xml
View File

@ -1,197 +1,182 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<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.00-dev4</version> <version>1.4.03-dev1</version>
<name>mcMMO</name> <name>mcMMO</name>
<url>https://github.com/mcMMO-Dev/mcMMO</url> <url>https://github.com/mcMMO-Dev/mcMMO</url>
<issueManagement> <issueManagement>
<url>https://github.com/mcMMO-Dev/mcMMO/issues</url> <url>https://github.com/mcMMO-Dev/mcMMO/issues</url>
<system>GitHub</system> <system>GitHub</system>
</issueManagement> </issueManagement>
<build> <build>
<finalName>mcMMO</finalName> <finalName>mcMMO</finalName>
<sourceDirectory>${basedir}/src/main/java</sourceDirectory> <sourceDirectory>${basedir}/src/main/java</sourceDirectory>
<resources> <resources>
<resource> <resource>
<targetPath>.</targetPath> <targetPath>.</targetPath>
<filtering>true</filtering> <filtering>true</filtering>
<directory>${basedir}/src/main/resources/</directory> <directory>${basedir}/src/main/resources/</directory>
<includes> <includes>
<include>*.yml</include> <include>*.yml</include>
<include>.jenkins</include> <include>.jenkins</include>
</includes> </includes>
</resource> </resource>
<resource> <resource>
<targetPath>resources</targetPath> <targetPath>resources</targetPath>
<filtering>false</filtering> <filtering>false</filtering>
<directory>${basedir}/src/main/resources/xpbar/</directory> <directory>${basedir}/src/main/resources/xpbar/</directory>
<includes> <includes>
<include>xpbar*.png</include> <include>xpbar*.png</include>
</includes> </includes>
</resource> </resource>
<resource> <resource>
<targetPath>resources</targetPath> <targetPath>resources</targetPath>
<filtering>false</filtering> <filtering>false</filtering>
<directory>${basedir}/src/main/resources/healthbar/</directory> <directory>${basedir}/src/main/resources/healthbar/</directory>
<includes> <includes>
<include>health*.png</include> <include>health*.png</include>
</includes> </includes>
</resource> </resource>
<resource> <resource>
<targetPath>resources</targetPath> <targetPath>resources</targetPath>
<filtering>false</filtering> <filtering>false</filtering>
<directory>${basedir}/src/main/resources/skillicon/</directory> <directory>${basedir}/src/main/resources/skillicon/</directory>
<includes> <includes>
<include>*.png</include> <include>*.png</include>
</includes> </includes>
</resource> </resource>
<resource> <resource>
<targetPath>resources</targetPath> <targetPath>resources</targetPath>
<filtering>false</filtering> <filtering>false</filtering>
<directory>${basedir}/src/main/resources/sound/</directory> <directory>${basedir}/src/main/resources/sound/</directory>
<includes> <includes>
<include>*.wav</include> <include>*.wav</include>
</includes> </includes>
</resource> </resource>
<resource> <resource>
<targetPath>com/gmail/nossr50/locale</targetPath> <targetPath>com/gmail/nossr50/locale</targetPath>
<filtering>true</filtering> <filtering>true</filtering>
<directory>${basedir}/src/main/resources/locale/</directory> <directory>${basedir}/src/main/resources/locale/</directory>
<includes> <includes>
<include>locale*.properties</include> <include>locale*.properties</include>
</includes> </includes>
</resource> </resource>
</resources> </resources>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version> <version>2.3.2</version>
<configuration> <configuration>
<source>1.6</source> <source>1.6</source>
<target>1.6</target> <target>1.6</target>
<excludes> <excludes>
</excludes> </excludes>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
<artifactId>maven-assembly-plugin</artifactId> <artifactId>maven-assembly-plugin</artifactId>
<configuration> <configuration>
<descriptors> <descriptors>
<descriptor>src/main/assembly/package.xml</descriptor> <descriptor>src/main/assembly/package.xml</descriptor>
</descriptors> </descriptors>
</configuration> </configuration>
<executions> <executions>
<execution> <execution>
<id>build</id> <id>build</id>
<phase>package</phase> <phase>package</phase>
<goals> <goals>
<goal>single</goal> <goal>single</goal>
</goals> </goals>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
<version>1.5</version> <version>1.5</version>
<configuration> <configuration>
<artifactSet> <artifactSet>
<includes> <includes>
<include>com.turt2live.metrics:MetricsExtension</include> <include>com.turt2live.metrics:MetricsExtension</include>
</includes> </includes>
</artifactSet> </artifactSet>
<relocations> <relocations>
<relocation> <relocation>
<pattern>com.turt2live.metrics</pattern> <pattern>com.turt2live.metrics</pattern>
<shadedPattern>com.gmail.nossr50.util.mcstats</shadedPattern> <shadedPattern>com.gmail.nossr50.metrics.mcstats</shadedPattern>
</relocation> </relocation>
</relocations> </relocations>
</configuration> </configuration>
<executions> <executions>
<execution> <execution>
<phase>package</phase> <phase>package</phase>
<goals> <goals>
<goal>shade</goal> <goal>shade</goal>
</goals> </goals>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
</plugins> </plugins>
<extensions> <extensions>
<extension> <extension>
<groupId>org.apache.maven.wagon</groupId> <groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-file</artifactId> <artifactId>wagon-file</artifactId>
<version>2.2</version> <version>2.2</version>
</extension> </extension>
</extensions> </extensions>
</build> </build>
<repositories> <repositories>
<repository> <repository>
<snapshots> <id>bukkit-repo</id>
<enabled>true</enabled> <url>http://repo.bukkit.org/content/groups/public/</url>
<updatePolicy>always</updatePolicy> </repository>
<checksumPolicy>fail</checksumPolicy> <repository>
</snapshots> <id>spout-repo</id>
<id>bukkit-repo</id> <url>http://nexus.spout.org/content/groups/public/</url>
<url>http://repo.bukkit.org/content/groups/public/</url> </repository>
</repository> <repository>
<repository> <id>Plugin MetricsExtension</id>
<snapshots> <url>http://repo.turt2live.com</url>
<enabled>true</enabled> </repository>
<updatePolicy>always</updatePolicy> </repositories>
<checksumPolicy>fail</checksumPolicy> <dependencies>
</snapshots> <dependency>
<id>spout-repo</id> <groupId>org.bukkit</groupId>
<url>http://nexus.spout.org/content/groups/public/</url> <artifactId>bukkit</artifactId>
</repository> <version>LATEST</version>
<repository> <type>jar</type>
<snapshots> <scope>compile</scope>
<enabled>true</enabled> </dependency>
<updatePolicy>always</updatePolicy> <dependency>
<checksumPolicy>fail</checksumPolicy> <groupId>org.getspout</groupId>
</snapshots> <artifactId>spoutplugin</artifactId>
<id>Plugin MetricsExtension</id> <version>LATEST</version>
<url>http://repo.turt2live.com</url> <type>jar</type>
</repository> <scope>compile</scope>
</repositories> </dependency>
<dependencies> <dependency>
<dependency> <groupId>junit</groupId>
<groupId>org.bukkit</groupId> <artifactId>junit-dep</artifactId>
<artifactId>bukkit</artifactId> <version>4.10</version>
<version>LATEST</version> <scope>test</scope>
<type>jar</type> </dependency>
<scope>compile</scope> <dependency>
</dependency> <groupId>com.turt2live.metrics</groupId>
<dependency> <artifactId>MetricsExtension</artifactId>
<groupId>org.getspout</groupId> <version>0.0.2-SNAPSHOT</version>
<artifactId>spoutplugin</artifactId> <type>jar</type>
<version>LATEST</version> <scope>compile</scope>
<type>jar</type> </dependency>
<scope>compile</scope> </dependencies>
</dependency> <distributionManagement>
<dependency> <repository>
<groupId>junit</groupId> <id>mcmmo-repo</id>
<artifactId>junit-dep</artifactId> <url>file:///var/lib/jenkins/repo</url>
<version>4.10</version> </repository>
<scope>test</scope> </distributionManagement>
</dependency> <properties>
<dependency> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<groupId>com.turt2live.metrics</groupId> </properties>
<artifactId>MetricsExtension</artifactId> </project>
<version>0.0.2-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies>
<distributionManagement>
<repository>
<id>mcmmo-repo</id>
<url>file:///var/lib/jenkins/repo</url>
</repository>
</distributionManagement>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

View File

@ -1,51 +1,51 @@
package com.gmail.nossr50.api; package com.gmail.nossr50.api;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.skills.utilities.AbilityType; import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.player.UserManager;
public final class AbilityAPI { public final class AbilityAPI {
private AbilityAPI() {} private AbilityAPI() {}
public static boolean berserkEnabled(Player player) { public static boolean berserkEnabled(Player player) {
return Users.getPlayer(player).getProfile().getAbilityMode(AbilityType.BERSERK); return UserManager.getPlayer(player).getAbilityMode(AbilityType.BERSERK);
} }
public static boolean gigaDrillBreakerEnabled(Player player) { public static boolean gigaDrillBreakerEnabled(Player player) {
return Users.getPlayer(player).getProfile().getAbilityMode(AbilityType.GIGA_DRILL_BREAKER); return UserManager.getPlayer(player).getAbilityMode(AbilityType.GIGA_DRILL_BREAKER);
} }
public static boolean greenTerraEnabled(Player player) { public static boolean greenTerraEnabled(Player player) {
return Users.getPlayer(player).getProfile().getAbilityMode(AbilityType.GREEN_TERRA); return UserManager.getPlayer(player).getAbilityMode(AbilityType.GREEN_TERRA);
} }
public static boolean serratedStrikesEnabled(Player player) { public static boolean serratedStrikesEnabled(Player player) {
return Users.getPlayer(player).getProfile().getAbilityMode(AbilityType.SERRATED_STRIKES); return UserManager.getPlayer(player).getAbilityMode(AbilityType.SERRATED_STRIKES);
} }
public static boolean skullSplitterEnabled(Player player) { public static boolean skullSplitterEnabled(Player player) {
return Users.getPlayer(player).getProfile().getAbilityMode(AbilityType.SKULL_SPLITTER); return UserManager.getPlayer(player).getAbilityMode(AbilityType.SKULL_SPLITTER);
} }
public static boolean superBreakerEnabled(Player player) { public static boolean superBreakerEnabled(Player player) {
return Users.getPlayer(player).getProfile().getAbilityMode(AbilityType.SUPER_BREAKER); return UserManager.getPlayer(player).getAbilityMode(AbilityType.SUPER_BREAKER);
} }
public static boolean treeFellerEnabled(Player player) { public static boolean treeFellerEnabled(Player player) {
return Users.getPlayer(player).getProfile().getAbilityMode(AbilityType.TREE_FELLER); return UserManager.getPlayer(player).getAbilityMode(AbilityType.TREE_FELLER);
} }
public static boolean isAnyAbilityEnabled(Player player) { public static boolean isAnyAbilityEnabled(Player player) {
PlayerProfile profile = Users.getPlayer(player).getProfile(); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
for (AbilityType ability : AbilityType.values()) { for (AbilityType ability : AbilityType.values()) {
if (profile.getAbilityMode(ability)) { if (mcMMOPlayer.getAbilityMode(ability)) {
return true; return true;
} }
} }
return false; return false;
} }
} }

View File

@ -5,7 +5,7 @@ import org.bukkit.plugin.Plugin;
import com.gmail.nossr50.chat.ChatManager; import com.gmail.nossr50.chat.ChatManager;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.player.UserManager;
public final class ChatAPI { public final class ChatAPI {
private ChatAPI() {} private ChatAPI() {}
@ -104,7 +104,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 Users.getPlayer(player).getPartyChatMode(); return UserManager.getPlayer(player).getPartyChatMode();
} }
/** /**
@ -114,7 +114,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 Users.getPlayer(playerName).getPartyChatMode(); return UserManager.getPlayer(playerName).getPartyChatMode();
} }
/** /**
@ -124,7 +124,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 Users.getPlayer(player).getAdminChatMode(); return UserManager.getPlayer(player).getAdminChatMode();
} }
/** /**
@ -134,6 +134,6 @@ 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 Users.getPlayer(playerName).getAdminChatMode(); return UserManager.getPlayer(playerName).getAdminChatMode();
} }
} }

View File

@ -1,335 +1,358 @@
package com.gmail.nossr50.api; package com.gmail.nossr50.api;
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.skills.utilities.SkillTools; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.skills.SkillUtils;
public final class ExperienceAPI { public final class ExperienceAPI {
private ExperienceAPI() {} private ExperienceAPI() {}
/** /**
* Check the XP of a player. This should be called after giving XP to process level-ups. * Adds raw XP to the player.
* * </br>
* @param player The player to check * This function is designed for API usage.
* @param skillType The skill to check *
* @deprecated Calling this function is no longer needed and should be avoided * @param player The player to add XP to
*/ * @param skillType The skill to add XP to
@Deprecated * @param XP The amount of XP to add
private static void checkXP(Player player, SkillType skillType) { * @deprecated Use {@link #addRawXP(Player, String, int)} instead
SkillTools.xpCheckSkill(skillType, player, Users.getProfile(player)); */
} @Deprecated
public static void addRawXP(Player player, SkillType skillType, int XP) {
/** UserManager.getPlayer(player).applyXpGain(skillType, XP);
* Adds raw XP to the player. }
* </br>
* This function is designed for API usage. /**
* * Adds raw XP to the player.
* @param player The player to add XP to * </br>
* @param skillType The skill to add XP to * This function is designed for API usage.
* @param XP The amount of XP to add *
* @deprecated Use {@link #addRawXP(Player, String, int)} instead * @param player The player to add XP to
*/ * @param skillType The skill to add XP to
@Deprecated * @param XP The amount of XP to add
public static void addRawXP(Player player, SkillType skillType, int XP) { */
Users.getPlayer(player).applyXpGain(skillType, XP); public static void addRawXP(Player player, String skillType, int XP) {
} UserManager.getPlayer(player).applyXpGain(SkillType.getSkill(skillType), XP);
}
/**
* Adds raw XP to the player. /**
* </br> * Adds XP to the player, calculates for XP Rate only.
* This function is designed for API usage. * </br>
* * This function is designed for API usage.
* @param player The player to add XP to *
* @param skillType The skill to add XP to * @param player The player to add XP to
* @param XP The amount of XP to add * @param skillType The skill to add XP to
*/ * @param XP The amount of XP to add
public static void addRawXP(Player player, String skillType, int XP) { * @deprecated Use {@link #addMultipliedXP(Player, String, int)} instead
Users.getPlayer(player).applyXpGain(SkillType.getSkill(skillType), XP); */
} @Deprecated
public static void addMultipliedXP(Player player, SkillType skillType, int XP) {
/** UserManager.getPlayer(player).applyXpGain(skillType, (int) (XP * Config.getInstance().getExperienceGainsGlobalMultiplier()));
* Adds XP to the player, calculates for XP Rate only. }
* </br>
* This function is designed for API usage. /**
* * Adds XP to the player, calculates for XP Rate only.
* @param player The player to add XP to * </br>
* @param skillType The skill to add XP to * This function is designed for API usage.
* @param XP The amount of XP to add *
* @deprecated Use {@link #addMultipliedXP(Player, String, int)} instead * @param player The player to add XP to
*/ * @param skillType The skill to add XP to
@Deprecated * @param XP The amount of XP to add
public static void addMultipliedXP(Player player, SkillType skillType, int XP) { */
Users.getPlayer(player).applyXpGain(skillType, (int) (XP * Config.getInstance().getExperienceGainsGlobalMultiplier())); public static void addMultipliedXP(Player player, String skillType, int XP) {
} UserManager.getPlayer(player).applyXpGain(SkillType.getSkill(skillType), (int) (XP * Config.getInstance().getExperienceGainsGlobalMultiplier()));
}
/**
* Adds XP to the player, calculates for XP Rate only. /**
* </br> * Adds XP to the player, calculates for XP Rate, skill modifiers and perks. May be shared with the party.
* This function is designed for API usage. * </br>
* * This function is designed for API usage.
* @param player The player to add XP to *
* @param skillType The skill to add XP to * @param player The player to add XP to
* @param XP The amount of XP to add * @param skillType The skill to add XP to
*/ * @param XP The amount of XP to add
public static void addMultipliedXP(Player player, String skillType, int XP) { * @deprecated Use {@link #addXP(Player, String, int)} instead
Users.getPlayer(player).applyXpGain(SkillType.getSkill(skillType), (int) (XP * Config.getInstance().getExperienceGainsGlobalMultiplier())); */
} @Deprecated
public static void addXP(Player player, SkillType skillType, int XP) {
/** UserManager.getPlayer(player).beginXpGain(skillType, XP);
* Adds XP to the player, calculates for XP Rate, skill modifiers and perks. May be shared with the party. }
* </br>
* This function is designed for API usage. /**
* * Adds XP to the player, calculates for XP Rate, skill modifiers and perks. May be shared with the party.
* @param player The player to add XP to * </br>
* @param skillType The skill to add XP to * This function is designed for API usage.
* @param XP The amount of XP to add *
* @deprecated Use {@link #addXP(Player, String, int)} instead * @param player The player to add XP to
*/ * @param skillType The skill to add XP to
@Deprecated * @param XP The amount of XP to add
public static void addXP(Player player, SkillType skillType, int XP) { */
Users.getPlayer(player).beginXpGain(skillType, XP); public static void addXP(Player player, String skillType, int XP) {
} UserManager.getPlayer(player).beginXpGain(SkillType.getSkill(skillType), XP);
}
/**
* Adds XP to the player, calculates for XP Rate, skill modifiers and perks. May be shared with the party. /**
* </br> * Get the amount of XP a player has in a specific skill.
* This function is designed for API usage. * </br>
* * This function is designed for API usage.
* @param player The player to add XP to *
* @param skillType The skill to add XP to * @param player The player to get XP for
* @param XP The amount of XP to add * @param skillType The skill to get XP for
*/ * @return the amount of XP in a given skill
public static void addXP(Player player, String skillType, int XP) { * @deprecated Use {@link #getXP(Player, String)} instead
Users.getPlayer(player).beginXpGain(SkillType.getSkill(skillType), XP); */
} @Deprecated
public static int getXP(Player player, SkillType skillType) {
/** return UserManager.getPlayer(player).getProfile().getSkillXpLevel(skillType);
* Get the amount of XP a player has in a specific skill. }
* </br>
* This function is designed for API usage. /**
* * Get the amount of XP a player has in a specific skill.
* @param player The player to get XP for * </br>
* @param skillType The skill to get XP for * This function is designed for API usage.
* @return the amount of XP in a given skill *
* @deprecated Use {@link #getXP(Player, String)} instead * @param player The player to get XP for
*/ * @param skillType The skill to get XP for
@Deprecated * @return the amount of XP in a given skill
public static int getXP(Player player, SkillType skillType) { */
return Users.getPlayer(player).getProfile().getSkillXpLevel(skillType); public static int getXP(Player player, String skillType) {
} return UserManager.getPlayer(player).getProfile().getSkillXpLevel(SkillType.getSkill(skillType));
}
/**
* Get the amount of XP a player has in a specific skill. /**
* </br> * Get the amount of XP left before leveling up.
* This function is designed for API usage. * </br>
* * This function is designed for API usage.
* @param player The player to get XP for *
* @param skillType The skill to get XP for * @param player The player to get the XP amount for
* @return the amount of XP in a given skill * @param skillType The skill to get the XP amount for
*/ * @return the amount of XP left before leveling up a specifc skill
public static int getXP(Player player, String skillType) { * @deprecated Use {@link #getXPToNextLevel(Player, String)} instead
return Users.getPlayer(player).getProfile().getSkillXpLevel(SkillType.getSkill(skillType)); */
} @Deprecated
public static int getXPToNextLevel(Player player, SkillType skillType) {
/** return UserManager.getPlayer(player).getProfile().getXpToLevel(skillType);
* Get the amount of XP left before leveling up. }
* </br>
* This function is designed for API usage. /**
* * Get the amount of XP left before leveling up.
* @param player The player to get the XP amount for * </br>
* @param skillType The skill to get the XP amount for * This function is designed for API usage.
* @return the amount of XP left before leveling up a specifc skill *
* @deprecated Use {@link #getXPToNextLevel(Player, String)} instead * @param player The player to get the XP amount for
*/ * @param skillType The skill to get the XP amount for
@Deprecated * @return the amount of XP left before leveling up a specifc skill
public static int getXPToNextLevel(Player player, SkillType skillType) { */
return Users.getPlayer(player).getProfile().getXpToLevel(skillType); public static int getXPToNextLevel(Player player, String skillType) {
} return UserManager.getPlayer(player).getProfile().getXpToLevel(SkillType.getSkill(skillType));
}
/**
* Get the amount of XP left before leveling up. /**
* </br> * Add levels to a skill.
* This function is designed for API usage. * </br>
* * This function is designed for API usage.
* @param player The player to get the XP amount for *
* @param skillType The skill to get the XP amount for * @param player The player to add levels to
* @return the amount of XP left before leveling up a specifc skill * @param skillType Type of skill to add levels to
*/ * @param levels Number of levels to add
public static int getXPToNextLevel(Player player, String skillType) { * @param notify Unused argument
return Users.getPlayer(player).getProfile().getXpToLevel(SkillType.getSkill(skillType)); * @deprecated Use addLevel(Player, SKillType, int) instead
} */
public static void addLevel(Player player, SkillType skillType, int levels, boolean notify) {
/** UserManager.getProfile(player).addLevels(skillType, levels);
* Add levels to a skill.
* </br> if (notify) {
* This function is designed for API usage. checkXP(player, skillType);
* }
* @param player The player to add levels to }
* @param skillType Type of skill to add levels to
* @param levels Number of levels to add /**
* @param notify Unused argument * Add levels to a skill.
* @deprecated Use addLevel(Player, SKillType, int) instead * </br>
*/ * This function is designed for API usage.
public static void addLevel(Player player, SkillType skillType, int levels, boolean notify) { *
Users.getProfile(player).addLevels(skillType, levels); * @param player The player to add levels to
* @param skillType Type of skill to add levels to
if (notify) { * @param levels Number of levels to add
checkXP(player, skillType); * @deprecated Use {@link #addLevel(Player, String, int)} instead
} */
} @Deprecated
public static void addLevel(Player player, SkillType skillType, int levels) {
/** UserManager.getPlayer(player).getProfile().addLevels(skillType, levels);
* Add levels to a skill. }
* </br>
* This function is designed for API usage. /**
* * Add levels to a skill.
* @param player The player to add levels to * </br>
* @param skillType Type of skill to add levels to * This function is designed for API usage.
* @param levels Number of levels to add *
* @deprecated Use {@link #addLevel(Player, String, int)} instead * @param player The player to add levels to
*/ * @param skillType Type of skill to add levels to
@Deprecated * @param levels Number of levels to add
public static void addLevel(Player player, SkillType skillType, int levels) { */
Users.getPlayer(player).getProfile().addLevels(skillType, levels); public static void addLevel(Player player, String skillType, int levels) {
} UserManager.getPlayer(player).getProfile().addLevels(SkillType.getSkill(skillType), levels);
}
/**
* Add levels to a skill. /**
* </br> * Get the level a player has in a specific skill.
* This function is designed for API usage. * </br>
* * This function is designed for API usage.
* @param player The player to add levels to *
* @param skillType Type of skill to add levels to * @param player The player to get the level for
* @param levels Number of levels to add * @param skillType The skill to get the level for
*/ * @return the level of a given skill
public static void addLevel(Player player, String skillType, int levels) { * @deprecated Use {@link #getLevel(Player, String)} instead
Users.getPlayer(player).getProfile().addLevels(SkillType.getSkill(skillType), levels); */
} @Deprecated
public static int getLevel(Player player, SkillType skillType) {
/** return UserManager.getPlayer(player).getProfile().getSkillLevel(skillType);
* Get the level a player has in a specific skill. }
* </br>
* This function is designed for API usage. /**
* * Get the level a player has in a specific skill.
* @param player The player to get the level for * </br>
* @param skillType The skill to get the level for * This function is designed for API usage.
* @return the level of a given skill *
* @deprecated Use {@link #getLevel(Player, String)} instead * @param player The player to get the level for
*/ * @param skillType The skill to get the level for
@Deprecated * @return the level of a given skill
public static int getLevel(Player player, SkillType skillType) { */
return Users.getPlayer(player).getProfile().getSkillLevel(skillType); public static int getLevel(Player player, String skillType) {
} return UserManager.getPlayer(player).getProfile().getSkillLevel(SkillType.getSkill(skillType));
}
/**
* Get the level a player has in a specific skill. /**
* </br> * Gets the power level of a player.
* This function is designed for API usage. * </br>
* * This function is designed for API usage.
* @param player The player to get the level for *
* @param skillType The skill to get the level for * @param player The player to get the power level for
* @return the level of a given skill * @return the power level of the player
*/ */
public static int getLevel(Player player, String skillType) { public static int getPowerLevel(Player player) {
return Users.getPlayer(player).getProfile().getSkillLevel(SkillType.getSkill(skillType)); return UserManager.getPlayer(player).getPowerLevel();
} }
/** /**
* Gets the power level of a player. * Get the level cap of a specific skill.
* </br> * </br>
* This function is designed for API usage. * This function is designed for API usage.
* *
* @param player The player to get the power level for * @param skillType The skill to get the level cap for
* @return the power level of the player * @return the level cap of a given skill
*/ */
public static int getPowerLevel(Player player) { public static int getLevelCap(String skillType) {
return Users.getPlayer(player).getPowerLevel(); return Config.getInstance().getLevelCap(SkillType.getSkill(skillType));
} }
/** /**
* Sets the level of a player in a specific skill type. * Get the power level cap.
* </br> * </br>
* This function is designed for API usage. * This function is designed for API usage.
* *
* @param player The player to set the level of * @return the power level cap of a given skill
* @param skillType The skill to set the level for */
* @param skillLevel The value to set the level to public static int getPowerLevelCap() {
* @deprecated Use {@link #setLevel(Player, String, int)} instead return Config.getInstance().getPowerLevelCap();
*/ }
@Deprecated
public static void setLevel(Player player, SkillType skillType, int skillLevel) { /**
Users.getPlayer(player).getProfile().modifySkill(skillType, skillLevel); * Sets the level of a player in a specific skill type.
} * </br>
* This function is designed for API usage.
/** *
* Sets the level of a player in a specific skill type. * @param player The player to set the level of
* </br> * @param skillType The skill to set the level for
* This function is designed for API usage. * @param skillLevel The value to set the level to
* * @deprecated Use {@link #setLevel(Player, String, int)} instead
* @param player The player to set the level of */
* @param skillType The skill to set the level for @Deprecated
* @param skillLevel The value to set the level to public static void setLevel(Player player, SkillType skillType, int skillLevel) {
*/ UserManager.getPlayer(player).getProfile().modifySkill(skillType, skillLevel);
public static void setLevel(Player player, String skillType, int skillLevel) { }
Users.getPlayer(player).getProfile().modifySkill(SkillType.getSkill(skillType), skillLevel);
} /**
* Sets the level of a player in a specific skill type.
/** * </br>
* Sets the XP of a player in a specific skill type. * This function is designed for API usage.
* </br> *
* This function is designed for API usage. * @param player The player to set the level of
* * @param skillType The skill to set the level for
* @param player The player to set the XP of * @param skillLevel The value to set the level to
* @param skillType The skill to set the XP for */
* @param newValue The value to set the XP to public static void setLevel(Player player, String skillType, int skillLevel) {
* @deprecated Use {@link #setXP(Player, String, int)} instead UserManager.getPlayer(player).getProfile().modifySkill(SkillType.getSkill(skillType), skillLevel);
*/ }
@Deprecated
public static void setXP(Player player, SkillType skillType, int newValue) { /**
Users.getPlayer(player).getProfile().setSkillXpLevel(skillType, newValue); * Sets the XP of a player in a specific skill type.
} * </br>
* This function is designed for API usage.
/** *
* Sets the XP of a player in a specific skill type. * @param player The player to set the XP of
* </br> * @param skillType The skill to set the XP for
* This function is designed for API usage. * @param newValue The value to set the XP to
* * @deprecated Use {@link #setXP(Player, String, int)} instead
* @param player The player to set the XP of */
* @param skillType The skill to set the XP for @Deprecated
* @param newValue The value to set the XP to public static void setXP(Player player, SkillType skillType, int newValue) {
*/ UserManager.getPlayer(player).getProfile().setSkillXpLevel(skillType, newValue);
public static void setXP(Player player, String skillType, int newValue) { }
Users.getPlayer(player).getProfile().setSkillXpLevel(SkillType.getSkill(skillType), newValue);
} /**
* Sets the XP of a player in a specific skill type.
/** * </br>
* Removes XP from a player in a specific skill type. * This function is designed for API usage.
* </br> *
* This function is designed for API usage. * @param player The player to set the XP of
* * @param skillType The skill to set the XP for
* @param player The player to change the XP of * @param newValue The value to set the XP to
* @param skillType The skill to change the XP for */
* @param xp The amount of XP to remove public static void setXP(Player player, String skillType, int newValue) {
* @deprecated Use {@link #removeXP(Player, String, int)} instead UserManager.getPlayer(player).getProfile().setSkillXpLevel(SkillType.getSkill(skillType), newValue);
*/ }
@Deprecated
public static void removeXP(Player player, SkillType skillType, int xp) { /**
Users.getPlayer(player).getProfile().removeXp(skillType, xp); * Removes XP from a player in a specific skill type.
} * </br>
* This function is designed for API usage.
/** *
* Removes XP from a player in a specific skill type. * @param player The player to change the XP of
* </br> * @param skillType The skill to change the XP for
* This function is designed for API usage. * @param xp The amount of XP to remove
* * @deprecated Use {@link #removeXP(Player, String, int)} instead
* @param player The player to change the XP of */
* @param skillType The skill to change the XP for @Deprecated
* @param xp The amount of XP to remove public static void removeXP(Player player, SkillType skillType, int xp) {
*/ UserManager.getPlayer(player).getProfile().removeXp(skillType, xp);
public static void removeXP(Player player, String skillType, int xp) { }
Users.getPlayer(player).getProfile().removeXp(SkillType.getSkill(skillType), xp);
} /**
} * Removes XP from a player in a specific skill type.
* </br>
* This function is designed for API usage.
*
* @param player The player to change the XP of
* @param skillType The skill to change the XP for
* @param xp The amount of XP to remove
*/
public static void removeXP(Player player, String skillType, int xp) {
UserManager.getPlayer(player).getProfile().removeXp(SkillType.getSkill(skillType), xp);
}
/**
* Check the XP of a player. This should be called after giving XP to process level-ups.
*
* @param player The player to check
* @param skillType The skill to check
* @deprecated Calling this function is no longer needed and should be avoided
*/
@Deprecated
private static void checkXP(Player player, SkillType skillType) {
SkillUtils.xpCheckSkill(skillType, player, UserManager.getProfile(player));
}
}

View File

@ -1,174 +1,174 @@
package com.gmail.nossr50.api; package com.gmail.nossr50.api;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.party.Party; import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.player.UserManager;
public final class PartyAPI { public final class PartyAPI {
private PartyAPI() {} private PartyAPI() {}
/** /**
* Get the name of the party a player is in. * Get the name of the party a player is in.
* </br> * </br>
* This function is designed for API usage. * This function is designed for API usage.
* *
* @param player The player to check the party name of * @param player The player to check the party name of
* @return the name of the player's party * @return the name of the player's party
*/ */
public static String getPartyName(Player player) { public static String getPartyName(Player player) {
return Users.getPlayer(player).getParty().getName(); return UserManager.getPlayer(player).getParty().getName();
} }
/** /**
* Checks if a player is in a party. * Checks if a player is in a party.
* </br> * </br>
* This function is designed for API usage. * This function is designed for API usage.
* *
* @param player The player to check * @param player The player to check
* @return true if the player is in a party, false otherwise * @return true if the player is in a party, false otherwise
*/ */
public static boolean inParty(Player player) { public static boolean inParty(Player player) {
return Users.getPlayer(player).inParty(); return UserManager.getPlayer(player).inParty();
} }
/** /**
* Check if two players are in the same party. * Check if two players are in the same party.
* </br> * </br>
* This function is designed for API usage. * This function is designed for API usage.
* *
* @param playera The first player to check * @param playera The first player to check
* @param playerb The second player to check * @param playerb The second player to check
* @return true if the two players are in the same party, false otherwise * @return true if the two players are in the same party, false otherwise
*/ */
public static boolean inSameParty(Player playera, Player playerb) { public static boolean inSameParty(Player playera, Player playerb) {
return PartyManager.inSameParty(playera, playerb); return PartyManager.inSameParty(playera, playerb);
} }
/** /**
* Get a list of all current parties. * Get a list of all current parties.
* </br> * </br>
* This function is designed for API usage. * This function is designed for API usage.
* *
* @return the list of parties. * @return the list of parties.
*/ */
public static List<Party> getParties() { public static List<Party> getParties() {
return PartyManager.getParties(); return PartyManager.getParties();
} }
/** /**
* Add a player to a party. * Add a player to a party.
* </br> * </br>
* This function is designed for API usage. * This function is designed for API usage.
* *
* @param player The player to add to the party * @param player The player to add to the party
* @param partyName The party to add the player to * @param partyName The party to add the player to
*/ */
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);
if (party == null) { if (party == null) {
party = new Party(); party = new Party();
party.setName(partyName); party.setName(partyName);
party.setLeader(player.getName()); party.setLeader(player.getName());
} }
PartyManager.addToParty(player, Users.getPlayer(player), party); PartyManager.addToParty(player, UserManager.getPlayer(player), party);
} }
/** /**
* Remove a player from a party. * Remove a player from a party.
* </br> * </br>
* This function is designed for API usage. * This function is designed for API usage.
* *
* @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(player, Users.getPlayer(player).getParty()); PartyManager.removeFromParty(player, UserManager.getPlayer(player).getParty());
} }
/** /**
* Get the leader of a party. * Get the leader of a party.
* </br> * </br>
* This function is designed for API usage. * This function is designed for API usage.
* *
* @param partyName The party name * @param partyName The party name
* @return the leader of the party * @return the leader of the party
*/ */
public static String getPartyLeader(String partyName) { public static String getPartyLeader(String partyName) {
return PartyManager.getPartyLeader(partyName); return PartyManager.getPartyLeader(partyName);
} }
/** /**
* Set the leader of a party. * Set the leader of a party.
* </br> * </br>
* This function is designed for API usage. * This function is designed for API usage.
* *
* @param partyName The name of the party to set the leader of * @param partyName The name of the party to set the leader of
* @param player The player to set as leader * @param player The player to set as leader
*/ */
public static void setPartyLeader(String partyName, String player) { public static void setPartyLeader(String partyName, String player) {
PartyManager.setPartyLeader(player, PartyManager.getParty(partyName)); PartyManager.setPartyLeader(player, PartyManager.getParty(partyName));
} }
/** /**
* Get a list of all players in this player's party. * Get a list of all players in this player's party.
* </br> * </br>
* This function is designed for API usage. * This function is designed for API usage.
* *
* @param player The player to check * @param player The player to check
* @return all the players in the player's party * @return all the players in the player's party
* @deprecated * @deprecated
*/ */
@Deprecated @Deprecated
public static List<String> getAllMembers(Player player) { public static List<String> getAllMembers(Player player) {
List<String> memberNames = new ArrayList<String>(); List<String> memberNames = new ArrayList<String>();
for (OfflinePlayer member : PartyManager.getAllMembers(player)) { for (OfflinePlayer member : PartyManager.getAllMembers(player)) {
memberNames.add(member.getName()); memberNames.add(member.getName());
} }
return memberNames; return memberNames;
} }
/** /**
* Get a list of all players in this player's party. * Get a list of all players in this player's party.
* </br> * </br>
* This function is designed for API usage. * This function is designed for API usage.
* *
* @param player The player to check * @param player The player to check
* @return all the players in the player's party * @return all the players in the player's party
*/ */
public static List<OfflinePlayer> getOnlineAndOfflineMembers(Player player) { public static List<OfflinePlayer> getOnlineAndOfflineMembers(Player player) {
return PartyManager.getAllMembers(player); return PartyManager.getAllMembers(player);
} }
/** /**
* Get a list of all online players in this party. * Get a list of all online players in this party.
* </br> * </br>
* This function is designed for API usage. * This function is designed for API usage.
* *
* @param partyName The party to check * @param partyName The party to check
* @return all online players in this party * @return all online players in this party
*/ */
public static List<Player> getOnlineMembers(String partyName) { public static List<Player> getOnlineMembers(String partyName) {
return PartyManager.getOnlineMembers(partyName); return PartyManager.getOnlineMembers(partyName);
} }
/** /**
* Get a list of all online players in this player's party. * Get a list of all online players in this player's party.
* </br> * </br>
* This function is designed for API usage. * This function is designed for API usage.
* *
* @param player The player to check * @param player The player to check
* @return all online players in the player's party * @return all online players in the player's party
*/ */
public static List<Player> getOnlineMembers(Player player) { public static List<Player> getOnlineMembers(Player player) {
return PartyManager.getOnlineMembers(player); return PartyManager.getOnlineMembers(player);
} }
} }

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

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

View File

@ -1,66 +1,78 @@
package com.gmail.nossr50.chat; package com.gmail.nossr50.chat;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
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.events.chat.McMMOAdminChatEvent; import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.events.chat.McMMOPartyChatEvent; import com.gmail.nossr50.events.chat.McMMOAdminChatEvent;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.events.chat.McMMOPartyChatEvent;
import com.gmail.nossr50.party.Party; import com.gmail.nossr50.locale.LocaleLoader;
public final class ChatManager { public final class ChatManager {
public ChatManager () {} public ChatManager () {}
public static void handleAdminChat(Plugin plugin, String playerName, String displayName, String message) { public static void handleAdminChat(Plugin plugin, String playerName, String displayName, String message, boolean isAsync) {
McMMOAdminChatEvent chatEvent = new McMMOAdminChatEvent(plugin, playerName, displayName, message); McMMOAdminChatEvent chatEvent = new McMMOAdminChatEvent(plugin, playerName, displayName, message, isAsync);
mcMMO.p.getServer().getPluginManager().callEvent(chatEvent); mcMMO.p.getServer().getPluginManager().callEvent(chatEvent);
if (chatEvent.isCancelled()) { if (chatEvent.isCancelled()) {
return; return;
} }
if(Config.getInstance().getAdminDisplayNames()) if (Config.getInstance().getAdminDisplayNames()) {
displayName = chatEvent.getDisplayName(); displayName = chatEvent.getDisplayName();
else }
displayName = chatEvent.getSender(); else {
displayName = chatEvent.getSender();
String adminMessage = chatEvent.getMessage(); }
mcMMO.p.getServer().broadcast(LocaleLoader.getString("Commands.AdminChat.Prefix", displayName) + adminMessage, "mcmmo.chat.adminchat"); String adminMessage = chatEvent.getMessage();
}
mcMMO.p.getServer().broadcast(LocaleLoader.getString("Commands.AdminChat.Prefix", displayName) + adminMessage, "mcmmo.chat.adminchat");
public static void handleAdminChat(Plugin plugin, String senderName, String message) { }
handleAdminChat(plugin, senderName, senderName, message);
} public static void handleAdminChat(Plugin plugin, String senderName, String message) {
handleAdminChat(plugin, senderName, senderName, message);
public static void handlePartyChat(Plugin plugin, Party party, String playerName, String displayName, String message) { }
String partyName = party.getName();
public static void handleAdminChat(Plugin plugin, String playerName, String displayName, String message) {
McMMOPartyChatEvent chatEvent = new McMMOPartyChatEvent(plugin, playerName, displayName, partyName, message); handleAdminChat(plugin, playerName, displayName, message, false);
mcMMO.p.getServer().getPluginManager().callEvent(chatEvent); }
if (chatEvent.isCancelled()) { public static void handlePartyChat(Plugin plugin, Party party, String playerName, String displayName, String message, boolean isAsync) {
return; String partyName = party.getName();
}
McMMOPartyChatEvent chatEvent = new McMMOPartyChatEvent(plugin, playerName, displayName, partyName, message, isAsync);
if(Config.getInstance().getPartyDisplayNames()) mcMMO.p.getServer().getPluginManager().callEvent(chatEvent);
displayName = chatEvent.getDisplayName();
else if (chatEvent.isCancelled()) {
displayName = chatEvent.getSender(); return;
}
String partyMessage = chatEvent.getMessage();
if (Config.getInstance().getPartyDisplayNames()) {
for (Player member : party.getOnlineMembers()) { displayName = chatEvent.getDisplayName();
member.sendMessage(LocaleLoader.getString("Commands.Party.Chat.Prefix", displayName) + partyMessage); }
} else {
displayName = chatEvent.getSender();
mcMMO.p.getLogger().info("[P](" + partyName + ")" + "<" + ChatColor.stripColor(displayName) + "> " + partyMessage); }
}
String partyMessage = chatEvent.getMessage();
public static void handlePartyChat(Plugin plugin, Party party, String senderName, String message) {
handlePartyChat(plugin, party, senderName, senderName, message); for (Player member : party.getOnlineMembers()) {
} member.sendMessage(LocaleLoader.getString("Commands.Party.Chat.Prefix", displayName) + partyMessage);
}
mcMMO.p.getLogger().info("[P](" + partyName + ")" + "<" + ChatColor.stripColor(displayName) + "> " + partyMessage);
}
public static void handlePartyChat(Plugin plugin, Party party, String senderName, String message) {
handlePartyChat(plugin, party, senderName, senderName, message);
}
public static void handlePartyChat(Plugin plugin, Party party, String playerName, String displayName, String message) {
handlePartyChat(plugin, party, playerName, displayName, message, false);
}
} }

View File

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

View File

@ -0,0 +1,79 @@
package com.gmail.nossr50.commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager;
public class McabilityCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
McMMOPlayer mcMMOPlayer;
switch (args.length) {
case 0:
if (!Permissions.mcability(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
mcMMOPlayer = UserManager.getPlayer((Player) sender);
if (mcMMOPlayer.getAbilityUse()) {
sender.sendMessage(LocaleLoader.getString("Commands.Ability.Off"));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.Ability.On"));
}
mcMMOPlayer.toggleAbilityUse();
return true;
case 1:
if (!Permissions.mcabilityOthers(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
mcMMOPlayer = UserManager.getPlayer(args[0]);
if (mcMMOPlayer == null) {
PlayerProfile playerProfile = new PlayerProfile(args[0], false);
if (!playerProfile.isLoaded()) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
sender.sendMessage(LocaleLoader.getString("Commands.Offline"));
return true;
}
Player player = mcMMOPlayer.getPlayer();
if (!player.isOnline()) {
sender.sendMessage(LocaleLoader.getString("Commands.Offline"));
return true;
}
if (mcMMOPlayer.getAbilityUse()) {
player.sendMessage(LocaleLoader.getString("Commands.Ability.Off"));
}
else {
player.sendMessage(LocaleLoader.getString("Commands.Ability.On"));
}
mcMMOPlayer.toggleAbilityUse();
return true;
default:
return false;
}
}
}

View File

@ -0,0 +1,88 @@
package com.gmail.nossr50.commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager;
public class McgodCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
McMMOPlayer mcMMOPlayer;
switch (args.length) {
case 0:
if (!Permissions.mcgod(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
if (!(sender instanceof Player)) {
return false;
}
mcMMOPlayer = UserManager.getPlayer((Player) sender);
if (mcMMOPlayer == null) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
if (mcMMOPlayer.getGodMode()) {
sender.sendMessage(LocaleLoader.getString("Commands.GodMode.Disabled"));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.GodMode.Enabled"));
}
mcMMOPlayer.toggleGodMode();
return true;
case 1:
if (!Permissions.mcgodOthers(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
mcMMOPlayer = UserManager.getPlayer(args[0]);
if (mcMMOPlayer == null) {
PlayerProfile playerProfile = new PlayerProfile(args[0], false);
if (!playerProfile.isLoaded()) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
sender.sendMessage(LocaleLoader.getString("Commands.Offline"));
return true;
}
Player player = mcMMOPlayer.getPlayer();
if (!player.isOnline()) {
sender.sendMessage(LocaleLoader.getString("Commands.Offline"));
return true;
}
if (mcMMOPlayer.getGodMode()) {
player.sendMessage(LocaleLoader.getString("Commands.GodMode.Disabled"));
}
else {
player.sendMessage(LocaleLoader.getString("Commands.GodMode.Enabled"));
}
mcMMOPlayer.toggleGodMode();
return true;
default:
return false;
}
}
}

View File

@ -1,114 +1,113 @@
package com.gmail.nossr50.commands.player; package com.gmail.nossr50.commands;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
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.getspout.spoutapi.player.SpoutPlayer; import org.getspout.spoutapi.player.SpoutPlayer;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.commands.party.PartySubcommandType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.party.commands.PartySubcommandType; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
public class McmmoCommand implements CommandExecutor { public class McmmoCommand implements CommandExecutor {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) {
switch (args.length) { case 0:
case 0: if (!Permissions.mcmmoDescription(sender)) {
if (!Permissions.mcmmoDescription(sender)) { sender.sendMessage(command.getPermissionMessage());
sender.sendMessage(command.getPermissionMessage()); return true;
return true; }
}
String description = LocaleLoader.getString("mcMMO.Description");
String description = LocaleLoader.getString("mcMMO.Description"); String[] mcSplit = description.split(",");
String[] mcSplit = description.split(","); sender.sendMessage(mcSplit);
sender.sendMessage(mcSplit);
if (Config.getInstance().getDonateMessageEnabled()) {
if (Config.getInstance().getDonateMessageEnabled()) { if (mcMMO.spoutEnabled && sender instanceof SpoutPlayer) {
if (mcMMO.spoutEnabled && sender instanceof SpoutPlayer) { SpoutPlayer spoutPlayer = (SpoutPlayer) sender;
SpoutPlayer spoutPlayer = (SpoutPlayer) sender; spoutPlayer.sendNotification(LocaleLoader.getString("Spout.Donate"), ChatColor.GREEN + "gjmcferrin@gmail.com", Material.DIAMOND);
spoutPlayer.sendNotification(LocaleLoader.getString("Spout.Donate"), ChatColor.GREEN + "gjmcferrin@gmail.com", Material.DIAMOND); }
}
sender.sendMessage(LocaleLoader.getString("MOTD.Donate"));
sender.sendMessage(LocaleLoader.getString("MOTD.Donate")); sender.sendMessage(ChatColor.GOLD + " - " + ChatColor.GREEN + "gjmcferrin@gmail.com" + ChatColor.GOLD + " Paypal");
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())); return true;
return true;
case 1:
case 1: if (args[0].equalsIgnoreCase("?") || args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("commands")) {
if (args[0].equalsIgnoreCase("?") || args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("commands")) { if (!Permissions.mcmmoHelp(sender)) {
if (!Permissions.mcmmoHelp(sender)) { sender.sendMessage(command.getPermissionMessage());
sender.sendMessage(command.getPermissionMessage()); return true;
return true; }
}
sender.sendMessage(LocaleLoader.getString("Commands.mcc.Header"));
sender.sendMessage(LocaleLoader.getString("Commands.mcc.Header")); displayPartyCommands(sender);
displayPartyCommands(sender); displayOtherCommands(sender);
displayOtherCommands(sender);
}
} return true;
return true;
default:
default: return false;
return false; }
} }
}
private void displayPartyCommands(CommandSender sender) {
private void displayPartyCommands(CommandSender sender) { if (Permissions.party(sender)) {
if (Permissions.party(sender)) { sender.sendMessage(LocaleLoader.getString("Commands.Party.Commands"));
sender.sendMessage(LocaleLoader.getString("Commands.Party.Commands")); sender.sendMessage("/party create <" + LocaleLoader.getString("Commands.Usage.PartyName") + "> " + LocaleLoader.getString("Commands.Party1"));
sender.sendMessage("/party create <" + LocaleLoader.getString("Commands.Usage.PartyName") + "> " + LocaleLoader.getString("Commands.Party1")); sender.sendMessage("/party join <" + LocaleLoader.getString("Commands.Usage.Player") + "> " + LocaleLoader.getString("Commands.Party2"));
sender.sendMessage("/party join <" + LocaleLoader.getString("Commands.Usage.Player") + "> " + LocaleLoader.getString("Commands.Party2")); sender.sendMessage("/party quit " + LocaleLoader.getString("Commands.Party.Quit"));
sender.sendMessage("/party quit " + LocaleLoader.getString("Commands.Party.Quit"));
if (Permissions.partyChat(sender)) {
if (Permissions.partyChat(sender)) { sender.sendMessage("/party chat " + LocaleLoader.getString("Commands.Party.Toggle"));
sender.sendMessage("/party chat " + LocaleLoader.getString("Commands.Party.Toggle")); }
}
sender.sendMessage("/party invite <" + LocaleLoader.getString("Commands.Usage.Player") + "> " + LocaleLoader.getString("Commands.Party.Invite"));
sender.sendMessage("/party invite <" + LocaleLoader.getString("Commands.Usage.Player") + "> " + LocaleLoader.getString("Commands.Party.Invite")); sender.sendMessage("/party accept " + LocaleLoader.getString("Commands.Party.Accept"));
sender.sendMessage("/party accept " + LocaleLoader.getString("Commands.Party.Accept"));
if (Permissions.partySubcommand(sender, PartySubcommandType.TELEPORT)) {
if (Permissions.partySubcommand(sender, PartySubcommandType.TELEPORT)) { sender.sendMessage("/party teleport " + LocaleLoader.getString("Commands.Party.Teleport"));
sender.sendMessage("/party teleport " + LocaleLoader.getString("Commands.Party.Teleport")); }
} }
} }
}
private void displayOtherCommands(CommandSender sender) {
private void displayOtherCommands(CommandSender sender) { sender.sendMessage(LocaleLoader.getString("Commands.Other"));
sender.sendMessage(LocaleLoader.getString("Commands.Other")); sender.sendMessage("/mcstats " + LocaleLoader.getString("Commands.Stats"));
sender.sendMessage("/mcstats " + LocaleLoader.getString("Commands.Stats")); sender.sendMessage("/mctop " + LocaleLoader.getString("Commands.Leaderboards"));
sender.sendMessage("/mctop " + LocaleLoader.getString("Commands.Leaderboards"));
if (Permissions.skillreset(sender)) {
if (Permissions.skillreset(sender)) { sender.sendMessage("/skillreset <skill|all> " + LocaleLoader.getString("Commands.Reset"));
sender.sendMessage("/skillreset <skill|all> " + LocaleLoader.getString("Commands.Reset")); }
}
if (Permissions.mcability(sender)) {
if (Permissions.mcability(sender)) { sender.sendMessage("/mcability " + LocaleLoader.getString("Commands.ToggleAbility"));
sender.sendMessage("/mcability " + LocaleLoader.getString("Commands.ToggleAbility")); }
}
if (Permissions.adminChat(sender)) {
if (Permissions.adminChat(sender)) { sender.sendMessage("/adminchat " + LocaleLoader.getString("Commands.AdminToggle"));
sender.sendMessage("/adminchat " + LocaleLoader.getString("Commands.AdminToggle")); }
}
if (Permissions.inspect(sender)) {
if (Permissions.inspect(sender)) { sender.sendMessage("/inspect " + LocaleLoader.getString("Commands.Inspect"));
sender.sendMessage("/inspect " + LocaleLoader.getString("Commands.Inspect")); }
}
if (Permissions.mmoedit(sender)) {
if (Permissions.mmoedit(sender)) { sender.sendMessage("/mmoedit " + LocaleLoader.getString("Commands.mmoedit"));
sender.sendMessage("/mmoedit " + LocaleLoader.getString("Commands.mmoedit")); }
}
if (Permissions.mcgod(sender)) {
if (Permissions.mcgod(sender)) { sender.sendMessage("/mcgod " + LocaleLoader.getString("Commands.mcgod"));
sender.sendMessage("/mcgod " + LocaleLoader.getString("Commands.mcgod")); }
}
sender.sendMessage(LocaleLoader.getString("Commands.SkillInfo"));
sender.sendMessage(LocaleLoader.getString("Commands.SkillInfo")); }
} }
}

View File

@ -0,0 +1,33 @@
package com.gmail.nossr50.commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.player.UserManager;
public class McnotifyCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) {
case 0:
McMMOPlayer mcMMOPlayer = UserManager.getPlayer((Player) sender);
if (mcMMOPlayer.useChatNotifications()) {
sender.sendMessage(LocaleLoader.getString("Commands.Notifications.Off"));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.Notifications.On"));
}
mcMMOPlayer.toggleChatNotifications();
return true;
default:
return false;
}
}
}

View File

@ -0,0 +1,80 @@
package com.gmail.nossr50.commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager;
public class McrefreshCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
McMMOPlayer mcMMOPlayer;
switch (args.length) {
case 0:
if (!Permissions.mcrefresh(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
if (!(sender instanceof Player)) {
return false;
}
mcMMOPlayer = UserManager.getPlayer(sender.getName());
mcMMOPlayer.setRecentlyHurt(0);
mcMMOPlayer.getProfile().resetCooldowns();
mcMMOPlayer.resetToolPrepMode();
mcMMOPlayer.resetAbilityMode();
sender.sendMessage(LocaleLoader.getString("Ability.Generic.Refresh"));
return true;
case 1:
if (!Permissions.mcrefreshOthers(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
mcMMOPlayer = UserManager.getPlayer(args[0]);
if (mcMMOPlayer == null) {
PlayerProfile playerProfile = new PlayerProfile(args[0], false);
if (!playerProfile.isLoaded()) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
sender.sendMessage(LocaleLoader.getString("Commands.Offline"));
return true;
}
Player player = mcMMOPlayer.getPlayer();
if (!player.isOnline()) {
sender.sendMessage(LocaleLoader.getString("Commands.Offline"));
return true;
}
mcMMOPlayer.setRecentlyHurt(0);
mcMMOPlayer.getProfile().resetCooldowns();
mcMMOPlayer.resetToolPrepMode();
mcMMOPlayer.resetAbilityMode();
player.sendMessage(LocaleLoader.getString("Ability.Generic.Refresh"));
sender.sendMessage(LocaleLoader.getString("Commands.mcrefresh.Success", args[0]));
return true;
default:
return false;
}
}
}

View File

@ -0,0 +1,69 @@
package com.gmail.nossr50.commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.StringUtils;
public class XprateCommand implements CommandExecutor {
private static double originalRate = Config.getInstance().getExperienceGainsGlobalMultiplier();
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) {
case 1:
if (!args[0].equalsIgnoreCase("reset")) {
return false;
}
if (!Permissions.xprateReset(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
if (mcMMO.p.isXPEventEnabled()) {
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Commands.xprate.over"));
mcMMO.p.toggleXpEventEnabled();
}
Config.getInstance().setExperienceGainsGlobalMultiplier(originalRate);
return true;
case 2:
if (!StringUtils.isInt(args[0])) {
return false;
}
if (!Permissions.xprateSet(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
if (!args[1].equalsIgnoreCase("true") && !args[1].equalsIgnoreCase("false")) {
return false;
}
mcMMO.p.setXPEventEnabled(Boolean.valueOf(args[1]));
int newXpRate = Integer.parseInt(args[0]);
Config.getInstance().setExperienceGainsGlobalMultiplier(newXpRate);
if (mcMMO.p.isXPEventEnabled()) {
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Commands.xprate.started.0"));
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Commands.xprate.started.1", newXpRate));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.xprate.modified", newXpRate));
}
return true;
default:
return false;
}
}
}

View File

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

View File

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

View File

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

View File

@ -1,89 +0,0 @@
package com.gmail.nossr50.commands.admin;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users;
public class McgodCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
PlayerProfile profile;
switch (args.length) {
case 0:
if (!Permissions.mcgod(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
if (!(sender instanceof Player)) {
return false;
}
profile = Users.getPlayer((Player) sender).getProfile();
if (profile == null) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
if (profile.getGodMode()) {
sender.sendMessage(LocaleLoader.getString("Commands.GodMode.Disabled"));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.GodMode.Enabled"));
}
profile.toggleGodMode();
return true;
case 1:
if (!Permissions.mcgodOthers(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
McMMOPlayer mcMMOPlayer = Users.getPlayer(args[0]);
if (mcMMOPlayer == null) {
profile = new PlayerProfile(args[0], false);
if (!profile.isLoaded()) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
sender.sendMessage(LocaleLoader.getString("Commands.Offline"));
return true;
}
profile = mcMMOPlayer.getProfile();
Player player = mcMMOPlayer.getPlayer();
if (!player.isOnline()) {
sender.sendMessage(LocaleLoader.getString("Commands.Offline"));
return true;
}
if (profile.getGodMode()) {
player.sendMessage(LocaleLoader.getString("Commands.GodMode.Disabled"));
}
else {
player.sendMessage(LocaleLoader.getString("Commands.GodMode.Enabled"));
}
profile.toggleGodMode();
return true;
default:
return false;
}
}
}

View File

@ -1,80 +0,0 @@
package com.gmail.nossr50.commands.admin;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users;
public class McrefreshCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
PlayerProfile profile;
switch (args.length) {
case 0:
if (!Permissions.mcrefresh(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
if (!(sender instanceof Player)) {
return false;
}
profile = Users.getPlayer(sender.getName()).getProfile();
profile.setRecentlyHurt(0);
profile.resetCooldowns();
profile.resetToolPrepMode();
profile.resetAbilityMode();
sender.sendMessage(LocaleLoader.getString("Ability.Generic.Refresh"));
return true;
case 1:
if (!Permissions.mcrefreshOthers(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
McMMOPlayer mcMMOPlayer = Users.getPlayer(args[0]);
if (mcMMOPlayer == null) {
profile = new PlayerProfile(args[0], false);
if (!profile.isLoaded()) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
sender.sendMessage(LocaleLoader.getString("Commands.Offline"));
return true;
}
profile = mcMMOPlayer.getProfile();
Player player = mcMMOPlayer.getPlayer();
if (!player.isOnline()) {
sender.sendMessage(LocaleLoader.getString("Commands.Offline"));
return true;
}
profile.setRecentlyHurt(0);
profile.resetCooldowns();
profile.resetToolPrepMode();
profile.resetAbilityMode();
player.sendMessage(LocaleLoader.getString("Ability.Generic.Refresh"));
sender.sendMessage(LocaleLoader.getString("Commands.mcrefresh.Success", args[0]));
return true;
default:
return false;
}
}
}

View File

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

View File

@ -1,169 +0,0 @@
package com.gmail.nossr50.commands.admin;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users;
public class SkillresetCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
PlayerProfile profile;
boolean allSkills = false;
SkillType skill = null;
String skillName = "";
switch (args.length) {
case 1:
if (!Permissions.skillreset(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
if (!(sender instanceof Player)) {
return false;
}
if (args[0].equalsIgnoreCase("all")) {
allSkills = true;
}
else if (!SkillTools.isSkill(args[0])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true;
}
profile = Users.getPlayer((Player) sender).getProfile();
if (allSkills) {
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
if (!Permissions.skillreset(sender, skillType)) {
sender.sendMessage(command.getPermissionMessage());
continue;
}
profile.modifySkill(skillType, 0);
}
sender.sendMessage(LocaleLoader.getString("Commands.Reset.All"));
}
else {
skill = SkillType.getSkill(args[0]);
skillName = SkillTools.getSkillName(skill);
if (!Permissions.skillreset(sender, skill)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
profile.modifySkill(skill, 0);
sender.sendMessage(LocaleLoader.getString("Commands.Reset.Single", skillName));
}
return true;
case 2:
if (!Permissions.skillresetOthers(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
if (args[1].equalsIgnoreCase("all")) {
allSkills = true;
}
else if (!SkillTools.isSkill(args[1])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true;
}
if (!allSkills) {
skill = SkillType.getSkill(args[1]);
skillName = SkillTools.getSkillName(skill);
if (!Permissions.skillresetOthers(sender, skill)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
}
McMMOPlayer mcMMOPlayer = Users.getPlayer(args[0]);
// If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
if (mcMMOPlayer == null) {
profile = new PlayerProfile(args[0], false);
if (!profile.isLoaded()) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
if (allSkills) {
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
if (!Permissions.skillresetOthers(sender, skill)) {
sender.sendMessage(command.getPermissionMessage());
continue;
}
profile.modifySkill(skillType, 0);
}
}
else {
profile.modifySkill(skill, 0);
}
profile.save(); // Since this is a temporary profile, we save it here.
}
else {
profile = mcMMOPlayer.getProfile();
if (allSkills) {
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
if (!Permissions.skillresetOthers(sender, skill)) {
sender.sendMessage(command.getPermissionMessage());
continue;
}
profile.modifySkill(skillType, 0);
}
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.Reset.All"));
}
else {
profile.modifySkill(skill, 0);
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.Reset.Single", skillName));
}
}
if (allSkills) {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", args[0]));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.2", skillName, args[0]));
}
return true;
default:
return false;
}
}
}

View File

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

View File

@ -1,69 +0,0 @@
package com.gmail.nossr50.commands.admin;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.StringUtils;
public class XprateCommand implements CommandExecutor {
private static double originalRate = Config.getInstance().getExperienceGainsGlobalMultiplier();
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) {
case 1:
if (!args[0].equalsIgnoreCase("reset")) {
return false;
}
if (!Permissions.xprateReset(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
if (mcMMO.p.isXPEventEnabled()) {
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Commands.xprate.over"));
mcMMO.p.toggleXpEventEnabled();
}
Config.getInstance().setExperienceGainsGlobalMultiplier(originalRate);
return true;
case 2:
if (!StringUtils.isInt(args[0])) {
return false;
}
if (!Permissions.xprateSet(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
if (!args[1].equalsIgnoreCase("true") && !args[1].equalsIgnoreCase("false")) {
return false;
}
mcMMO.p.setXPEventEnabled(Boolean.valueOf(args[1]));
int newXpRate = Integer.parseInt(args[0]);
Config.getInstance().setExperienceGainsGlobalMultiplier(newXpRate);
if (mcMMO.p.isXPEventEnabled()) {
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Commands.xprate.started.0"));
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Commands.xprate.started.1", newXpRate));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.xprate.modified", newXpRate));
}
return true;
default:
return false;
}
}
}

View File

@ -1,28 +1,26 @@
package com.gmail.nossr50.chat.commands; 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.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.chat.ChatManager; import com.gmail.nossr50.chat.ChatManager;
import com.gmail.nossr50.chat.ChatMode; import com.gmail.nossr50.chat.ChatMode;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
public class AdminChatCommand extends ChatCommand { public class AdminChatCommand extends ChatCommand {
public AdminChatCommand() { public AdminChatCommand() {
super(ChatMode.ADMIN); super(ChatMode.ADMIN);
} }
@Override @Override
protected void handleChatSending(CommandSender sender, String[] args) { protected void handleChatSending(CommandSender sender, String[] args) {
String message = buildChatMessage(args, 0); if (sender instanceof Player) {
Player player = (Player) sender;
if (sender instanceof Player) { ChatManager.handleAdminChat(mcMMO.p, player.getName(), player.getDisplayName(), buildChatMessage(args, 0));
Player player = (Player) sender; }
ChatManager.handleAdminChat(mcMMO.p, player.getName(), player.getDisplayName(), message); else {
} ChatManager.handleAdminChat(mcMMO.p, LocaleLoader.getString("Commands.Chat.Console"), buildChatMessage(args, 0));
else { }
ChatManager.handleAdminChat(mcMMO.p, LocaleLoader.getString("Commands.Chat.Console"), message); }
} }
}
}

View File

@ -1,88 +1,89 @@
package com.gmail.nossr50.chat.commands; package com.gmail.nossr50.commands.chat;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.chat.ChatMode; import com.gmail.nossr50.chat.ChatMode;
import com.gmail.nossr50.datatypes.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.player.UserManager;
public abstract class ChatCommand implements CommandExecutor { public abstract class ChatCommand implements CommandExecutor {
protected McMMOPlayer mcMMOPlayer; protected McMMOPlayer mcMMOPlayer;
protected ChatMode chatMode; protected ChatMode chatMode;
public ChatCommand (ChatMode chatMode) { public ChatCommand(ChatMode chatMode) {
this.chatMode = chatMode; this.chatMode = chatMode;
} }
@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 (!(sender instanceof Player)) { if (!(sender instanceof Player)) {
return false; return false;
} }
mcMMOPlayer = Users.getPlayer((Player) sender); mcMMOPlayer = UserManager.getPlayer((Player) sender);
if (chatMode.isEnabled(mcMMOPlayer)) { if (chatMode.isEnabled(mcMMOPlayer)) {
disableChatMode(sender); disableChatMode(sender);
} }
else { else {
enableChatMode(sender); enableChatMode(sender);
} }
return true; return true;
default: case 1:
if (args.length == 1) { if (args[0].equalsIgnoreCase("on")) {
if (args[0].equalsIgnoreCase("on")) { if (!(sender instanceof Player)) {
if (!(sender instanceof Player)) { return false;
return false; }
}
enableChatMode(sender);
enableChatMode(sender); return true;
return true; }
}
if (args[0].equalsIgnoreCase("off")) {
if (args[0].equalsIgnoreCase("off")) { if (!(sender instanceof Player)) {
if (!(sender instanceof Player)) { return false;
return false; }
}
disableChatMode(sender);
disableChatMode(sender); return true;
return true; }
}
} // Fallthrough
handleChatSending(sender, args); default:
return true; handleChatSending(sender, args);
} return true;
} }
}
private void enableChatMode(CommandSender sender) {
chatMode.enable(mcMMOPlayer); protected String buildChatMessage(String[] args, int index) {
sender.sendMessage(chatMode.getEnabledMessage()); StringBuilder builder = new StringBuilder();
} builder.append(args[index]);
private void disableChatMode(CommandSender sender) { for (int i = index + 1; i < args.length; i++) {
chatMode.disable(mcMMOPlayer); builder.append(" ");
sender.sendMessage(chatMode.getDisabledMessage()); builder.append(args[i]);
} }
protected String buildChatMessage(String[] args, int index) { return builder.toString();
StringBuilder builder = new StringBuilder(); }
builder.append(args[index]);
protected abstract void handleChatSending(CommandSender sender, String[] args);
for (int i = index + 1; i < args.length; i++) {
builder.append(" "); private void enableChatMode(CommandSender sender) {
builder.append(args[i]); chatMode.enable(mcMMOPlayer);
} sender.sendMessage(chatMode.getEnabledMessage());
}
return builder.toString();
} private void disableChatMode(CommandSender sender) {
chatMode.disable(mcMMOPlayer);
protected abstract void handleChatSending(CommandSender sender, String[] args); sender.sendMessage(chatMode.getDisabledMessage());
} }
}

View File

@ -1,48 +1,48 @@
package com.gmail.nossr50.chat.commands; 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.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.chat.ChatManager; import com.gmail.nossr50.chat.ChatManager;
import com.gmail.nossr50.chat.ChatMode; import com.gmail.nossr50.chat.ChatMode;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.party.Party; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.player.UserManager;
public class PartyChatCommand extends ChatCommand { public class PartyChatCommand extends ChatCommand {
public PartyChatCommand() { public PartyChatCommand() {
super(ChatMode.PARTY); super(ChatMode.PARTY);
} }
@Override @Override
protected void handleChatSending(CommandSender sender, String[] args) { protected void handleChatSending(CommandSender sender, String[] args) {
if (sender instanceof Player) { if (sender instanceof Player) {
Player player = (Player) sender; Player player = (Player) sender;
Party party = Users.getPlayer(player).getParty(); Party party = UserManager.getPlayer(player).getParty();
if (party == null) { if (party == null) {
sender.sendMessage(LocaleLoader.getString("Commands.Party.None")); sender.sendMessage(LocaleLoader.getString("Commands.Party.None"));
return; return;
} }
ChatManager.handlePartyChat(mcMMO.p, party, player.getName(), player.getDisplayName(), buildChatMessage(args, 0)); ChatManager.handlePartyChat(mcMMO.p, party, player.getName(), player.getDisplayName(), buildChatMessage(args, 0));
} }
else { else {
if (args.length < 2) { if (args.length < 2) {
sender.sendMessage(LocaleLoader.getString("Party.Specify")); sender.sendMessage(LocaleLoader.getString("Party.Specify"));
return; return;
} }
Party party = PartyManager.getParty(args[0]); Party party = PartyManager.getParty(args[0]);
if (party == null) { if (party == null) {
sender.sendMessage(LocaleLoader.getString("Party.InvalidName")); sender.sendMessage(LocaleLoader.getString("Party.InvalidName"));
return; return;
} }
ChatManager.handlePartyChat(mcMMO.p, party, LocaleLoader.getString("Commands.Chat.Console"), buildChatMessage(args, 1)); ChatManager.handlePartyChat(mcMMO.p, party, LocaleLoader.getString("Commands.Chat.Console"), buildChatMessage(args, 1));
} }
} }
} }

View File

@ -0,0 +1,45 @@
package com.gmail.nossr50.commands.database;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.database.DatabaseManager;
import com.gmail.nossr50.database.LeaderboardManager;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
public class McpurgeCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!Permissions.mcpurge(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
switch (args.length) {
case 0:
if (Config.getInstance().getUseMySQL()) {
DatabaseManager.purgePowerlessSQL();
if (Config.getInstance().getOldUsersCutoff() != -1) {
DatabaseManager.purgeOldSQL();
}
}
else {
LeaderboardManager.purgePowerlessFlatfile();
if (Config.getInstance().getOldUsersCutoff() != -1) {
LeaderboardManager.purgeOldFlatfile();
}
}
sender.sendMessage(LocaleLoader.getString("Commands.mcpurge.Success"));
return true;
default:
return false;
}
}
}

View File

@ -0,0 +1,51 @@
package com.gmail.nossr50.commands.database;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.database.DatabaseManager;
import com.gmail.nossr50.database.LeaderboardManager;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
public class McremoveCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!Permissions.mcremove(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
switch (args.length) {
case 1:
/* MySQL */
if (Config.getInstance().getUseMySQL()) {
String tablePrefix = Config.getInstance().getMySQLTablePrefix();
if (DatabaseManager.update("DELETE FROM " + tablePrefix + "users WHERE " + tablePrefix + "users.user = '" + args[0] + "'") != 0) {
DatabaseManager.profileCleanup(args[0]);
sender.sendMessage(LocaleLoader.getString("Commands.mcremove.Success", args[0]));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
}
}
else {
if (LeaderboardManager.removeFlatFileUser(args[0])) {
DatabaseManager.profileCleanup(args[0]);
sender.sendMessage(LocaleLoader.getString("Commands.mcremove.Success", args[0]));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
}
}
return true;
default:
return false;
}
}
}

View File

@ -0,0 +1,51 @@
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.config.Config;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.runnables.database.SQLConversionTask;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager;
public class MmoupdateCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!Permissions.mmoupdate(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
switch (args.length) {
case 0:
sender.sendMessage(LocaleLoader.getString("Commands.mmoupdate.Start"));
UserManager.clearAll();
convertToMySQL();
for (Player player : mcMMO.p.getServer().getOnlinePlayers()) {
UserManager.addUser(player);
}
sender.sendMessage(LocaleLoader.getString("Commands.mmoupdate.Finish"));
return true;
default:
return false;
}
}
/**
* Convert FlatFile data to MySQL data.
*/
private void convertToMySQL() {
if (!Config.getInstance().getUseMySQL()) {
return;
}
mcMMO.p.getServer().getScheduler().runTaskLaterAsynchronously(mcMMO.p, new SQLConversionTask(), 1);
}
}

View File

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

View File

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

View File

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

View File

@ -0,0 +1,169 @@
package com.gmail.nossr50.commands.experience;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.skills.SkillUtils;
public class SkillresetCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
PlayerProfile profile;
boolean allSkills = false;
SkillType skill = null;
String skillName = "";
switch (args.length) {
case 1:
if (!Permissions.skillreset(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
if (!(sender instanceof Player)) {
return false;
}
if (args[0].equalsIgnoreCase("all")) {
allSkills = true;
}
else if (!SkillUtils.isSkill(args[0])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true;
}
profile = UserManager.getPlayer((Player) sender).getProfile();
if (allSkills) {
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
if (!Permissions.skillreset(sender, skillType)) {
sender.sendMessage(command.getPermissionMessage());
continue;
}
profile.modifySkill(skillType, 0);
}
sender.sendMessage(LocaleLoader.getString("Commands.Reset.All"));
}
else {
skill = SkillType.getSkill(args[0]);
skillName = SkillUtils.getSkillName(skill);
if (!Permissions.skillreset(sender, skill)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
profile.modifySkill(skill, 0);
sender.sendMessage(LocaleLoader.getString("Commands.Reset.Single", skillName));
}
return true;
case 2:
if (!Permissions.skillresetOthers(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
if (args[1].equalsIgnoreCase("all")) {
allSkills = true;
}
else if (!SkillUtils.isSkill(args[1])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true;
}
if (!allSkills) {
skill = SkillType.getSkill(args[1]);
skillName = SkillUtils.getSkillName(skill);
if (!Permissions.skillresetOthers(sender, skill)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
}
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(args[0]);
// If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
if (mcMMOPlayer == null) {
profile = new PlayerProfile(args[0], false);
if (!profile.isLoaded()) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
if (allSkills) {
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
if (!Permissions.skillresetOthers(sender, skill)) {
sender.sendMessage(command.getPermissionMessage());
continue;
}
profile.modifySkill(skillType, 0);
}
}
else {
profile.modifySkill(skill, 0);
}
profile.save(); // Since this is a temporary profile, we save it here.
}
else {
profile = mcMMOPlayer.getProfile();
if (allSkills) {
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
if (!Permissions.skillresetOthers(sender, skillType)) {
sender.sendMessage(command.getPermissionMessage());
continue;
}
profile.modifySkill(skillType, 0);
}
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.Reset.All"));
}
else {
profile.modifySkill(skill, 0);
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.Reset.Single", skillName));
}
}
if (allSkills) {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", args[0]));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.2", skillName, args[0]));
}
return true;
default:
return false;
}
}
}

View File

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

View File

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

View File

@ -0,0 +1,42 @@
package com.gmail.nossr50.commands.party;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.player.UserManager;
public class PartyAcceptCommand implements CommandExecutor {
private McMMOPlayer mcMMOPlayer;
private Player player;
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) {
case 1:
player = (Player) sender;
mcMMOPlayer = UserManager.getPlayer(player);
if (!mcMMOPlayer.hasPartyInvite()) {
sender.sendMessage(LocaleLoader.getString("mcMMO.NoInvites"));
return true;
}
// Changing parties
if (!PartyManager.changeOrJoinParty(mcMMOPlayer, player, mcMMOPlayer.getParty(), mcMMOPlayer.getPartyInvite().getName())) {
return true;
}
PartyManager.joinInvitedParty(player, mcMMOPlayer);
return true;
default:
sender.sendMessage(LocaleLoader.getString("Commands.Usage.1", "party", "accept"));
return true;
}
}
}

View File

@ -0,0 +1,34 @@
package com.gmail.nossr50.commands.party;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.player.UserManager;
public class PartyChangeOwnerCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) {
case 2:
Party playerParty = UserManager.getPlayer((Player) sender).getParty();
if (!playerParty.getMembers().contains(mcMMO.p.getServer().getOfflinePlayer(args[1]))) {
sender.sendMessage(LocaleLoader.getString("Party.NotInYourParty", args[1]));
return true;
}
PartyManager.setPartyLeader(args[1], playerParty);
return true;
default:
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "owner", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">"));
return true;
}
}
}

View File

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

View File

@ -0,0 +1,154 @@
package com.gmail.nossr50.commands.party;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.commands.chat.PartyChatCommand;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager;
public class PartyCommand implements CommandExecutor {
private McMMOPlayer mcMMOPlayer;
private Player player;
private CommandExecutor partyJoinCommand = new PartyJoinCommand();
private CommandExecutor partyAcceptCommand = new PartyAcceptCommand();
private CommandExecutor partyCreateCommand = new PartyCreateCommand();
private CommandExecutor partyQuitCommand = new PartyQuitCommand();
private CommandExecutor partyExpShareCommand = new PartyExpShareCommand();
private CommandExecutor partyItemShareCommand = new PartyItemShareCommand();
private CommandExecutor partyInviteCommand = new PartyInviteCommand();
private CommandExecutor partyKickCommand = new PartyKickCommand();
private CommandExecutor partyDisbandCommand = new PartyDisbandCommand();
private CommandExecutor partyChangeOwnerCommand = new PartyChangeOwnerCommand();
private CommandExecutor partyLockCommand = new PartyLockCommand();
private CommandExecutor partyChangePasswordCommand = new PartyChangePasswordCommand();
private CommandExecutor partyRenameCommand = new PartyRenameCommand();
private CommandExecutor partyInfoCommand = new PartyInfoCommand();
private CommandExecutor partyHelpCommand = new PartyHelpCommand();
private CommandExecutor partyTeleportCommand = new PtpCommand();
private CommandExecutor partyChatCommand = new PartyChatCommand();
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (CommandUtils.noConsoleUsage(sender)) {
return true;
}
if (!Permissions.party(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
player = (Player) sender;
mcMMOPlayer = UserManager.getPlayer(player);
if (args.length < 1) {
if (!mcMMOPlayer.inParty()) {
sender.sendMessage(LocaleLoader.getString("Commands.Party.None"));
return printUsage();
}
return partyInfoCommand.onCommand(sender, command, label, args);
}
PartySubcommandType subcommand = PartySubcommandType.getSubcommand(args[0]);
if (subcommand == null) {
return printUsage();
}
// Can't use this for lock/unlock since they're handled by the same command
if (subcommand != PartySubcommandType.LOCK && subcommand != PartySubcommandType.UNLOCK && !Permissions.partySubcommand(sender, subcommand)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
switch (subcommand) {
case JOIN:
return partyJoinCommand.onCommand(sender, command, label, args);
case ACCEPT:
return partyAcceptCommand.onCommand(sender, command, label, args);
case CREATE:
return partyCreateCommand.onCommand(sender, command, label, args);
case HELP:
return partyHelpCommand.onCommand(sender, command, label, args);
default:
break;
}
// Party member commands
if (!mcMMOPlayer.inParty()) {
sender.sendMessage(LocaleLoader.getString("Commands.Party.None"));
return printUsage();
}
switch (subcommand) {
case INFO:
return partyInfoCommand.onCommand(sender, command, label, args);
case QUIT:
return partyQuitCommand.onCommand(sender, command, label, args);
case INVITE:
return partyInviteCommand.onCommand(sender, command, label, args);
case TELEPORT:
return partyTeleportCommand.onCommand(sender, command, label, extractArgs(args));
case CHAT:
return partyChatCommand.onCommand(sender, command, label, extractArgs(args));
default:
break;
}
// Party leader commands
if (!mcMMOPlayer.getParty().getLeader().equals(player.getName())) {
sender.sendMessage(LocaleLoader.getString("Party.NotOwner"));
return true;
}
switch (subcommand) {
case EXPSHARE:
return partyExpShareCommand.onCommand(sender, command, label, args);
case ITEMSHARE:
return partyItemShareCommand.onCommand(sender, command, label, args);
case KICK:
return partyKickCommand.onCommand(sender, command, label, args);
case DISBAND:
return partyDisbandCommand.onCommand(sender, command, label, args);
case OWNER:
return partyChangeOwnerCommand.onCommand(sender, command, label, args);
case LOCK:
// Fallthrough
case UNLOCK:
return partyLockCommand.onCommand(sender, command, label, args);
case PASSWORD:
return partyChangePasswordCommand.onCommand(sender, command, label, args);
case RENAME:
return partyRenameCommand.onCommand(sender, command, label, args);
default:
break;
}
return true;
}
private boolean printUsage() {
player.sendMessage(LocaleLoader.getString("Party.Help.0", "/party join"));
player.sendMessage(LocaleLoader.getString("Party.Help.1", "/party create"));
player.sendMessage(LocaleLoader.getString("Party.Help.2", "/party ?"));
return true;
}
private String[] extractArgs(String[] args) {
String[] newArgs = new String[args.length - 1];
for (int i = 1; i < args.length; i++) {
newArgs[i - 1] = args[i];
}
return newArgs;
}
}

View File

@ -0,0 +1,56 @@
package com.gmail.nossr50.commands.party;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.player.UserManager;
public class PartyCreateCommand implements CommandExecutor {
private McMMOPlayer mcMMOPlayer;
private Player player;
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) {
case 2:
// Fallthrough
case 3:
Party newParty = PartyManager.getParty(args[1]);
// Check to see if the party exists, and if it does cancel creating a new party
if (newParty != null) {
sender.sendMessage(LocaleLoader.getString("Commands.Party.AlreadyExists", args[1]));
return true;
}
player = (Player) sender;
mcMMOPlayer = UserManager.getPlayer(player);
// Changing parties
if (!PartyManager.changeOrJoinParty(mcMMOPlayer, player, mcMMOPlayer.getParty(), args[1])) {
return true;
}
PartyManager.createParty(player, mcMMOPlayer, args[1], getPassword(args));
return true;
default:
sender.sendMessage(LocaleLoader.getString("Commands.Usage.3", "party", "create", "<" + LocaleLoader.getString("Commands.Usage.PartyName") + ">", "[" + LocaleLoader.getString("Commands.Usage.Password") + "]"));
return true;
}
}
private String getPassword(String[] args) {
if (args.length == 3) {
return args[2];
}
return null;
}
}

View File

@ -0,0 +1,37 @@
package com.gmail.nossr50.commands.party;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.player.UserManager;
public class PartyDisbandCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) {
case 1:
Party playerParty = UserManager.getPlayer((Player) sender).getParty();
for (Player member : playerParty.getOnlineMembers()) {
if (!PartyManager.handlePartyChangeEvent(member, playerParty.getName(), null, EventReason.KICKED_FROM_PARTY)) {
return true;
}
member.sendMessage(LocaleLoader.getString("Party.Disband"));
}
PartyManager.disbandParty(playerParty);
return true;
default:
sender.sendMessage(LocaleLoader.getString("Commands.Usage.1", "party", "disband"));
return true;
}
}
}

View File

@ -1,55 +1,55 @@
package com.gmail.nossr50.party.commands; package com.gmail.nossr50.commands.party;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.party.Party; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.ShareHandler; import com.gmail.nossr50.party.ShareHandler;
import com.gmail.nossr50.party.ShareHandler.ShareMode; import com.gmail.nossr50.party.ShareHandler.ShareMode;
import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.player.UserManager;
public class PartyExpShareCommand implements CommandExecutor { public class PartyExpShareCommand implements CommandExecutor {
private Party playerParty; 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()) {
sender.sendMessage(LocaleLoader.getString("Party.ExpShare.Disabled")); sender.sendMessage(LocaleLoader.getString("Party.ExpShare.Disabled"));
return true; return true;
} }
switch (args.length) { switch (args.length) {
case 2: case 2:
playerParty = Users.getPlayer((Player) sender).getParty(); playerParty = UserManager.getPlayer((Player) sender).getParty();
if (args[1].equalsIgnoreCase("none") || args[1].equalsIgnoreCase("off") || args[1].equalsIgnoreCase("false")) { if (args[1].equalsIgnoreCase("none") || args[1].equalsIgnoreCase("off") || args[1].equalsIgnoreCase("false")) {
handleChangingShareMode(ShareMode.NONE); handleChangingShareMode(ShareMode.NONE);
} }
else if (args[1].equalsIgnoreCase("equal") || args[1].equalsIgnoreCase("even") || args[1].equalsIgnoreCase("on") || args[1].equalsIgnoreCase("true")) { else if (args[1].equalsIgnoreCase("equal") || args[1].equalsIgnoreCase("even") || args[1].equalsIgnoreCase("on") || args[1].equalsIgnoreCase("true")) {
handleChangingShareMode(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]"));
} }
return true; return true;
default: default:
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "expshare", "<NONE | EQUAL>")); sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "expshare", "<NONE | EQUAL>"));
return true; return true;
} }
} }
private void handleChangingShareMode(ShareHandler.ShareMode mode) { private void handleChangingShareMode(ShareHandler.ShareMode mode) {
playerParty.setXpShareMode(mode); playerParty.setXpShareMode(mode);
for (Player member : playerParty.getOnlineMembers()) { for (Player member : playerParty.getOnlineMembers()) {
member.sendMessage(LocaleLoader.getString("Commands.Party.SetSharing", LocaleLoader.getString("Party.ShareType.Exp"), LocaleLoader.getString("Party.ShareMode." + StringUtils.getCapitalized(mode.toString())))); member.sendMessage(LocaleLoader.getString("Commands.Party.SetSharing", LocaleLoader.getString("Party.ShareType.Exp"), LocaleLoader.getString("Party.ShareMode." + StringUtils.getCapitalized(mode.toString()))));
} }
} }
} }

View File

@ -0,0 +1,30 @@
package com.gmail.nossr50.commands.party;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import com.gmail.nossr50.locale.LocaleLoader;
public class PartyHelpCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) {
case 1:
sender.sendMessage(LocaleLoader.getString("Party.Help.3", "/party join", "/party quit"));
sender.sendMessage(LocaleLoader.getString("Party.Help.1", "/party create"));
sender.sendMessage(LocaleLoader.getString("Party.Help.4", "/party <lock|unlock>"));
sender.sendMessage(LocaleLoader.getString("Party.Help.5", "/party password"));
sender.sendMessage(LocaleLoader.getString("Party.Help.6", "/party kick"));
sender.sendMessage(LocaleLoader.getString("Party.Help.7", "/party leader"));
sender.sendMessage(LocaleLoader.getString("Party.Help.8", "/party disband"));
return true;
default:
sender.sendMessage(LocaleLoader.getString("Commands.Usage.1", "party", "help"));
return true;
}
}
}

View File

@ -1,97 +1,102 @@
package com.gmail.nossr50.party.commands; package com.gmail.nossr50.commands.party;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer; 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;
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.McMMOPlayer; import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.party.Party; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.party.ShareHandler;
import com.gmail.nossr50.util.player.UserManager;
public class PartyInfoCommand implements CommandExecutor {
private Player player; public class PartyInfoCommand implements CommandExecutor {
private Party playerParty; private Player player;
private Party playerParty;
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { @Override
player = (Player) sender; public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
McMMOPlayer mcMMOPlayer = Users.getPlayer(player); player = (Player) sender;
playerParty = mcMMOPlayer.getParty(); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
playerParty = mcMMOPlayer.getParty();
displayPartyHeader();
displayShareModeInfo(); displayPartyHeader();
displayMemberInfo(); displayShareModeInfo();
return true; displayMemberInfo();
} return true;
}
private String createMembersList() {
StringBuilder memberList = new StringBuilder(); private String createMembersList() {
StringBuilder memberList = new StringBuilder();
for (OfflinePlayer member : playerParty.getMembers()) {
if (playerParty.getLeader().equals(member.getName())) { for (OfflinePlayer member : playerParty.getMembers()) {
memberList.append(ChatColor.GOLD).append(member.getName()).append(" "); if (playerParty.getLeader().equals(member.getName())) {
} memberList.append(ChatColor.GOLD).append(member.getName()).append(" ");
else if (member.isOnline()) { }
memberList.append(ChatColor.WHITE).append(member.getName()).append(" "); else if (member.isOnline()) {
} memberList.append(ChatColor.WHITE).append(member.getName()).append(" ");
else { }
memberList.append(ChatColor.GRAY).append(member.getName()).append(" "); else {
} memberList.append(ChatColor.GRAY).append(member.getName()).append(" ");
} }
}
return memberList.toString();
} return memberList.toString();
}
private void displayShareModeInfo() {
boolean xpShareEnabled = Config.getInstance().getExpShareEnabled(); private void displayShareModeInfo() {
boolean itemShareEnabled = Config.getInstance().getItemShareEnabled(); boolean xpShareEnabled = Config.getInstance().getExpShareEnabled();
boolean itemShareEnabled = Config.getInstance().getItemShareEnabled();
if (!xpShareEnabled && !itemShareEnabled) { boolean itemSharingActive = playerParty.getItemShareMode() != ShareHandler.ShareMode.NONE;
return;
} if (!xpShareEnabled && !itemShareEnabled) {
return;
String expShareInfo = ""; }
String itemShareInfo = "";
String separator = ""; String expShareInfo = "";
String itemShareInfo = "";
if (xpShareEnabled) { String separator = "";
expShareInfo = LocaleLoader.getString("Commands.Party.ExpShare", playerParty.getXpShareMode().toString());
} if (xpShareEnabled) {
expShareInfo = LocaleLoader.getString("Commands.Party.ExpShare", playerParty.getXpShareMode().toString());
if (itemShareEnabled) { }
itemShareInfo = LocaleLoader.getString("Commands.Party.ItemShare", playerParty.getItemShareMode().toString());
} if (itemShareEnabled) {
itemShareInfo = LocaleLoader.getString("Commands.Party.ItemShare", playerParty.getItemShareMode().toString());
if (xpShareEnabled && itemShareEnabled) { }
separator = ChatColor.DARK_GRAY + " || ";
} if (xpShareEnabled && itemShareEnabled) {
separator = ChatColor.DARK_GRAY + " || ";
player.sendMessage(LocaleLoader.getString("Commands.Party.ShareMode") + expShareInfo + separator + itemShareInfo); }
}
player.sendMessage(LocaleLoader.getString("Commands.Party.ShareMode") + expShareInfo + separator + itemShareInfo);
private void displayPartyHeader() { if (itemSharingActive) {
player.sendMessage(LocaleLoader.getString("Commands.Party.Header")); player.sendMessage(LocaleLoader.getString("Commands.Party.ItemShareCategories", playerParty.getItemShareCategories()));
}
if (playerParty.isLocked()) { }
player.sendMessage(LocaleLoader.getString("Commands.Party.Status", playerParty.getName(), LocaleLoader.getString("Party.Status.Locked")));
} private void displayPartyHeader() {
else { player.sendMessage(LocaleLoader.getString("Commands.Party.Header"));
player.sendMessage(LocaleLoader.getString("Commands.Party.Status", playerParty.getName(), LocaleLoader.getString("Party.Status.Unlocked")));
} if (playerParty.isLocked()) {
} player.sendMessage(LocaleLoader.getString("Commands.Party.Status", playerParty.getName(), LocaleLoader.getString("Party.Status.Locked")));
}
private void displayMemberInfo() { else {
int membersNear = PartyManager.getNearMembers(player, playerParty, Config.getInstance().getPartyShareRange()).size(); player.sendMessage(LocaleLoader.getString("Commands.Party.Status", playerParty.getName(), LocaleLoader.getString("Party.Status.Unlocked")));
int membersOnline = playerParty.getOnlineMembers().size() - 1; }
}
player.sendMessage(LocaleLoader.getString("Commands.Party.Members.Header"));
player.sendMessage(LocaleLoader.getString("Commands.Party.MembersNear", membersNear, membersOnline)); private void displayMemberInfo() {
player.sendMessage(LocaleLoader.getString("Commands.Party.Members", createMembersList())); int membersNear = PartyManager.getNearMembers(player, playerParty, Config.getInstance().getPartyShareRange()).size();
} int membersOnline = playerParty.getOnlineMembers().size() - 1;
}
player.sendMessage(LocaleLoader.getString("Commands.Party.Members.Header"));
player.sendMessage(LocaleLoader.getString("Commands.Party.MembersNear", membersNear, membersOnline));
player.sendMessage(LocaleLoader.getString("Commands.Party.Members", createMembersList()));
}
}

View File

@ -0,0 +1,72 @@
package com.gmail.nossr50.commands.party;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.player.UserManager;
public class PartyInviteCommand implements CommandExecutor {
private McMMOPlayer mcMMOTarget;
private Player target;
private McMMOPlayer mcMMOPlayer;
private Player player;
private Party playerParty;
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) {
case 2:
if (!mcMMO.p.getServer().getOfflinePlayer(args[1]).isOnline()) {
sender.sendMessage(LocaleLoader.getString("Party.NotOnline", args[1]));
return true;
}
mcMMOTarget = UserManager.getPlayer(args[1]);
if (mcMMOTarget == null) {
sender.sendMessage(LocaleLoader.getString("Party.Player.Invalid"));
return true;
}
target = mcMMOTarget.getPlayer();
mcMMOPlayer = UserManager.getPlayer((Player) sender);
player = mcMMOPlayer.getPlayer();
if (player.equals(target)) {
sender.sendMessage(LocaleLoader.getString("Party.Invite.Self"));
return true;
}
if (PartyManager.inSameParty(player, target)) {
sender.sendMessage(LocaleLoader.getString("Party.Player.InSameParty", target.getName()));
return true;
}
playerParty = mcMMOPlayer.getParty();
if (!PartyManager.canInvite(player, playerParty)) {
player.sendMessage(LocaleLoader.getString("Party.Locked"));
return true;
}
mcMMOTarget.setPartyInvite(playerParty);
sender.sendMessage(LocaleLoader.getString("Commands.Invite.Success"));
target.sendMessage(LocaleLoader.getString("Commands.Party.Invite.0", playerParty.getName(), player.getName()));
target.sendMessage(LocaleLoader.getString("Commands.Party.Invite.1"));
return true;
default:
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "invite", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">"));
return true;
}
}
}

View File

@ -0,0 +1,101 @@
package com.gmail.nossr50.commands.party;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.party.Party;
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.player.UserManager;
public class PartyItemShareCommand implements CommandExecutor {
private Party playerParty;
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!Config.getInstance().getItemShareEnabled()) {
sender.sendMessage(LocaleLoader.getString("Party.ItemShare.Disabled"));
return true;
}
switch (args.length) {
case 2:
playerParty = UserManager.getPlayer((Player) sender).getParty();
if (args[1].equalsIgnoreCase("none") || args[1].equalsIgnoreCase("off") || args[1].equalsIgnoreCase("false")) {
handleChangingShareMode(ShareMode.NONE);
}
else if (args[1].equalsIgnoreCase("equal") || args[1].equalsIgnoreCase("even")) {
handleChangingShareMode(ShareMode.EQUAL);
}
else if (args[1].equalsIgnoreCase("random")) {
handleChangingShareMode(ShareMode.RANDOM);
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "<NONE | EQUAL | RANDOM>"));
}
return true;
case 3:
playerParty = UserManager.getPlayer((Player) sender).getParty();
boolean toggle = false;
if (args[2].equalsIgnoreCase("true") || args[2].equalsIgnoreCase("on") || args[2].equalsIgnoreCase("enabled")) {
toggle = true;
}
else if (args[2].equalsIgnoreCase("false") || args[2].equalsIgnoreCase("off") || args[2].equalsIgnoreCase("disabled")) {
toggle = false;
}
if (args[1].equalsIgnoreCase("loot")) {
playerParty.setSharingLootDrops(toggle);
}
else if (args[1].equalsIgnoreCase("mining")) {
playerParty.setSharingMiningDrops(toggle);
}
else if (args[1].equalsIgnoreCase("herbalism")) {
playerParty.setSharingHerbalismDrops(toggle);
}
else if (args[1].equalsIgnoreCase("woodcutting")) {
playerParty.setSharingWoodcuttingDrops(toggle);
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "<loot | mining | herbalism | woodcutting> <true | false>"));
}
notifyToggleItemShareCategory(args, toggle);
return true;
default:
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "<NONE | EQUAL | RANDOM>"));
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "<loot | mining | herbalism | woodcutting> <true | false>"));
return true;
}
}
private void handleChangingShareMode(ShareHandler.ShareMode mode) {
playerParty.setItemShareMode(mode);
for (Player member : playerParty.getOnlineMembers()) {
member.sendMessage(LocaleLoader.getString("Commands.Party.SetSharing", LocaleLoader.getString("Party.ShareType.Item"), LocaleLoader.getString("Party.ShareMode." + StringUtils.getCapitalized(mode.toString()))));
}
}
private void notifyToggleItemShareCategory(String[] args, boolean toggle) {
String state = "disabled";
if (toggle) {
state = "enabled";
}
for (Player member : playerParty.getOnlineMembers()) {
member.sendMessage(LocaleLoader.getString("Commands.Party.ToggleShareCategory", StringUtils.getCapitalized(args[1]), state));
}
}
}

View File

@ -1,95 +1,96 @@
package com.gmail.nossr50.party.commands; package com.gmail.nossr50.commands.party;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.McMMOPlayer; import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.party.Party; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.player.UserManager;
public class PartyJoinCommand implements CommandExecutor { public class PartyJoinCommand implements CommandExecutor {
private McMMOPlayer mcMMOTarget; private McMMOPlayer mcMMOTarget;
private Player target; private Player target;
private Party targetParty; private Party targetParty;
private McMMOPlayer mcMMOPlayer; private McMMOPlayer mcMMOPlayer;
private Player player; private Player player;
private Party playerParty; 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: // Fallthrough
// Verify target exists and is in a different party than the player case 3:
if (!canJoinParty(sender, args[1])) { // Verify target exists and is in a different party than the player
return true; if (!canJoinParty(sender, args[1])) {
} return true;
}
String password = getPassword(args);
String password = getPassword(args);
// Make sure party passwords match
if (!PartyManager.checkPartyPassword(player, targetParty, password)) { // Make sure party passwords match
return true; if (!PartyManager.checkPartyPassword(player, targetParty, password)) {
} return true;
}
// Changing parties
if (!PartyManager.changeOrJoinParty(mcMMOPlayer, player, playerParty, targetParty.getName())) { // Changing parties
return true; if (!PartyManager.changeOrJoinParty(mcMMOPlayer, player, playerParty, targetParty.getName())) {
} return true;
}
PartyManager.joinParty(player, mcMMOPlayer, targetParty, password);
return true; PartyManager.joinParty(player, mcMMOPlayer, targetParty, password);
return true;
default:
sender.sendMessage(LocaleLoader.getString("Commands.Usage.3", "party", "join", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">", "[" + LocaleLoader.getString("Commands.Usage.Password") + "]")); default:
return true; sender.sendMessage(LocaleLoader.getString("Commands.Usage.3", "party", "join", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">", "[" + LocaleLoader.getString("Commands.Usage.Password") + "]"));
} return true;
} }
}
private String getPassword(String[] args) {
if (args.length == 3) { private String getPassword(String[] args) {
return args[2]; if (args.length == 3) {
} return args[2];
}
return null;
} return null;
}
private boolean canJoinParty(CommandSender sender, String targetName) {
if (!mcMMO.p.getServer().getOfflinePlayer(targetName).isOnline()) { private boolean canJoinParty(CommandSender sender, String targetName) {
sender.sendMessage(LocaleLoader.getString("Party.NotOnline", targetName)); if (!mcMMO.p.getServer().getOfflinePlayer(targetName).isOnline()) {
return false; sender.sendMessage(LocaleLoader.getString("Party.NotOnline", targetName));
} return false;
}
mcMMOTarget = Users.getPlayer(targetName);
mcMMOTarget = UserManager.getPlayer(targetName);
if (mcMMOTarget == null) {
sender.sendMessage(LocaleLoader.getString("Party.Player.Invalid")); if (mcMMOTarget == null) {
return false; sender.sendMessage(LocaleLoader.getString("Party.Player.Invalid"));
} return false;
}
target = mcMMOTarget.getPlayer();
target = mcMMOTarget.getPlayer();
if (!mcMMOTarget.inParty()) {
sender.sendMessage(LocaleLoader.getString("Party.PlayerNotInParty", targetName)); if (!mcMMOTarget.inParty()) {
return false; sender.sendMessage(LocaleLoader.getString("Party.PlayerNotInParty", targetName));
} return false;
}
player = (Player) sender;
mcMMOPlayer = Users.getPlayer(player); player = (Player) sender;
playerParty = mcMMOPlayer.getParty(); mcMMOPlayer = UserManager.getPlayer(player);
targetParty = mcMMOTarget.getParty(); playerParty = mcMMOPlayer.getParty();
targetParty = mcMMOTarget.getParty();
if (player.equals(target) || (mcMMOPlayer.inParty() && playerParty.equals(targetParty))) {
sender.sendMessage(LocaleLoader.getString("Party.Join.Self")); if (player.equals(target) || (mcMMOPlayer.inParty() && playerParty.equals(targetParty))) {
return false; sender.sendMessage(LocaleLoader.getString("Party.Join.Self"));
} return false;
}
return true;
} return true;
} }
}

View File

@ -0,0 +1,49 @@
package com.gmail.nossr50.commands.party;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.player.UserManager;
public class PartyKickCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) {
case 2:
Party playerParty = UserManager.getPlayer((Player) sender).getParty();
OfflinePlayer target = mcMMO.p.getServer().getOfflinePlayer(args[1]);
if (!playerParty.getMembers().contains(target)) {
sender.sendMessage(LocaleLoader.getString("Party.NotInYourParty", args[1]));
return true;
}
if (target.isOnline()) {
Player onlineTarget = target.getPlayer();
String partyName = playerParty.getName();
if (!PartyManager.handlePartyChangeEvent(onlineTarget, partyName, null, EventReason.KICKED_FROM_PARTY)) {
return true;
}
onlineTarget.sendMessage(LocaleLoader.getString("Commands.Party.Kick", partyName));
}
PartyManager.removeFromParty(target, playerParty);
return true;
default:
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "kick", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">"));
return true;
}
}
}

View File

@ -1,97 +1,97 @@
package com.gmail.nossr50.party.commands; package com.gmail.nossr50.commands.party;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.party.Party; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.player.UserManager;
public class PartyLockCommand implements CommandExecutor { public class PartyLockCommand implements CommandExecutor {
private Party playerParty; 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 = Users.getPlayer((Player) sender).getParty(); 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")) {
lockParty(sender, command); lockParty(sender, command);
} }
else if (args[0].equalsIgnoreCase("unlock")) { else if (args[0].equalsIgnoreCase("unlock")) {
unlockParty(sender, command); unlockParty(sender, command);
} }
return true; return true;
case 2: case 2:
if (!args[0].equalsIgnoreCase("lock")) { if (!args[0].equalsIgnoreCase("lock")) {
sendUsageStrings(sender); sendUsageStrings(sender);
return true; return true;
} }
if (args[1].equalsIgnoreCase("on") || args[1].equalsIgnoreCase("true")) { if (args[1].equalsIgnoreCase("on") || args[1].equalsIgnoreCase("true")) {
lockParty(sender, command); lockParty(sender, command);
} }
else if (args[1].equalsIgnoreCase("off") || args[1].equalsIgnoreCase("false")) { else if (args[1].equalsIgnoreCase("off") || args[1].equalsIgnoreCase("false")) {
unlockParty(sender, command); unlockParty(sender, command);
} }
else { else {
sendUsageStrings(sender); sendUsageStrings(sender);
} }
return true; return true;
default: default:
sendUsageStrings(sender); sendUsageStrings(sender);
return true; return true;
} }
} }
/** /**
* Handle locking a party. * Handle locking a party.
*/ */
private void lockParty(CommandSender sender, Command command) { private void lockParty(CommandSender sender, Command command) {
if (!Permissions.partySubcommand(sender, PartySubcommandType.LOCK)) { if (!Permissions.partySubcommand(sender, PartySubcommandType.LOCK)) {
sender.sendMessage(command.getPermissionMessage()); sender.sendMessage(command.getPermissionMessage());
return; return;
} }
if (playerParty.isLocked()) { if (playerParty.isLocked()) {
sender.sendMessage(LocaleLoader.getString("Party.IsLocked")); sender.sendMessage(LocaleLoader.getString("Party.IsLocked"));
return; return;
} }
playerParty.setLocked(true); playerParty.setLocked(true);
sender.sendMessage(LocaleLoader.getString("Party.Locked")); sender.sendMessage(LocaleLoader.getString("Party.Locked"));
} }
/** /**
* Handle unlocking a party. * Handle unlocking a party.
* *
* @return true if party is successfully unlocked, false otherwise. * @return true if party is successfully unlocked, false otherwise.
*/ */
private void unlockParty(CommandSender sender, Command command) { private void unlockParty(CommandSender sender, Command command) {
if (!Permissions.partySubcommand(sender, PartySubcommandType.UNLOCK)) { if (!Permissions.partySubcommand(sender, PartySubcommandType.UNLOCK)) {
sender.sendMessage(command.getPermissionMessage()); sender.sendMessage(command.getPermissionMessage());
return; return;
} }
if (!playerParty.isLocked()) { if (!playerParty.isLocked()) {
sender.sendMessage(LocaleLoader.getString("Party.IsntLocked")); sender.sendMessage(LocaleLoader.getString("Party.IsntLocked"));
return; return;
} }
playerParty.setLocked(false); playerParty.setLocked(false);
sender.sendMessage(LocaleLoader.getString("Party.Unlocked")); 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"));
} }
} }

View File

@ -0,0 +1,38 @@
package com.gmail.nossr50.commands.party;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.player.UserManager;
public class PartyQuitCommand implements CommandExecutor {
private Player player;
private Party playerParty;
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) {
case 1:
player = (Player) sender;
playerParty = UserManager.getPlayer(player).getParty();
if (!PartyManager.handlePartyChangeEvent(player, playerParty.getName(), null, EventReason.LEFT_PARTY)) {
return true;
}
PartyManager.removeFromParty(player, playerParty);
sender.sendMessage(LocaleLoader.getString("Commands.Party.Leave"));
return true;
default:
sender.sendMessage(LocaleLoader.getString("Commands.Usage.1", "party", "[quit|q|leave]"));
return true;
}
}
}

View File

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

View File

@ -1,45 +1,48 @@
package com.gmail.nossr50.party.commands; package com.gmail.nossr50.commands.party;
public enum PartySubcommandType { public enum PartySubcommandType {
JOIN, JOIN,
ACCEPT, ACCEPT,
CREATE, CREATE,
HELP, HELP,
INFO, INFO,
QUIT, QUIT,
EXPSHARE, EXPSHARE,
ITEMSHARE, ITEMSHARE,
INVITE, INVITE,
KICK, KICK,
DISBAND, DISBAND,
OWNER, OWNER,
LOCK, LOCK,
UNLOCK, UNLOCK,
PASSWORD, PASSWORD,
RENAME, RENAME,
TELEPORT, TELEPORT,
CHAT; CHAT;
public static PartySubcommandType getSubcommand(String commandName) { public static PartySubcommandType getSubcommand(String commandName) {
for (PartySubcommandType command : values()) { for (PartySubcommandType command : values()) {
if (command.name().equalsIgnoreCase(commandName)) { if (command.name().equalsIgnoreCase(commandName)) {
return command; return command;
} }
} }
if (commandName.equalsIgnoreCase("?")) { if (commandName.equalsIgnoreCase("?")) {
return HELP; return HELP;
} }
else if (commandName.equalsIgnoreCase("q") || commandName.equalsIgnoreCase("leave")) { else if (commandName.equalsIgnoreCase("q") || commandName.equalsIgnoreCase("leave")) {
return QUIT; return QUIT;
} }
else if (commandName.equalsIgnoreCase("xpshare") || commandName.equalsIgnoreCase("shareexp") || commandName.equalsIgnoreCase("sharexp")) { else if (commandName.equalsIgnoreCase("leader")) {
return EXPSHARE; return OWNER;
} }
else if (commandName.equalsIgnoreCase("shareitem") || commandName.equalsIgnoreCase("shareitems")) { else if (commandName.equalsIgnoreCase("xpshare") || commandName.equalsIgnoreCase("shareexp") || commandName.equalsIgnoreCase("sharexp")) {
return ITEMSHARE; return EXPSHARE;
} }
else if (commandName.equalsIgnoreCase("shareitem") || commandName.equalsIgnoreCase("shareitems")) {
return null; return ITEMSHARE;
} }
}
return null;
}
}

View File

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

View File

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

View File

@ -1,80 +0,0 @@
package com.gmail.nossr50.commands.player;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users;
public class McabilityCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
PlayerProfile profile;
switch (args.length) {
case 0:
if (!Permissions.mcability(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
profile = Users.getPlayer((Player) sender).getProfile();
if (profile.getAbilityUse()) {
sender.sendMessage(LocaleLoader.getString("Commands.Ability.Off"));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.Ability.On"));
}
profile.toggleAbilityUse();
return true;
case 1:
if (!Permissions.mcabilityOthers(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
McMMOPlayer mcMMOPlayer = Users.getPlayer(args[0]);
if (mcMMOPlayer == null) {
profile = new PlayerProfile(args[0], false);
if (!profile.isLoaded()) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
sender.sendMessage(LocaleLoader.getString("Commands.Offline"));
return true;
}
Player player = mcMMOPlayer.getPlayer();
profile = mcMMOPlayer.getProfile();
if (!player.isOnline()) {
sender.sendMessage(LocaleLoader.getString("Commands.Offline"));
return true;
}
if (profile.getAbilityUse()) {
player.sendMessage(LocaleLoader.getString("Commands.Ability.Off"));
}
else {
player.sendMessage(LocaleLoader.getString("Commands.Ability.On"));
}
profile.toggleAbilityUse();
return true;
default:
return false;
}
}
}

View File

@ -1,34 +0,0 @@
package com.gmail.nossr50.commands.player;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Users;
public class McnotifyCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) {
case 0:
PlayerProfile profile = Users.getPlayer((Player) sender).getProfile();
if (profile.useChatNotifications()) {
sender.sendMessage(LocaleLoader.getString("Commands.Notifications.Off"));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.Notifications.On"));
}
profile.toggleChatNotifications();
return true;
default:
return false;
}
}
}

View File

@ -8,83 +8,83 @@ 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.database.Leaderboard; import com.gmail.nossr50.database.LeaderboardManager;
import com.gmail.nossr50.datatypes.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.runnables.McRankAsync; import com.gmail.nossr50.runnables.commands.McrankCommandAsyncTask;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
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.Users; import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.skills.SkillUtils;
public class McrankCommand implements CommandExecutor { public class McrankCommand implements CommandExecutor {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) { switch (args.length) {
case 0: case 0:
if (!Permissions.mcrank(sender)) { if (!Permissions.mcrank(sender)) {
sender.sendMessage(command.getPermissionMessage()); sender.sendMessage(command.getPermissionMessage());
return true; return true;
} }
if (!(sender instanceof Player)) { if (!(sender instanceof Player)) {
return false;
}
if (Config.getInstance().getUseMySQL()) {
sqlDisplay(sender, sender.getName());
}
else {
LeaderboardManager.updateLeaderboards(); // Make sure the information is up to date
flatfileDisplay(sender, sender.getName());
}
return true;
case 1:
if (!Permissions.mcrankOthers(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(args[0]);
if (mcMMOPlayer == null) {
PlayerProfile profile = new PlayerProfile(args[0], false); // Temporary Profile
if (!profile.isLoaded()) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
if (sender instanceof Player && !Permissions.mcrankOffline(sender)) {
sender.sendMessage(LocaleLoader.getString("Inspect.Offline"));
return true;
}
}
else {
Player target = mcMMOPlayer.getPlayer();
if (sender instanceof Player && !Misc.isNear(((Player) sender).getLocation(), target.getLocation(), 5.0) && !Permissions.mcrankFar(sender)) {
sender.sendMessage(LocaleLoader.getString("Inspect.TooFar"));
return true;
}
}
if (Config.getInstance().getUseMySQL()) {
sqlDisplay(sender, args[0]);
}
else {
LeaderboardManager.updateLeaderboards(); // Make sure the information is up to date
flatfileDisplay(sender, args[0]);
}
return true;
default:
return false; return false;
}
if (Config.getInstance().getUseMySQL()) {
sqlDisplay(sender, sender.getName());
}
else {
Leaderboard.updateLeaderboards(); // Make sure the information is up to date
flatfileDisplay(sender, sender.getName());
}
return true;
case 1:
if (!Permissions.mcrankOthers(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
McMMOPlayer mcMMOPlayer = Users.getPlayer(args[0]);
if (mcMMOPlayer == null) {
PlayerProfile profile = new PlayerProfile(args[0], false); //Temporary Profile
if (!profile.isLoaded()) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
if (sender instanceof Player && !Permissions.mcrankOffline(sender)) {
sender.sendMessage(LocaleLoader.getString("Inspect.Offline"));
return true;
}
}
else {
Player target = mcMMOPlayer.getPlayer();
if (sender instanceof Player && !Misc.isNear(((Player) sender).getLocation(), target.getLocation(), 5.0) && !Permissions.mcrankFar(sender)) {
sender.sendMessage(LocaleLoader.getString("Inspect.TooFar"));
return true;
}
}
if (Config.getInstance().getUseMySQL()) {
sqlDisplay(sender, args[0]);
}
else {
Leaderboard.updateLeaderboards(); // Make sure the information is up to date
flatfileDisplay(sender, args[0]);
}
return true;
default:
return false;
} }
} }
@ -93,22 +93,22 @@ public class McrankCommand implements CommandExecutor {
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Player", playerName)); sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Player", playerName));
for (SkillType skillType : SkillType.values()) { for (SkillType skillType : SkillType.values()) {
int[] rankInts = Leaderboard.getPlayerRank(playerName, skillType); int[] rankInts = LeaderboardManager.getPlayerRank(playerName, skillType);
if (skillType.isChildSkill()) { if (skillType.isChildSkill()) {
continue; continue;
} }
if (rankInts[1] == 0) { if (rankInts[1] == 0) {
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", SkillTools.getSkillName(skillType), LocaleLoader.getString("Commands.mcrank.Unranked"))); // Don't bother showing ranking for players without skills sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", SkillUtils.getSkillName(skillType), LocaleLoader.getString("Commands.mcrank.Unranked"))); // Don't bother showing ranking for players without skills
} }
else { else {
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", SkillTools.getSkillName(skillType), rankInts[0])); sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", SkillUtils.getSkillName(skillType), rankInts[0]));
} }
} }
// Show the powerlevel ranking // Show the powerlevel ranking
int[] rankInts = Leaderboard.getPlayerRank(playerName); int[] rankInts = LeaderboardManager.getPlayerRank(playerName);
if (rankInts[1] == 0) { if (rankInts[1] == 0) {
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Overall", LocaleLoader.getString("Commands.mcrank.Unranked"))); // Don't bother showing ranking for players without skills sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Overall", LocaleLoader.getString("Commands.mcrank.Unranked"))); // Don't bother showing ranking for players without skills
@ -119,6 +119,6 @@ public class McrankCommand implements CommandExecutor {
} }
private void sqlDisplay(CommandSender sender, String playerName) { private void sqlDisplay(CommandSender sender, String playerName) {
Bukkit.getScheduler().runTaskAsynchronously(mcMMO.p, new McRankAsync(playerName, sender)); Bukkit.getScheduler().runTaskAsynchronously(mcMMO.p, new McrankCommandAsyncTask(playerName, sender));
} }
} }

View File

@ -1,50 +1,50 @@
package com.gmail.nossr50.commands.player; package com.gmail.nossr50.commands.player;
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 org.bukkit.entity.Player;
import com.gmail.nossr50.commands.CommandHelper; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.McMMOPlayer; import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.player.UserManager;
public class McstatsCommand implements CommandExecutor { public class McstatsCommand implements CommandExecutor {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (CommandHelper.noConsoleUsage(sender)) { if (CommandUtils.noConsoleUsage(sender)) {
return true; return true;
} }
switch (args.length) { switch (args.length) {
case 0: case 0:
Player player = (Player) sender; Player player = (Player) sender;
McMMOPlayer mcMMOPlayer = Users.getPlayer(player); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
PlayerProfile profile = mcMMOPlayer.getProfile(); PlayerProfile profile = mcMMOPlayer.getProfile();
player.sendMessage(LocaleLoader.getString("Stats.Own.Stats")); player.sendMessage(LocaleLoader.getString("Stats.Own.Stats"));
player.sendMessage(LocaleLoader.getString("mcMMO.NoSkillNote")); player.sendMessage(LocaleLoader.getString("mcMMO.NoSkillNote"));
CommandHelper.printGatheringSkills(player, profile); CommandUtils.printGatheringSkills(player, profile);
CommandHelper.printCombatSkills(player, profile); CommandUtils.printCombatSkills(player, profile);
CommandHelper.printMiscSkills(player, profile); CommandUtils.printMiscSkills(player, profile);
int powerLevelCap = Config.getInstance().getPowerLevelCap(); int powerLevelCap = Config.getInstance().getPowerLevelCap();
if (powerLevelCap != Integer.MAX_VALUE) { if (powerLevelCap != Integer.MAX_VALUE) {
player.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Capped", mcMMOPlayer.getPowerLevel(), powerLevelCap)); player.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Capped", mcMMOPlayer.getPowerLevel(), powerLevelCap));
} }
else { else {
player.sendMessage(LocaleLoader.getString("Commands.PowerLevel", mcMMOPlayer.getPowerLevel())); player.sendMessage(LocaleLoader.getString("Commands.PowerLevel", mcMMOPlayer.getPowerLevel()));
} }
return true; return true;
default: default:
return false; return false;
} }
} }
} }

View File

@ -1,115 +1,129 @@
package com.gmail.nossr50.commands.player; package com.gmail.nossr50.commands.player;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; 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.database.Leaderboard; import com.gmail.nossr50.database.LeaderboardManager;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.runnables.McTopAsync; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.SkillTools; import com.gmail.nossr50.runnables.commands.MctopCommandAsyncTask;
import com.gmail.nossr50.skills.utilities.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.skills.SkillUtils;
public class MctopCommand implements CommandExecutor { public class MctopCommand implements CommandExecutor {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
boolean useMySQL = Config.getInstance().getUseMySQL(); boolean useMySQL = Config.getInstance().getUseMySQL();
switch (args.length) { switch (args.length) {
case 0: case 0:
display(1, "ALL", sender, useMySQL, command); display(1, "ALL", sender, useMySQL, command);
return true; return true;
case 1: case 1:
if (StringUtils.isInt(args[0])) { if (StringUtils.isInt(args[0])) {
display(Integer.parseInt(args[0]), "ALL", sender, useMySQL, command); display(Integer.parseInt(args[0]), "ALL", sender, useMySQL, command);
} }
else if (SkillTools.isSkill(args[0])) { else if (SkillUtils.isSkill(args[0])) {
display(1, SkillType.getSkill(args[0]).toString(), sender, useMySQL, command); SkillType skill = SkillType.getSkill(args[0]);
}
else { if (skill.isChildSkill()) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid")); sender.sendMessage("Child skills are not yet supported by this command."); // TODO: Localize this
} return true;
}
return true;
display(1, skill.toString(), sender, useMySQL, command);
case 2: }
if (!StringUtils.isInt(args[1])) { else {
return false; sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
} }
if (SkillTools.isSkill(args[0])) { return true;
display(Integer.parseInt(args[1]), SkillType.getSkill(args[0]).toString(), sender, useMySQL, command);
} case 2:
else { if (!StringUtils.isInt(args[1])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid")); return false;
} }
return true; if (SkillUtils.isSkill(args[0])) {
SkillType skill = SkillType.getSkill(args[0]);
default:
return false; if (skill.isChildSkill()) {
} sender.sendMessage("Child skills are not yet supported by this command."); // TODO: Localize this
} return true;
}
private void display(int page, String skill, CommandSender sender, boolean sql, Command command) {
if (sql) { display(Integer.parseInt(args[1]), skill.toString(), sender, useMySQL, command);
if (skill.equalsIgnoreCase("all")) { }
sqlDisplay(page, "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing", sender, command); else {
} sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
else { }
sqlDisplay(page, skill, sender, command);
} return true;
}
else { default:
flatfileDisplay(page, skill, sender, command); return false;
} }
} }
private void flatfileDisplay(int page, String skill, CommandSender sender, Command command) { private void display(int page, String skill, CommandSender sender, boolean sql, Command command) {
if (!skill.equalsIgnoreCase("all") && !Permissions.mctop(sender, SkillType.getSkill(skill))) { if (sql) {
sender.sendMessage(command.getPermissionMessage()); if (skill.equalsIgnoreCase("all")) {
return; sqlDisplay(page, "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing", sender, command);
} }
else {
Leaderboard.updateLeaderboards(); //Make sure we have the latest information sqlDisplay(page, skill, sender, command);
}
String[] info = Leaderboard.retrieveInfo(skill, page); }
else {
if (skill.equalsIgnoreCase("all")) { flatfileDisplay(page, skill, sender, command);
sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Leaderboard")); }
} }
else {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Leaderboard", StringUtils.getCapitalized(skill))); private void flatfileDisplay(int page, String skill, CommandSender sender, Command command) {
} if (!skill.equalsIgnoreCase("all") && !Permissions.mctop(sender, SkillType.getSkill(skill))) {
sender.sendMessage(command.getPermissionMessage());
int n = (page * 10) - 9; // Position return;
for (String x : info) { }
if (x != null) {
String digit = String.valueOf(n); LeaderboardManager.updateLeaderboards(); // Make sure we have the latest information
if (n < 10) { String[] info = LeaderboardManager.retrieveInfo(skill, page);
digit = "0" + digit;
} if (skill.equalsIgnoreCase("all")) {
sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Leaderboard"));
String[] splitx = x.split(":"); }
else {
// Format: 1. Playername - skill value sender.sendMessage(LocaleLoader.getString("Commands.Skill.Leaderboard", StringUtils.getCapitalized(skill)));
sender.sendMessage(digit + ". " + ChatColor.GREEN + splitx[1] + " - " + ChatColor.WHITE + splitx[0]); }
n++;
} int n = (page * 10) - 9; // Position
} for (String x : info) {
if (x != null) {
sender.sendMessage(LocaleLoader.getString("Commands.mctop.Tip")); String digit = String.valueOf(n);
}
if (n < 10) {
private void sqlDisplay(int page, String query, CommandSender sender, Command command) { digit = "0" + digit;
Bukkit.getScheduler().runTaskAsynchronously(mcMMO.p, new McTopAsync(page, query, sender, command)); }
}
} String[] splitx = x.split(":");
// Format: 1. Playername - skill value
sender.sendMessage(digit + ". " + ChatColor.GREEN + splitx[1] + " - " + ChatColor.WHITE + splitx[0]);
n++;
}
}
sender.sendMessage(LocaleLoader.getString("Commands.mctop.Tip"));
}
private void sqlDisplay(int page, String query, CommandSender sender, Command command) {
Bukkit.getScheduler().runTaskAsynchronously(mcMMO.p, new MctopCommandAsyncTask(page, query, sender, command));
}
}

View File

@ -1,105 +1,105 @@
package com.gmail.nossr50.skills.acrobatics; package com.gmail.nossr50.commands.skills;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.skills.SkillCommand; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.skills.acrobatics.Acrobatics;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
public class AcrobaticsCommand extends SkillCommand { public class AcrobaticsCommand extends SkillCommand {
private String dodgeChance; private String dodgeChance;
private String dodgeChanceLucky; private String dodgeChanceLucky;
private String rollChance; private String rollChance;
private String rollChanceLucky; private String rollChanceLucky;
private String gracefulRollChance; private String gracefulRollChance;
private String gracefulRollChanceLucky; private String gracefulRollChanceLucky;
private boolean canDodge; private boolean canDodge;
private boolean canRoll; private boolean canRoll;
private boolean canGracefulRoll; private boolean canGracefulRoll;
public AcrobaticsCommand() { public AcrobaticsCommand() {
super(SkillType.ACROBATICS); super(SkillType.ACROBATICS);
} }
@Override @Override
protected void dataCalculations() { protected void dataCalculations() {
//DODGE // DODGE
String[] dodgeStrings = calculateAbilityDisplayValues(Acrobatics.dodgeMaxBonusLevel, Acrobatics.dodgeMaxChance); String[] dodgeStrings = calculateAbilityDisplayValues(Acrobatics.dodgeMaxBonusLevel, Acrobatics.dodgeMaxChance);
dodgeChance = dodgeStrings[0]; dodgeChance = dodgeStrings[0];
dodgeChanceLucky = dodgeStrings[1]; dodgeChanceLucky = dodgeStrings[1];
//ROLL // ROLL
String[] rollStrings = calculateAbilityDisplayValues(Acrobatics.rollMaxBonusLevel, Acrobatics.rollMaxChance); String[] rollStrings = calculateAbilityDisplayValues(Acrobatics.rollMaxBonusLevel, Acrobatics.rollMaxChance);
rollChance = rollStrings[0]; rollChance = rollStrings[0];
rollChanceLucky = rollStrings[1]; rollChanceLucky = rollStrings[1];
//GRACEFUL ROLL // GRACEFUL ROLL
String[] gracefulRollStrings = calculateAbilityDisplayValues(Acrobatics.gracefulRollMaxBonusLevel, Acrobatics.gracefulRollMaxChance); String[] gracefulRollStrings = calculateAbilityDisplayValues(Acrobatics.gracefulRollMaxBonusLevel, Acrobatics.gracefulRollMaxChance);
gracefulRollChance = gracefulRollStrings[0]; gracefulRollChance = gracefulRollStrings[0];
gracefulRollChanceLucky = gracefulRollStrings[1]; gracefulRollChanceLucky = gracefulRollStrings[1];
} }
@Override @Override
protected void permissionsCheck() { 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 boolean effectsHeaderPermissions() { protected boolean effectsHeaderPermissions() {
return canDodge || canGracefulRoll || canRoll; return canDodge || canGracefulRoll || canRoll;
} }
@Override @Override
protected void effectsDisplay() { protected void effectsDisplay() {
luckyEffectsDisplay(); luckyEffectsDisplay();
if (canRoll) { if (canRoll) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Acrobatics.Effect.0"), LocaleLoader.getString("Acrobatics.Effect.1"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Acrobatics.Effect.0"), LocaleLoader.getString("Acrobatics.Effect.1")));
} }
if (canGracefulRoll) { if (canGracefulRoll) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Acrobatics.Effect.2"), LocaleLoader.getString("Acrobatics.Effect.3"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Acrobatics.Effect.2"), LocaleLoader.getString("Acrobatics.Effect.3")));
} }
if (canDodge) { if (canDodge) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Acrobatics.Effect.4"), LocaleLoader.getString("Acrobatics.Effect.5"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Acrobatics.Effect.4"), LocaleLoader.getString("Acrobatics.Effect.5")));
} }
} }
@Override @Override
protected boolean statsHeaderPermissions() { protected boolean statsHeaderPermissions() {
return canDodge || canGracefulRoll || canRoll; return canDodge || canGracefulRoll || canRoll;
} }
@Override @Override
protected void statsDisplay() { protected void statsDisplay() {
if (canRoll) { if (canRoll) {
if (isLucky) { if (isLucky) {
player.sendMessage(LocaleLoader.getString("Acrobatics.Roll.Chance", new Object[] { rollChance }) + LocaleLoader.getString("Perks.lucky.bonus", new Object[] { rollChanceLucky })); player.sendMessage(LocaleLoader.getString("Acrobatics.Roll.Chance", new Object[] { rollChance }) + LocaleLoader.getString("Perks.lucky.bonus", new Object[] { rollChanceLucky }));
} }
else { else {
player.sendMessage(LocaleLoader.getString("Acrobatics.Roll.Chance", new Object[] { rollChance })); player.sendMessage(LocaleLoader.getString("Acrobatics.Roll.Chance", new Object[] { rollChance }));
} }
} }
if (canGracefulRoll) { if (canGracefulRoll) {
if (isLucky) { if (isLucky) {
player.sendMessage(LocaleLoader.getString("Acrobatics.Roll.GraceChance", new Object[] { gracefulRollChance }) + LocaleLoader.getString("Perks.lucky.bonus", new Object[] { gracefulRollChanceLucky })); player.sendMessage(LocaleLoader.getString("Acrobatics.Roll.GraceChance", new Object[] { gracefulRollChance }) + LocaleLoader.getString("Perks.lucky.bonus", new Object[] { gracefulRollChanceLucky }));
} }
else { else {
player.sendMessage(LocaleLoader.getString("Acrobatics.Roll.GraceChance", new Object[] { gracefulRollChance })); player.sendMessage(LocaleLoader.getString("Acrobatics.Roll.GraceChance", new Object[] { gracefulRollChance }));
} }
} }
if (canDodge) { if (canDodge) {
if (isLucky) { if (isLucky) {
player.sendMessage(LocaleLoader.getString("Acrobatics.DodgeChance", new Object[] { dodgeChance }) + LocaleLoader.getString("Perks.lucky.bonus", new Object[] { dodgeChanceLucky })); player.sendMessage(LocaleLoader.getString("Acrobatics.DodgeChance", new Object[] { dodgeChance }) + LocaleLoader.getString("Perks.lucky.bonus", new Object[] { dodgeChanceLucky }));
} }
else { else {
player.sendMessage(LocaleLoader.getString("Acrobatics.DodgeChance", new Object[] { dodgeChance })); player.sendMessage(LocaleLoader.getString("Acrobatics.DodgeChance", new Object[] { dodgeChance }));
} }
} }
} }
} }

View File

@ -1,104 +1,104 @@
package com.gmail.nossr50.skills.archery; package com.gmail.nossr50.commands.skills;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.skills.SkillCommand; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.skills.archery.Archery;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
public class ArcheryCommand extends SkillCommand { public class ArcheryCommand extends SkillCommand {
private String skillShotBonus; private String skillShotBonus;
private String dazeChance; private String dazeChance;
private String dazeChanceLucky; private String dazeChanceLucky;
private String retrieveChance; private String retrieveChance;
private String retrieveChanceLucky; private String retrieveChanceLucky;
private boolean canSkillShot; private boolean canSkillShot;
private boolean canDaze; private boolean canDaze;
private boolean canRetrieve; private boolean canRetrieve;
public ArcheryCommand() { public ArcheryCommand() {
super(SkillType.ARCHERY); super(SkillType.ARCHERY);
} }
@Override @Override
protected void dataCalculations() { protected void dataCalculations() {
//SKILL SHOT // SKILL SHOT
double bonus = (skillValue / Archery.skillShotIncreaseLevel) * Archery.skillShotIncreasePercentage; double bonus = (skillValue / Archery.skillShotIncreaseLevel) * Archery.skillShotIncreasePercentage;
if (bonus > Archery.skillShotMaxBonusPercentage) { if (bonus > Archery.skillShotMaxBonusPercentage) {
skillShotBonus = percent.format(Archery.skillShotMaxBonusPercentage); skillShotBonus = percent.format(Archery.skillShotMaxBonusPercentage);
} }
else { else {
skillShotBonus = percent.format(bonus); skillShotBonus = percent.format(bonus);
} }
//DAZE // DAZE
String[] dazeStrings = calculateAbilityDisplayValues(Archery.dazeMaxBonusLevel, Archery.dazeMaxBonus); String[] dazeStrings = calculateAbilityDisplayValues(Archery.dazeMaxBonusLevel, Archery.dazeMaxBonus);
dazeChance = dazeStrings[0]; dazeChance = dazeStrings[0];
dazeChanceLucky = dazeStrings[1]; dazeChanceLucky = dazeStrings[1];
//RETRIEVE // RETRIEVE
String[] retrieveStrings = calculateAbilityDisplayValues(Archery.retrieveMaxBonusLevel, Archery.retrieveMaxChance); String[] retrieveStrings = calculateAbilityDisplayValues(Archery.retrieveMaxBonusLevel, Archery.retrieveMaxChance);
retrieveChance = retrieveStrings[0]; retrieveChance = retrieveStrings[0];
retrieveChanceLucky = retrieveStrings[1]; retrieveChanceLucky = retrieveStrings[1];
} }
@Override @Override
protected void permissionsCheck() { 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 boolean effectsHeaderPermissions() { protected boolean effectsHeaderPermissions() {
return canSkillShot || canDaze || canRetrieve; return canSkillShot || canDaze || canRetrieve;
} }
@Override @Override
protected void effectsDisplay() { protected void effectsDisplay() {
luckyEffectsDisplay(); luckyEffectsDisplay();
if (canSkillShot) { if (canSkillShot) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Archery.Effect.0"), LocaleLoader.getString("Archery.Effect.1"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Archery.Effect.0"), LocaleLoader.getString("Archery.Effect.1")));
} }
if (canDaze) { if (canDaze) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Archery.Effect.2"), LocaleLoader.getString("Archery.Effect.3", Archery.dazeModifier))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Archery.Effect.2"), LocaleLoader.getString("Archery.Effect.3", Archery.dazeModifier)));
} }
if (canRetrieve) { if (canRetrieve) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Archery.Effect.4"), LocaleLoader.getString("Archery.Effect.5"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Archery.Effect.4"), LocaleLoader.getString("Archery.Effect.5")));
} }
} }
@Override @Override
protected boolean statsHeaderPermissions() { protected boolean statsHeaderPermissions() {
return canSkillShot || canDaze || canRetrieve; return canSkillShot || canDaze || canRetrieve;
} }
@Override @Override
protected void statsDisplay() { protected void statsDisplay() {
if (canSkillShot) { if (canSkillShot) {
player.sendMessage(LocaleLoader.getString("Archery.Combat.SkillshotBonus", skillShotBonus)); player.sendMessage(LocaleLoader.getString("Archery.Combat.SkillshotBonus", skillShotBonus));
} }
if (canDaze) { if (canDaze) {
if (isLucky) { if (isLucky) {
player.sendMessage(LocaleLoader.getString("Archery.Combat.DazeChance", dazeChance) + LocaleLoader.getString("Perks.lucky.bonus", dazeChanceLucky)); player.sendMessage(LocaleLoader.getString("Archery.Combat.DazeChance", dazeChance) + LocaleLoader.getString("Perks.lucky.bonus", dazeChanceLucky));
} }
else { else {
player.sendMessage(LocaleLoader.getString("Archery.Combat.DazeChance", dazeChance)); player.sendMessage(LocaleLoader.getString("Archery.Combat.DazeChance", dazeChance));
} }
} }
if (canRetrieve) { if (canRetrieve) {
if (isLucky) { if (isLucky) {
player.sendMessage(LocaleLoader.getString("Archery.Combat.RetrieveChance", retrieveChance) + LocaleLoader.getString("Perks.lucky.bonus", retrieveChanceLucky)); player.sendMessage(LocaleLoader.getString("Archery.Combat.RetrieveChance", retrieveChance) + LocaleLoader.getString("Perks.lucky.bonus", retrieveChanceLucky));
} }
else { else {
player.sendMessage(LocaleLoader.getString("Archery.Combat.RetrieveChance", retrieveChance)); player.sendMessage(LocaleLoader.getString("Archery.Combat.RetrieveChance", retrieveChance));
} }
} }
} }
} }

View File

@ -1,128 +1,128 @@
package com.gmail.nossr50.skills.axes; package com.gmail.nossr50.commands.skills;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.skills.SkillCommand; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.skills.axes.Axes;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
public class AxesCommand extends SkillCommand { public class AxesCommand extends SkillCommand {
private String critChance; private String critChance;
private String critChanceLucky; private String critChanceLucky;
private String bonusDamage; private String bonusDamage;
private String impactDamage; private String impactDamage;
private String greaterImpactDamage; private String greaterImpactDamage;
private String skullSplitterLength; private String skullSplitterLength;
private String skullSplitterLengthEndurance; private String skullSplitterLengthEndurance;
private boolean canSkullSplitter; private boolean canSkullSplitter;
private boolean canCritical; private boolean canCritical;
private boolean canBonusDamage; private boolean canBonusDamage;
private boolean canImpact; private boolean canImpact;
private boolean canGreaterImpact; private boolean canGreaterImpact;
public AxesCommand() { public AxesCommand() {
super(SkillType.AXES); super(SkillType.AXES);
} }
@Override @Override
protected void dataCalculations() { protected void dataCalculations() {
//IMPACT // IMPACT
impactDamage = String.valueOf(1 + (skillValue / Axes.impactIncreaseLevel)); impactDamage = String.valueOf(1 + (skillValue / Axes.impactIncreaseLevel));
greaterImpactDamage = String.valueOf(Axes.greaterImpactBonusDamage); greaterImpactDamage = String.valueOf(Axes.greaterImpactBonusDamage);
//SKULL SPLITTER // SKULL SPLITTER
String[] skullSplitterStrings = calculateLengthDisplayValues(); String[] skullSplitterStrings = calculateLengthDisplayValues();
skullSplitterLength = skullSplitterStrings[0]; skullSplitterLength = skullSplitterStrings[0];
skullSplitterLengthEndurance = skullSplitterStrings[1]; skullSplitterLengthEndurance = skullSplitterStrings[1];
//CRITICAL STRIKES // CRITICAL STRIKES
String[] criticalStrikeStrings = calculateAbilityDisplayValues(Axes.criticalHitMaxBonusLevel, Axes.criticalHitMaxChance); String[] criticalStrikeStrings = calculateAbilityDisplayValues(Axes.criticalHitMaxBonusLevel, Axes.criticalHitMaxChance);
critChance = criticalStrikeStrings[0]; critChance = criticalStrikeStrings[0];
critChanceLucky = criticalStrikeStrings[1]; critChanceLucky = criticalStrikeStrings[1];
//AXE MASTERY // AXE MASTERY
if (skillValue >= Axes.bonusDamageMaxBonusLevel) { if (skillValue >= Axes.bonusDamageMaxBonusLevel) {
bonusDamage = String.valueOf(Axes.bonusDamageMaxBonus); bonusDamage = String.valueOf(Axes.bonusDamageMaxBonus);
} }
else { else {
bonusDamage = String.valueOf(skillValue / (Axes.bonusDamageMaxBonusLevel / Axes.bonusDamageMaxBonus)); bonusDamage = String.valueOf(skillValue / (Axes.bonusDamageMaxBonusLevel / Axes.bonusDamageMaxBonus));
} }
} }
@Override @Override
protected void permissionsCheck() { 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);
canImpact = Permissions.armorImpact(player); canImpact = Permissions.armorImpact(player);
canGreaterImpact = Permissions.greaterImpact(player); canGreaterImpact = Permissions.greaterImpact(player);
} }
@Override @Override
protected boolean effectsHeaderPermissions() { protected boolean effectsHeaderPermissions() {
return canSkullSplitter || canCritical || canBonusDamage || canImpact || canGreaterImpact; return canSkullSplitter || canCritical || canBonusDamage || canImpact || canGreaterImpact;
} }
@Override @Override
protected void effectsDisplay() { protected void effectsDisplay() {
luckyEffectsDisplay(); luckyEffectsDisplay();
if (canSkullSplitter) { if (canSkullSplitter) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Axes.Effect.0"), LocaleLoader.getString("Axes.Effect.1"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Axes.Effect.0"), LocaleLoader.getString("Axes.Effect.1")));
} }
if (canCritical) { if (canCritical) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Axes.Effect.2"), LocaleLoader.getString("Axes.Effect.3"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Axes.Effect.2"), LocaleLoader.getString("Axes.Effect.3")));
} }
if (canBonusDamage) { if (canBonusDamage) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Axes.Effect.4"), LocaleLoader.getString("Axes.Effect.5"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Axes.Effect.4"), LocaleLoader.getString("Axes.Effect.5")));
} }
if (canImpact) { if (canImpact) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Axes.Effect.6"), LocaleLoader.getString("Axes.Effect.7"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Axes.Effect.6"), LocaleLoader.getString("Axes.Effect.7")));
} }
if (canGreaterImpact) { if (canGreaterImpact) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Axes.Effect.8"), LocaleLoader.getString("Axes.Effect.9"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Axes.Effect.8"), LocaleLoader.getString("Axes.Effect.9")));
} }
} }
@Override @Override
protected boolean statsHeaderPermissions() { protected boolean statsHeaderPermissions() {
return canSkullSplitter || canCritical || canBonusDamage || canImpact || canGreaterImpact; return canSkullSplitter || canCritical || canBonusDamage || canImpact || canGreaterImpact;
} }
@Override @Override
protected void statsDisplay() { protected void statsDisplay() {
if (canBonusDamage) { if (canBonusDamage) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Axes.Ability.Bonus.0"), LocaleLoader.getString("Axes.Ability.Bonus.1", bonusDamage))); player.sendMessage(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Axes.Ability.Bonus.0"), LocaleLoader.getString("Axes.Ability.Bonus.1", bonusDamage)));
} }
if (canImpact) { if (canImpact) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Axes.Ability.Bonus.2"), LocaleLoader.getString("Axes.Ability.Bonus.3", impactDamage))); player.sendMessage(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Axes.Ability.Bonus.2"), LocaleLoader.getString("Axes.Ability.Bonus.3", impactDamage)));
} }
if (canGreaterImpact) { if (canGreaterImpact) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Axes.Ability.Bonus.4"), LocaleLoader.getString("Axes.Ability.Bonus.5", greaterImpactDamage))); player.sendMessage(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Axes.Ability.Bonus.4"), LocaleLoader.getString("Axes.Ability.Bonus.5", greaterImpactDamage)));
} }
if (canCritical) { if (canCritical) {
if (isLucky) { if (isLucky) {
player.sendMessage(LocaleLoader.getString("Axes.Combat.CritChance", critChance) + LocaleLoader.getString("Perks.lucky.bonus", critChanceLucky)); player.sendMessage(LocaleLoader.getString("Axes.Combat.CritChance", critChance) + LocaleLoader.getString("Perks.lucky.bonus", critChanceLucky));
} }
else { else {
player.sendMessage(LocaleLoader.getString("Axes.Combat.CritChance", critChance)); player.sendMessage(LocaleLoader.getString("Axes.Combat.CritChance", critChance));
} }
} }
if (canSkullSplitter) { if (canSkullSplitter) {
if (hasEndurance) { if (hasEndurance) {
player.sendMessage(LocaleLoader.getString("Axes.Combat.SS.Length", skullSplitterLength) + LocaleLoader.getString("Perks.activationtime.bonus", skullSplitterLengthEndurance)); player.sendMessage(LocaleLoader.getString("Axes.Combat.SS.Length", skullSplitterLength) + LocaleLoader.getString("Perks.activationtime.bonus", skullSplitterLengthEndurance));
} }
else { else {
player.sendMessage(LocaleLoader.getString("Axes.Combat.SS.Length", skullSplitterLength)); player.sendMessage(LocaleLoader.getString("Axes.Combat.SS.Length", skullSplitterLength));
} }
} }
} }
} }

View File

@ -1,67 +1,66 @@
package com.gmail.nossr50.skills.excavation; package com.gmail.nossr50.commands.skills;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.skills.SkillCommand; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Permissions;
public class ExcavationCommand extends SkillCommand {
public class ExcavationCommand extends SkillCommand { private String gigaDrillBreakerLength;
private String gigaDrillBreakerLength; private String gigaDrillBreakerLengthEndurance;
private String gigaDrillBreakerLengthEndurance;
private boolean canGigaDrill;
private boolean canGigaDrill; private boolean canTreasureHunt;
private boolean canTreasureHunt;
public ExcavationCommand() {
public ExcavationCommand() { super(SkillType.EXCAVATION);
super(SkillType.EXCAVATION); }
}
@Override
@Override protected void dataCalculations() {
protected void dataCalculations() { // GIGA DRILL BREAKER
//GIGA DRILL BREAKER String gigaDrillStrings[] = calculateLengthDisplayValues();
String gigaDrillStrings[] = calculateLengthDisplayValues(); gigaDrillBreakerLength = gigaDrillStrings[0];
gigaDrillBreakerLength = gigaDrillStrings[0]; gigaDrillBreakerLengthEndurance = gigaDrillStrings[1];
gigaDrillBreakerLengthEndurance = gigaDrillStrings[1]; }
}
@Override
@Override protected void permissionsCheck() {
protected void permissionsCheck() { canGigaDrill = Permissions.gigaDrillBreaker(player);
canGigaDrill = Permissions.gigaDrillBreaker(player); canTreasureHunt = Permissions.excavationTreasureHunter(player);
canTreasureHunt = Permissions.excavationTreasureHunter(player); }
}
@Override
@Override protected boolean effectsHeaderPermissions() {
protected boolean effectsHeaderPermissions() { return canGigaDrill || canTreasureHunt;
return canGigaDrill || canTreasureHunt; }
}
@Override
@Override protected void effectsDisplay() {
protected void effectsDisplay() { luckyEffectsDisplay();
luckyEffectsDisplay();
if (canGigaDrill) {
if (canGigaDrill) { player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Excavation.Effect.0"), LocaleLoader.getString("Excavation.Effect.1")));
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Excavation.Effect.0"), LocaleLoader.getString("Excavation.Effect.1"))); }
}
if (canTreasureHunt) {
if (canTreasureHunt) { player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Excavation.Effect.2"), LocaleLoader.getString("Excavation.Effect.3")));
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Excavation.Effect.2"), LocaleLoader.getString("Excavation.Effect.3"))); }
} }
}
@Override
@Override protected boolean statsHeaderPermissions() {
protected boolean statsHeaderPermissions() { return canGigaDrill;
return canGigaDrill; }
}
@Override
@Override protected void statsDisplay() {
protected void statsDisplay() { if (canGigaDrill) {
if (canGigaDrill) { if (hasEndurance) {
if (hasEndurance) { player.sendMessage(LocaleLoader.getString("Excavation.Effect.Length", gigaDrillBreakerLength) + LocaleLoader.getString("Perks.activationtime.bonus", gigaDrillBreakerLengthEndurance));
player.sendMessage(LocaleLoader.getString("Excavation.Effect.Length", gigaDrillBreakerLength) + LocaleLoader.getString("Perks.activationtime.bonus", gigaDrillBreakerLengthEndurance)); }
} else {
else { player.sendMessage(LocaleLoader.getString("Excavation.Effect.Length", gigaDrillBreakerLength));
player.sendMessage(LocaleLoader.getString("Excavation.Effect.Length", gigaDrillBreakerLength)); }
} }
} }
} }
}

View File

@ -1,124 +1,125 @@
package com.gmail.nossr50.skills.fishing; package com.gmail.nossr50.commands.skills;
import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.skills.SkillCommand; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.skills.fishing.Fishing;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager;
public class FishingCommand extends SkillCommand {
private int lootTier; public class FishingCommand extends SkillCommand {
private String magicChance; private int lootTier;
private String magicChanceLucky; private String magicChance;
private String chanceRaining = ""; private String magicChanceLucky;
private String shakeChance; private String chanceRaining = "";
private String shakeChanceLucky; private String shakeChance;
private String fishermansDietRank; private String shakeChanceLucky;
private String fishermansDietRank;
private boolean canTreasureHunt;
private boolean canMagicHunt; private boolean canTreasureHunt;
private boolean canShake; private boolean canMagicHunt;
private boolean canFishermansDiet; private boolean canShake;
private boolean canFishermansDiet;
public FishingCommand() {
super(SkillType.FISHING); public FishingCommand() {
} super(SkillType.FISHING);
}
@Override
protected void dataCalculations() { @Override
lootTier = Fishing.getLootTier((int) skillValue); protected void dataCalculations() {
lootTier = UserManager.getPlayer(player).getFishingManager().getLootTier();
//TREASURE HUNTER
double enchantChance = lootTier * AdvancedConfig.getInstance().getFishingMagicMultiplier(); // TREASURE HUNTER
double enchantChance = lootTier * AdvancedConfig.getInstance().getFishingMagicMultiplier();
if (player.getWorld().hasStorm()) {
chanceRaining = LocaleLoader.getString("Fishing.Chance.Raining"); if (player.getWorld().hasStorm()) {
enchantChance = enchantChance * 1.1D; chanceRaining = LocaleLoader.getString("Fishing.Chance.Raining");
} enchantChance = enchantChance * 1.1D;
}
String[] treasureHunterStrings = calculateAbilityDisplayValues(enchantChance);
magicChance = treasureHunterStrings[0]; String[] treasureHunterStrings = calculateAbilityDisplayValues(enchantChance);
magicChanceLucky = treasureHunterStrings[1]; magicChance = treasureHunterStrings[0];
magicChanceLucky = treasureHunterStrings[1];
//SHAKE
String[] shakeStrings = calculateAbilityDisplayValues(ShakeMob.getShakeProbability((int) skillValue)); // SHAKE
shakeChance = shakeStrings[0]; String[] shakeStrings = calculateAbilityDisplayValues(UserManager.getPlayer(player).getFishingManager().getShakeProbability());
shakeChance = shakeStrings[0];
shakeChanceLucky = shakeStrings[1]; shakeChanceLucky = shakeStrings[1];
//FISHERMAN'S DIET // FISHERMAN'S DIET
fishermansDietRank = calculateRank(Fishing.fishermansDietMaxLevel, Fishing.fishermansDietRankLevel1); fishermansDietRank = calculateRank(Fishing.fishermansDietMaxLevel, Fishing.fishermansDietRankLevel1);
} }
@Override @Override
protected void permissionsCheck() { 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);
canFishermansDiet = Permissions.fishermansDiet(player); canFishermansDiet = Permissions.fishermansDiet(player);
} }
@Override @Override
protected boolean effectsHeaderPermissions() { protected boolean effectsHeaderPermissions() {
return canTreasureHunt || canMagicHunt || canShake; return canTreasureHunt || canMagicHunt || canShake;
} }
@Override @Override
protected void effectsDisplay() { protected void effectsDisplay() {
luckyEffectsDisplay(); luckyEffectsDisplay();
if (canTreasureHunt) { if (canTreasureHunt) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Fishing.Effect.0"), LocaleLoader.getString("Fishing.Effect.1"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Fishing.Effect.0"), LocaleLoader.getString("Fishing.Effect.1")));
} }
if (canMagicHunt) { if (canMagicHunt) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Fishing.Effect.2"), LocaleLoader.getString("Fishing.Effect.3"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Fishing.Effect.2"), LocaleLoader.getString("Fishing.Effect.3")));
} }
if (canShake) { if (canShake) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Fishing.Effect.4"), LocaleLoader.getString("Fishing.Effect.5"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Fishing.Effect.4"), LocaleLoader.getString("Fishing.Effect.5")));
} }
if (canFishermansDiet) { if (canFishermansDiet) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Fishing.Effect.6"), LocaleLoader.getString("Fishing.Effect.7"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Fishing.Effect.6"), LocaleLoader.getString("Fishing.Effect.7")));
} }
} }
@Override @Override
protected boolean statsHeaderPermissions() { protected boolean statsHeaderPermissions() {
return canTreasureHunt || canMagicHunt || canShake; return canTreasureHunt || canMagicHunt || canShake;
} }
@Override @Override
protected void statsDisplay() { protected void statsDisplay() {
if (canTreasureHunt) { if (canTreasureHunt) {
player.sendMessage(LocaleLoader.getString("Fishing.Ability.Rank", lootTier)); player.sendMessage(LocaleLoader.getString("Fishing.Ability.Rank", lootTier));
} }
if (canMagicHunt) { if (canMagicHunt) {
if (isLucky) { if (isLucky) {
player.sendMessage(LocaleLoader.getString("Fishing.Enchant.Chance", magicChance) + chanceRaining + LocaleLoader.getString("Perks.lucky.bonus", magicChanceLucky)); player.sendMessage(LocaleLoader.getString("Fishing.Enchant.Chance", magicChance) + chanceRaining + LocaleLoader.getString("Perks.lucky.bonus", magicChanceLucky));
} }
else { else {
player.sendMessage(LocaleLoader.getString("Fishing.Enchant.Chance", magicChance) + chanceRaining); player.sendMessage(LocaleLoader.getString("Fishing.Enchant.Chance", magicChance) + chanceRaining);
} }
} }
if (canShake) { if (canShake) {
if (skillValue < AdvancedConfig.getInstance().getShakeUnlockLevel()) { if (skillValue < AdvancedConfig.getInstance().getShakeUnlockLevel()) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Fishing.Ability.Locked.0", AdvancedConfig.getInstance().getShakeUnlockLevel()))); player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Fishing.Ability.Locked.0", AdvancedConfig.getInstance().getShakeUnlockLevel())));
} }
else { else {
if (isLucky) { if (isLucky) {
player.sendMessage(LocaleLoader.getString("Fishing.Ability.Shake", shakeChance) + LocaleLoader.getString("Perks.lucky.bonus", shakeChanceLucky)); player.sendMessage(LocaleLoader.getString("Fishing.Ability.Shake", shakeChance) + LocaleLoader.getString("Perks.lucky.bonus", shakeChanceLucky));
} }
else { else {
player.sendMessage(LocaleLoader.getString("Fishing.Ability.Shake", shakeChance)); player.sendMessage(LocaleLoader.getString("Fishing.Ability.Shake", shakeChance));
} }
} }
} }
if (canFishermansDiet) { if (canFishermansDiet) {
player.sendMessage(LocaleLoader.getString("Fishing.Ability.FD", fishermansDietRank)); player.sendMessage(LocaleLoader.getString("Fishing.Ability.FD", fishermansDietRank));
} }
} }
} }

View File

@ -1,157 +1,180 @@
package com.gmail.nossr50.skills.herbalism; package com.gmail.nossr50.commands.skills;
import org.bukkit.Material; import org.bukkit.Material;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.skills.SkillCommand; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.skills.herbalism.Herbalism;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
public class HerbalismCommand extends SkillCommand { public class HerbalismCommand extends SkillCommand {
private String greenTerraLength; private String greenTerraLength;
private String greenTerraLengthEndurance; private String greenTerraLengthEndurance;
private String greenThumbChance; private String greenThumbChance;
private String greenThumbChanceLucky; private String greenThumbChanceLucky;
private String greenThumbStage; private String greenThumbStage;
private String farmersDietRank; private String farmersDietRank;
private String doubleDropChance; private String doubleDropChance;
private String doubleDropChanceLucky; private String doubleDropChanceLucky;
private String hylianLuckChance; private String hylianLuckChance;
private String hylianLuckChanceLucky; private String hylianLuckChanceLucky;
private String shroomThumbChance;
private boolean hasHylianLuck; private String shroomThumbChanceLucky;
private boolean canGreenTerra;
private boolean canGreenThumbWheat; private boolean hasHylianLuck;
private boolean canGreenThumbBlocks; private boolean canGreenTerra;
private boolean canFarmersDiet; private boolean canGreenThumbWheat;
private boolean canDoubleDrop; private boolean canGreenThumbBlocks;
private boolean doubleDropsDisabled; private boolean canFarmersDiet;
private boolean canDoubleDrop;
public HerbalismCommand() { private boolean canShroomThumb;
super(SkillType.HERBALISM); private boolean doubleDropsDisabled;
}
public HerbalismCommand() {
@Override super(SkillType.HERBALISM);
protected void dataCalculations() { }
//GREEN TERRA
String[] greenTerraStrings = calculateLengthDisplayValues(); @Override
greenTerraLength = greenTerraStrings[0]; protected void dataCalculations() {
greenTerraLengthEndurance = greenTerraStrings[1]; // GREEN TERRA
String[] greenTerraStrings = calculateLengthDisplayValues();
//FARMERS DIET greenTerraLength = greenTerraStrings[0];
farmersDietRank = calculateRank(Herbalism.farmersDietMaxLevel, Herbalism.farmersDietRankLevel1); greenTerraLengthEndurance = greenTerraStrings[1];
//GREEN THUMB // FARMERS DIET
greenThumbStage = calculateRank(Herbalism.greenThumbStageMaxLevel, Herbalism.greenThumbStageChangeLevel); farmersDietRank = calculateRank(Herbalism.farmersDietMaxLevel, Herbalism.farmersDietRankLevel1);
String[] greenThumbStrings = calculateAbilityDisplayValues(Herbalism.greenThumbMaxLevel, Herbalism.greenThumbMaxChance); // GREEN THUMB
greenThumbChance = greenThumbStrings[0]; greenThumbStage = calculateRank(Herbalism.greenThumbStageMaxLevel, Herbalism.greenThumbStageChangeLevel);
greenThumbChanceLucky = greenThumbStrings[1];
String[] greenThumbStrings = calculateAbilityDisplayValues(Herbalism.greenThumbMaxLevel, Herbalism.greenThumbMaxChance);
//DOUBLE DROPS greenThumbChance = greenThumbStrings[0];
String[] doubleDropStrings = calculateAbilityDisplayValues(Herbalism.doubleDropsMaxLevel, Herbalism.doubleDropsMaxChance); greenThumbChanceLucky = greenThumbStrings[1];
doubleDropChance = doubleDropStrings[0];
doubleDropChanceLucky = doubleDropStrings[1]; // DOUBLE DROPS
String[] doubleDropStrings = calculateAbilityDisplayValues(Herbalism.doubleDropsMaxLevel, Herbalism.doubleDropsMaxChance);
//HYLIAN LUCK doubleDropChance = doubleDropStrings[0];
String[] hylianLuckStrings = calculateAbilityDisplayValues(Herbalism.hylianLuckMaxLevel, Herbalism.hylianLuckMaxChance); doubleDropChanceLucky = doubleDropStrings[1];
hylianLuckChance = hylianLuckStrings[0];
hylianLuckChanceLucky = hylianLuckStrings[1]; // HYLIAN LUCK
} String[] hylianLuckStrings = calculateAbilityDisplayValues(Herbalism.hylianLuckMaxLevel, Herbalism.hylianLuckMaxChance);
hylianLuckChance = hylianLuckStrings[0];
@Override hylianLuckChanceLucky = hylianLuckStrings[1];
protected void permissionsCheck() {
hasHylianLuck = Permissions.hylianLuck(player); // SHROOM THUMB
canGreenTerra = Permissions.greenTerra(player); String[] shroomThumbStrings = calculateAbilityDisplayValues(Herbalism.shroomThumbMaxLevel, Herbalism.shroomThumbMaxChance);
canGreenThumbWheat = Permissions.greenThumbPlant(player, Material.CROPS); //TODO: This isn't really accurate - they could have perms for other crops but not wheat. shroomThumbChance = shroomThumbStrings[0];
canGreenThumbBlocks = (Permissions.greenThumbBlock(player, Material.DIRT) || Permissions.greenThumbBlock(player, Material.COBBLESTONE) || Permissions.greenThumbBlock(player, Material.COBBLE_WALL) || Permissions.greenThumbBlock(player, Material.SMOOTH_BRICK)); shroomThumbChanceLucky = shroomThumbStrings[1];
canFarmersDiet = Permissions.farmersDiet(player); }
canDoubleDrop = Permissions.doubleDrops(player, skill);
doubleDropsDisabled = skill.getDoubleDropsDisabled(); @Override
} protected void permissionsCheck() {
hasHylianLuck = Permissions.hylianLuck(player);
@Override canGreenTerra = Permissions.greenTerra(player);
protected boolean effectsHeaderPermissions() { canGreenThumbWheat = Permissions.greenThumbPlant(player, Material.CROPS); // TODO: This isn't really accurate - they could have perms for other crops but not wheat.
return canGreenTerra || (canDoubleDrop && !doubleDropsDisabled) || canFarmersDiet || canGreenThumbBlocks || canGreenThumbWheat; canGreenThumbBlocks = (Permissions.greenThumbBlock(player, Material.DIRT) || Permissions.greenThumbBlock(player, Material.COBBLESTONE) || Permissions.greenThumbBlock(player, Material.COBBLE_WALL) || Permissions.greenThumbBlock(player, Material.SMOOTH_BRICK));
} canFarmersDiet = Permissions.farmersDiet(player);
canDoubleDrop = Permissions.doubleDrops(player, skill);
@Override doubleDropsDisabled = skill.getDoubleDropsDisabled();
protected void effectsDisplay() { canShroomThumb = Permissions.shroomThumb(player);
luckyEffectsDisplay(); }
if (canGreenTerra) { @Override
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.0"), LocaleLoader.getString("Herbalism.Effect.1"))); protected boolean effectsHeaderPermissions() {
} return canGreenTerra || (canDoubleDrop && !doubleDropsDisabled) || canFarmersDiet || canGreenThumbBlocks || canGreenThumbWheat || canShroomThumb;
}
if (canGreenThumbWheat) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.2"), LocaleLoader.getString("Herbalism.Effect.3"))); @Override
} protected void effectsDisplay() {
luckyEffectsDisplay();
if (canGreenThumbBlocks) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.4"), LocaleLoader.getString("Herbalism.Effect.5"))); if (canGreenTerra) {
} player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.0"), LocaleLoader.getString("Herbalism.Effect.1")));
}
if (canFarmersDiet) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.6"), LocaleLoader.getString("Herbalism.Effect.7"))); if (canGreenThumbWheat) {
} player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.2"), LocaleLoader.getString("Herbalism.Effect.3")));
}
if (hasHylianLuck) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.10"), LocaleLoader.getString("Herbalism.Effect.11"))); if (canGreenThumbBlocks) {
} player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.4"), LocaleLoader.getString("Herbalism.Effect.5")));
}
if (canDoubleDrop && !doubleDropsDisabled) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.8"), LocaleLoader.getString("Herbalism.Effect.9"))); if (canFarmersDiet) {
} player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.6"), LocaleLoader.getString("Herbalism.Effect.7")));
} }
@Override if (hasHylianLuck) {
protected boolean statsHeaderPermissions() { player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.10"), LocaleLoader.getString("Herbalism.Effect.11")));
return canGreenTerra || (canDoubleDrop && !doubleDropsDisabled) || canFarmersDiet || canGreenThumbBlocks || canGreenThumbWheat; }
}
if (canShroomThumb) {
@Override player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.12"), LocaleLoader.getString("Herbalism.Effect.13")));
protected void statsDisplay() { }
if (canGreenTerra) {
if (hasEndurance) { if (canDoubleDrop && !doubleDropsDisabled) {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTe.Length", greenTerraLength) + LocaleLoader.getString("Perks.activationtime.bonus", greenTerraLengthEndurance)); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.8"), LocaleLoader.getString("Herbalism.Effect.9")));
} }
else { }
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTe.Length", greenTerraLength));
} @Override
} protected boolean statsHeaderPermissions() {
return canGreenTerra || (canDoubleDrop && !doubleDropsDisabled) || canFarmersDiet || canGreenThumbBlocks || canGreenThumbWheat || canShroomThumb;
if (canGreenThumbBlocks || canGreenThumbWheat) { }
if (isLucky) {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTh.Chance", greenThumbChance) + LocaleLoader.getString("Perks.lucky.bonus", greenThumbChanceLucky)); @Override
} protected void statsDisplay() {
else { if (canGreenTerra) {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTh.Chance", greenThumbChance)); if (hasEndurance) {
} player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTe.Length", greenTerraLength) + LocaleLoader.getString("Perks.activationtime.bonus", greenTerraLengthEndurance));
} }
else {
if (canGreenThumbWheat) { player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTe.Length", greenTerraLength));
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTh.Stage", greenThumbStage)); }
} }
if (canFarmersDiet) { if (canGreenThumbBlocks || canGreenThumbWheat) {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.FD", farmersDietRank)); if (isLucky) {
} player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTh.Chance", greenThumbChance) + LocaleLoader.getString("Perks.lucky.bonus", greenThumbChanceLucky));
}
if (hasHylianLuck) { else {
if (isLucky) { player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTh.Chance", greenThumbChance));
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.HylianLuck", hylianLuckChance) + LocaleLoader.getString("Perks.lucky.bonus", hylianLuckChanceLucky)); }
} }
else {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.HylianLuck", hylianLuckChance)); if (canGreenThumbWheat) {
} player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTh.Stage", greenThumbStage));
} }
if (canDoubleDrop && !doubleDropsDisabled) {
if (isLucky) { if (canFarmersDiet) {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.DoubleDropChance", doubleDropChance) + LocaleLoader.getString("Perks.lucky.bonus", doubleDropChanceLucky)); player.sendMessage(LocaleLoader.getString("Herbalism.Ability.FD", farmersDietRank));
} }
else {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.DoubleDropChance", doubleDropChance)); if (hasHylianLuck) {
} if (isLucky) {
} player.sendMessage(LocaleLoader.getString("Herbalism.Ability.HylianLuck", hylianLuckChance) + LocaleLoader.getString("Perks.lucky.bonus", hylianLuckChanceLucky));
} }
} else {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.HylianLuck", hylianLuckChance));
}
}
if (canShroomThumb) {
if (isLucky) {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.ShroomThumb.Chance", shroomThumbChance) + LocaleLoader.getString("Perks.lucky.bonus", shroomThumbChanceLucky));
}
else {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.ShroomThumb.Chance", shroomThumbChance));
}
}
if (canDoubleDrop && !doubleDropsDisabled) {
if (isLucky) {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.DoubleDropChance", doubleDropChance) + LocaleLoader.getString("Perks.lucky.bonus", doubleDropChanceLucky));
}
else {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.DoubleDropChance", doubleDropChance));
}
}
}
}

View File

@ -1,180 +1,149 @@
package com.gmail.nossr50.skills.mining; package com.gmail.nossr50.commands.skills;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.skills.SkillCommand; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.skills.mining.Mining;
import com.gmail.nossr50.skills.mining.MiningManager;
public class MiningCommand extends SkillCommand { import com.gmail.nossr50.util.Permissions;
private String doubleDropChance; import com.gmail.nossr50.util.player.UserManager;
private String doubleDropChanceLucky;
private String superBreakerLength; public class MiningCommand extends SkillCommand {
private String superBreakerLengthEndurance; private String doubleDropChance;
private String blastMiningRank; private String doubleDropChanceLucky;
private String blastRadiusIncrease; private String superBreakerLength;
private String blastDamageDecrease; private String superBreakerLengthEndurance;
private boolean canSuperBreaker; private int blastMiningRank;
private boolean canDoubleDrop; private int bonusTNTDrops;
private boolean canBlast; private double blastRadiusIncrease;
private boolean canBiggerBombs; private String oreBonus;
private boolean canDemoExpert; private String debrisReduction;
private boolean doubleDropsDisabled; private String blastDamageDecrease;
public MiningCommand() { private boolean canSuperBreaker;
super(SkillType.MINING); private boolean canDoubleDrop;
} private boolean canBlast;
private boolean canBiggerBombs;
@Override private boolean canDemoExpert;
protected void dataCalculations() { private boolean doubleDropsDisabled;
//SUPER BREAKER
String[] superBreakerStrings = calculateLengthDisplayValues(); public MiningCommand() {
superBreakerLength = superBreakerStrings[0]; super(SkillType.MINING);
superBreakerLengthEndurance = superBreakerStrings[1]; }
//DOUBLE DROPS @Override
String[] doubleDropStrings = calculateAbilityDisplayValues(Mining.doubleDropsMaxLevel, Mining.doubleDropsMaxChance); protected void dataCalculations() {
doubleDropChance = doubleDropStrings[0]; // SUPER BREAKER
doubleDropChanceLucky = doubleDropStrings[1]; String[] superBreakerStrings = calculateLengthDisplayValues();
superBreakerLength = superBreakerStrings[0];
//BLAST MINING superBreakerLengthEndurance = superBreakerStrings[1];
if (skillValue >= BlastMining.rank8) {
blastMiningRank = "8"; // DOUBLE DROPS
blastDamageDecrease = "100.00%"; String[] doubleDropStrings = calculateAbilityDisplayValues(Mining.doubleDropsMaxLevel, Mining.doubleDropsMaxChance);
blastRadiusIncrease = "4"; doubleDropChance = doubleDropStrings[0];
} doubleDropChanceLucky = doubleDropStrings[1];
else if (skillValue >= BlastMining.rank7) {
blastMiningRank = "7"; // BLAST MINING
blastDamageDecrease = "50.00%"; MiningManager miningManager = UserManager.getPlayer(player).getMiningManager();
blastRadiusIncrease = "3"; blastMiningRank = miningManager.getBlastMiningTier();
} bonusTNTDrops = miningManager.getDropMultiplier();
else if (skillValue >= BlastMining.rank6) { oreBonus = percent.format(miningManager.getOreBonus() / 30.0D); // Base received in TNT is 30%
blastMiningRank = "6"; debrisReduction = percent.format(miningManager.getDebrisReduction() / 30.0D); // Base received in TNT is 30%
blastDamageDecrease = "50.00%"; blastDamageDecrease = percent.format(miningManager.getBlastDamageModifier() / 100.0D);
blastRadiusIncrease = "3"; blastRadiusIncrease = miningManager.getBlastRadiusModifier();
} }
else if (skillValue >= BlastMining.rank5) {
blastMiningRank = "5"; @Override
blastDamageDecrease = "25.00%"; protected void permissionsCheck() {
blastRadiusIncrease = "2"; canBiggerBombs = Permissions.biggerBombs(player);
} canBlast = Permissions.remoteDetonation(player);
else if (skillValue >= BlastMining.rank4) { canDemoExpert = Permissions.demolitionsExpertise(player);
blastMiningRank = "4"; canDoubleDrop = Permissions.doubleDrops(player, skill);
blastDamageDecrease = "25.00%"; canSuperBreaker = Permissions.superBreaker(player);
blastRadiusIncrease = "2"; doubleDropsDisabled = skill.getDoubleDropsDisabled();
} }
else if (skillValue >= BlastMining.rank3) {
blastMiningRank = "3"; @Override
blastDamageDecrease = "0.00%"; protected boolean effectsHeaderPermissions() {
blastRadiusIncrease = "1"; return canBiggerBombs || canBlast || canDemoExpert || (canDoubleDrop && !doubleDropsDisabled) || canSuperBreaker;
} }
else if (skillValue >= BlastMining.rank2) {
blastMiningRank = "2"; @Override
blastDamageDecrease = "0.00%"; protected void effectsDisplay() {
blastRadiusIncrease = "1"; luckyEffectsDisplay();
}
else if (skillValue >= BlastMining.rank1) { if (canSuperBreaker) {
blastMiningRank = "1"; player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Mining.Effect.0"), LocaleLoader.getString("Mining.Effect.1")));
blastDamageDecrease = "0.00%"; }
blastRadiusIncrease = "0";
} if (canDoubleDrop && !doubleDropsDisabled) {
else { player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Mining.Effect.2"), LocaleLoader.getString("Mining.Effect.3")));
blastMiningRank = "0"; }
blastDamageDecrease = "0.00%";
blastRadiusIncrease = "0"; if (canBlast) {
} player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Mining.Effect.4"), LocaleLoader.getString("Mining.Effect.5")));
} }
@Override if (canBiggerBombs) {
protected void permissionsCheck() { player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Mining.Effect.6"), LocaleLoader.getString("Mining.Effect.7")));
canBiggerBombs = Permissions.biggerBombs(player); }
canBlast = Permissions.remoteDetonation(player);
canDemoExpert = Permissions.demolitionsExpertise(player); if (canDemoExpert) {
canDoubleDrop = Permissions.doubleDrops(player, skill); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Mining.Effect.8"), LocaleLoader.getString("Mining.Effect.9")));
canSuperBreaker = Permissions.superBreaker(player); }
doubleDropsDisabled = skill.getDoubleDropsDisabled(); }
}
@Override
@Override protected boolean statsHeaderPermissions() {
protected boolean effectsHeaderPermissions() { return canBiggerBombs || canBlast || canDemoExpert || (canDoubleDrop && !doubleDropsDisabled) || canSuperBreaker;
return canBiggerBombs || canBlast || canDemoExpert || (canDoubleDrop && !doubleDropsDisabled) || canSuperBreaker; }
}
@Override
@Override protected void statsDisplay() {
protected void effectsDisplay() { if (canDoubleDrop && !doubleDropsDisabled) {
luckyEffectsDisplay(); if (isLucky) {
player.sendMessage(LocaleLoader.getString("Mining.Effect.DropChance", doubleDropChance) + LocaleLoader.getString("Perks.lucky.bonus", doubleDropChanceLucky));
if (canSuperBreaker) { }
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Mining.Effect.0"), LocaleLoader.getString("Mining.Effect.1"))); else {
} player.sendMessage(LocaleLoader.getString("Mining.Effect.DropChance", doubleDropChance));
}
if (canDoubleDrop && !doubleDropsDisabled) { }
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Mining.Effect.2"), LocaleLoader.getString("Mining.Effect.3")));
} if (canSuperBreaker) {
if (hasEndurance) {
if (canBlast) { player.sendMessage(LocaleLoader.getString("Mining.Ability.Length", superBreakerLength) + LocaleLoader.getString("Perks.activationtime.bonus", superBreakerLengthEndurance));
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Mining.Effect.4"), LocaleLoader.getString("Mining.Effect.5"))); }
} else {
player.sendMessage(LocaleLoader.getString("Mining.Ability.Length", superBreakerLength));
if (canBiggerBombs) { }
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Mining.Effect.6"), LocaleLoader.getString("Mining.Effect.7"))); }
}
if (canBlast) {
if (canDemoExpert) { if (skillValue < AdvancedConfig.getInstance().getBlastMiningRank1()) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Mining.Effect.8"), LocaleLoader.getString("Mining.Effect.9"))); player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Mining.Ability.Locked.0", AdvancedConfig.getInstance().getBlastMiningRank1())));
} }
} else {
player.sendMessage(LocaleLoader.getString("Mining.Blast.Rank", blastMiningRank, LocaleLoader.getString("Mining.Blast.Effect", oreBonus, debrisReduction, bonusTNTDrops)));
@Override }
protected boolean statsHeaderPermissions() { }
return canBiggerBombs || canBlast || canDemoExpert || (canDoubleDrop && !doubleDropsDisabled) || canSuperBreaker;
} if (canBiggerBombs) {
if (skillValue < AdvancedConfig.getInstance().getBlastMiningRank2()) {
@Override player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Mining.Ability.Locked.1", AdvancedConfig.getInstance().getBlastMiningRank2())));
protected void statsDisplay() { }
if (canDoubleDrop && !doubleDropsDisabled) { else {
if (isLucky) { player.sendMessage(LocaleLoader.getString("Mining.Blast.Radius.Increase", blastRadiusIncrease));
player.sendMessage(LocaleLoader.getString("Mining.Effect.DropChance", doubleDropChance) + LocaleLoader.getString("Perks.lucky.bonus", doubleDropChanceLucky)); }
} }
else {
player.sendMessage(LocaleLoader.getString("Mining.Effect.DropChance", doubleDropChance)); if (canDemoExpert) {
} if (skillValue < AdvancedConfig.getInstance().getBlastMiningRank4()) {
} player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Mining.Ability.Locked.2", AdvancedConfig.getInstance().getBlastMiningRank4())));
}
if (canSuperBreaker) { else {
if (hasEndurance) { player.sendMessage(LocaleLoader.getString("Mining.Effect.Decrease", blastDamageDecrease));
player.sendMessage(LocaleLoader.getString("Mining.Ability.Length", superBreakerLength) + LocaleLoader.getString("Perks.activationtime.bonus", superBreakerLengthEndurance)); }
} }
else { }
player.sendMessage(LocaleLoader.getString("Mining.Ability.Length", superBreakerLength)); }
}
}
if (canBlast) {
if (skillValue < BlastMining.rank1) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Mining.Ability.Locked.0", BlastMining.rank1)));
}
else {
player.sendMessage(LocaleLoader.getString("Mining.Blast.Rank", blastMiningRank, LocaleLoader.getString("Mining.Blast.Effect." + (Integer.parseInt(blastMiningRank) - 1))));
}
}
if (canBiggerBombs) {
if (skillValue < BlastMining.rank2) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Mining.Ability.Locked.1", BlastMining.rank2)));
}
else {
player.sendMessage(LocaleLoader.getString("Mining.Blast.Radius.Increase", blastRadiusIncrease));
}
}
if (canDemoExpert) {
if (skillValue < BlastMining.rank4) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Mining.Ability.Locked.2", BlastMining.rank4)));
}
else {
player.sendMessage(LocaleLoader.getString("Mining.Effect.Decrease", blastDamageDecrease));
}
}
}
}

View File

@ -1,164 +1,166 @@
package com.gmail.nossr50.skills.repair; package com.gmail.nossr50.commands.skills;
import org.bukkit.Material; import org.bukkit.Material;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.skills.SkillCommand; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.skills.repair.Repair;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.skills.repair.Repairable;
import com.gmail.nossr50.skills.repair.Salvage;
public class RepairCommand extends SkillCommand { import com.gmail.nossr50.util.Permissions;
private int arcaneForgingRank;
private String repairMasteryBonus; public class RepairCommand extends SkillCommand {
private String superRepairChance; private int arcaneForgingRank;
private String superRepairChanceLucky; private String repairMasteryBonus;
private String superRepairChance;
private boolean canSuperRepair; private String superRepairChanceLucky;
private boolean canMasterRepair;
private boolean canArcaneForge; private boolean canSuperRepair;
private boolean canSalvage; private boolean canMasterRepair;
private boolean canRepairStone; private boolean canArcaneForge;
private boolean canRepairIron; private boolean canSalvage;
private boolean canRepairGold; private boolean canRepairStone;
private boolean canRepairDiamond; private boolean canRepairIron;
private boolean canRepairString; private boolean canRepairGold;
private boolean canRepairLeather; private boolean canRepairDiamond;
private boolean canRepairWood; private boolean canRepairString;
private boolean arcaneBypass; private boolean canRepairLeather;
private boolean canRepairWood;
private int diamondLevel; private boolean arcaneBypass;
private int goldLevel;
private int ironLevel; private int diamondLevel;
private int stoneLevel; private int goldLevel;
private int ironLevel;
public RepairCommand() { private int stoneLevel;
super(SkillType.REPAIR);
} public RepairCommand() {
super(SkillType.REPAIR);
@Override }
protected void dataCalculations() {
// We're using pickaxes here, not the best but it works @Override
Repairable diamondRepairable = mcMMO.repairManager.getRepairable(Material.DIAMOND_PICKAXE.getId()); protected void dataCalculations() {
Repairable goldRepairable = mcMMO.repairManager.getRepairable(Material.GOLD_PICKAXE.getId()); // We're using pickaxes here, not the best but it works
Repairable ironRepairable = mcMMO.repairManager.getRepairable(Material.IRON_PICKAXE.getId()); Repairable diamondRepairable = mcMMO.repairManager.getRepairable(Material.DIAMOND_PICKAXE.getId());
Repairable stoneRepairable = mcMMO.repairManager.getRepairable(Material.STONE_PICKAXE.getId()); Repairable goldRepairable = mcMMO.repairManager.getRepairable(Material.GOLD_PICKAXE.getId());
Repairable ironRepairable = mcMMO.repairManager.getRepairable(Material.IRON_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 Repairable stoneRepairable = mcMMO.repairManager.getRepairable(Material.STONE_PICKAXE.getId());
diamondLevel = (diamondRepairable == null) ? 0 : diamondRepairable.getMinimumLevel();
goldLevel = (goldRepairable == null) ? 0 : goldRepairable.getMinimumLevel(); // TODO: This isn't really accurate - if they don't have pickaxes loaded it doesn't always mean the repair level is 0
ironLevel = (ironRepairable == null) ? 0 : ironRepairable.getMinimumLevel(); diamondLevel = (diamondRepairable == null) ? 0 : diamondRepairable.getMinimumLevel();
stoneLevel = (stoneRepairable == null) ? 0 : stoneRepairable.getMinimumLevel(); goldLevel = (goldRepairable == null) ? 0 : goldRepairable.getMinimumLevel();
ironLevel = (ironRepairable == null) ? 0 : ironRepairable.getMinimumLevel();
//REPAIR MASTERY stoneLevel = (stoneRepairable == null) ? 0 : stoneRepairable.getMinimumLevel();
if (skillValue >= Repair.REPAIR_MASTERY_MAX_BONUS_LEVEL) {
repairMasteryBonus = percent.format(Repair.REPAIR_MASTERY_CHANCE_MAX / 100D); // REPAIR MASTERY
} if (skillValue >= Repair.repairMasteryMaxBonusLevel) {
else { repairMasteryBonus = percent.format(Repair.repairMasteryMaxBonus / 100D);
repairMasteryBonus = percent.format((( Repair.REPAIR_MASTERY_CHANCE_MAX / Repair.REPAIR_MASTERY_MAX_BONUS_LEVEL) * skillValue) / 100D); }
} else {
repairMasteryBonus = percent.format(((Repair.repairMasteryMaxBonus / Repair.repairMasteryMaxBonusLevel) * skillValue) / 100D);
//SUPER REPAIR }
String[] superRepairStrings = calculateAbilityDisplayValues(Repair.SUPER_REPAIR_MAX_BONUS_LEVEL, Repair.SUPER_REPAIR_CHANCE_MAX);
superRepairChance = superRepairStrings[0]; // SUPER REPAIR
superRepairChanceLucky = superRepairStrings[1]; String[] superRepairStrings = calculateAbilityDisplayValues(Repair.superRepairMaxBonusLevel, Repair.superRepairMaxChance);
superRepairChance = superRepairStrings[0];
//ARCANE FORGING superRepairChanceLucky = superRepairStrings[1];
arcaneForgingRank = Repair.getArcaneForgingRank(profile);
} // ARCANE FORGING
arcaneForgingRank = Repair.getArcaneForgingRank(profile);
@Override }
protected void permissionsCheck() {
canSuperRepair = Permissions.superRepair(player); @Override
canMasterRepair = Permissions.repairMastery(player); protected void permissionsCheck() {
canArcaneForge = Permissions.arcaneForging(player); canSuperRepair = Permissions.superRepair(player);
canSalvage = Permissions.salvage(player); canMasterRepair = Permissions.repairMastery(player);
canRepairDiamond = Permissions.repairDiamond(player); canArcaneForge = Permissions.arcaneForging(player);
canRepairGold = Permissions.repairGold(player); canSalvage = Permissions.salvage(player);
canRepairIron = Permissions.repairIron(player); canRepairDiamond = Permissions.repairDiamond(player);
canRepairStone = Permissions.repairStone(player); canRepairGold = Permissions.repairGold(player);
canRepairString = Permissions.repairString(player); canRepairIron = Permissions.repairIron(player);
canRepairLeather = Permissions.repairLeather(player); canRepairStone = Permissions.repairStone(player);
canRepairWood = Permissions.repairWood(player); canRepairString = Permissions.repairString(player);
arcaneBypass = Permissions.arcaneBypass(player); canRepairLeather = Permissions.repairLeather(player);
} canRepairWood = Permissions.repairWood(player);
arcaneBypass = Permissions.arcaneBypass(player);
@Override }
protected boolean effectsHeaderPermissions() {
return canArcaneForge || canSalvage || canRepairDiamond || canRepairGold || canRepairIron || canMasterRepair || canRepairStone || canSuperRepair || canRepairString || canRepairWood || canRepairLeather; @Override
} protected boolean effectsHeaderPermissions() {
return canArcaneForge || canSalvage || canRepairDiamond || canRepairGold || canRepairIron || canMasterRepair || canRepairStone || canSuperRepair || canRepairString || canRepairWood || canRepairLeather;
@Override }
protected void effectsDisplay() {
luckyEffectsDisplay(); @Override
protected void effectsDisplay() {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.0"), LocaleLoader.getString("Repair.Effect.1"))); luckyEffectsDisplay();
if (canMasterRepair) { player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.0"), LocaleLoader.getString("Repair.Effect.1")));
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.2"), LocaleLoader.getString("Repair.Effect.3")));
} if (canMasterRepair) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.2"), LocaleLoader.getString("Repair.Effect.3")));
if (canSuperRepair) { }
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.4"), LocaleLoader.getString("Repair.Effect.5")));
} if (canSuperRepair) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.4"), LocaleLoader.getString("Repair.Effect.5")));
/* Repair Level Requirements */ }
if (canRepairStone && stoneLevel > 0) { /* Repair Level Requirements */
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.14", stoneLevel), LocaleLoader.getString("Repair.Effect.15")));
} if (canRepairStone && stoneLevel > 0) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.14", stoneLevel), LocaleLoader.getString("Repair.Effect.15")));
if (canRepairIron && ironLevel > 0) { }
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.12", ironLevel), LocaleLoader.getString("Repair.Effect.13")));
} if (canRepairIron && ironLevel > 0) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.12", ironLevel), LocaleLoader.getString("Repair.Effect.13")));
if (canRepairGold && goldLevel > 0) { }
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.10", goldLevel), LocaleLoader.getString("Repair.Effect.11")));
} if (canRepairGold && goldLevel > 0) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.10", goldLevel), LocaleLoader.getString("Repair.Effect.11")));
if (canRepairDiamond && diamondLevel > 0) { }
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.6", diamondLevel), LocaleLoader.getString("Repair.Effect.7")));
} if (canRepairDiamond && diamondLevel > 0) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.6", diamondLevel), LocaleLoader.getString("Repair.Effect.7")));
if (canSalvage && Salvage.salvageUnlockLevel > 0) { }
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.16", Salvage.salvageUnlockLevel), LocaleLoader.getString("Repair.Effect.17")));
} if (canSalvage && Salvage.salvageUnlockLevel > 0) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.16", Salvage.salvageUnlockLevel), LocaleLoader.getString("Repair.Effect.17")));
if (canArcaneForge) { }
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.8"), LocaleLoader.getString("Repair.Effect.9")));
} if (canArcaneForge) {
} player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.8"), LocaleLoader.getString("Repair.Effect.9")));
}
@Override }
protected boolean statsHeaderPermissions() {
return canArcaneForge || canMasterRepair || canSuperRepair; @Override
} protected boolean statsHeaderPermissions() {
return canArcaneForge || canMasterRepair || canSuperRepair;
@Override }
protected void statsDisplay() {
if (canMasterRepair) { @Override
player.sendMessage(LocaleLoader.getString("Repair.Skills.Mastery", repairMasteryBonus)); protected void statsDisplay() {
} if (canMasterRepair) {
player.sendMessage(LocaleLoader.getString("Repair.Skills.Mastery", repairMasteryBonus));
if (canSuperRepair) { }
if (isLucky) {
player.sendMessage(LocaleLoader.getString("Repair.Skills.Super.Chance", superRepairChance) + LocaleLoader.getString("Perks.lucky.bonus", superRepairChanceLucky)); if (canSuperRepair) {
} if (isLucky) {
else { player.sendMessage(LocaleLoader.getString("Repair.Skills.Super.Chance", superRepairChance) + LocaleLoader.getString("Perks.lucky.bonus", superRepairChanceLucky));
player.sendMessage(LocaleLoader.getString("Repair.Skills.Super.Chance", superRepairChance)); }
} else {
} player.sendMessage(LocaleLoader.getString("Repair.Skills.Super.Chance", superRepairChance));
}
if (canArcaneForge) { }
player.sendMessage(LocaleLoader.getString("Repair.Arcane.Rank", arcaneForgingRank));
if (canArcaneForge) {
if (Repair.arcaneForgingEnchantLoss) { player.sendMessage(LocaleLoader.getString("Repair.Arcane.Rank", arcaneForgingRank));
player.sendMessage(LocaleLoader.getString("Repair.Arcane.Chance.Success", (arcaneBypass ? 100 : Repair.getEnchantChance(arcaneForgingRank))));
} if (Repair.arcaneForgingEnchantLoss) {
player.sendMessage(LocaleLoader.getString("Repair.Arcane.Chance.Success", (arcaneBypass ? 100 : Repair.getEnchantChance(arcaneForgingRank))));
if (Repair.arcaneForgingDowngrades) { }
player.sendMessage(LocaleLoader.getString("Repair.Arcane.Chance.Downgrade", (arcaneBypass ? 0 : Repair.getDowngradeChance(arcaneForgingRank))));
} if (Repair.arcaneForgingDowngrades) {
} player.sendMessage(LocaleLoader.getString("Repair.Arcane.Chance.Downgrade", (arcaneBypass ? 0 : Repair.getDowngradeChance(arcaneForgingRank))));
} }
} }
}
}

View File

@ -1,158 +1,159 @@
package com.gmail.nossr50.skills; package com.gmail.nossr50.commands.skills;
import java.text.DecimalFormat; import java.text.DecimalFormat;
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 org.bukkit.entity.Player;
import com.gmail.nossr50.commands.CommandHelper; import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.skills.utilities.PerksUtils; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.SkillTools; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.skills.PerksUtils;
import com.gmail.nossr50.util.skills.SkillUtils;
public abstract class SkillCommand implements CommandExecutor {
protected SkillType skill; public abstract class SkillCommand implements CommandExecutor {
private String skillString; protected SkillType skill;
private String skillString;
protected Player player;
protected PlayerProfile profile; protected Player player;
protected float skillValue; protected PlayerProfile profile;
protected boolean isLucky; protected float skillValue;
protected boolean hasEndurance; protected boolean isLucky;
protected boolean hasEndurance;
protected DecimalFormat percent = new DecimalFormat("##0.00%");
protected DecimalFormat decimal = new DecimalFormat("##0.00"); protected DecimalFormat percent = new DecimalFormat("##0.00%");
protected DecimalFormat decimal = new DecimalFormat("##0.00");
public SkillCommand(SkillType skill) {
this.skill = skill; public SkillCommand(SkillType skill) {
this.skillString = StringUtils.getCapitalized(skill.toString()); this.skill = skill;
} this.skillString = StringUtils.getCapitalized(skill.toString());
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { @Override
if (CommandHelper.noConsoleUsage(sender)) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
return true; if (CommandUtils.noConsoleUsage(sender)) {
} return true;
}
player = (Player) sender;
profile = Users.getPlayer(player).getProfile(); player = (Player) sender;
profile = UserManager.getPlayer(player).getProfile();
if (profile == null) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist")); if (profile == null) {
return true; sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
} return true;
}
skillValue = profile.getSkillLevel(skill);
isLucky = Permissions.lucky(sender, skill); skillValue = profile.getSkillLevel(skill);
hasEndurance = (Permissions.twelveSecondActivationBoost(sender) || Permissions.eightSecondActivationBoost(sender) || Permissions.fourSecondActivationBoost(sender)); isLucky = Permissions.lucky(sender, skill);
hasEndurance = (Permissions.twelveSecondActivationBoost(sender) || Permissions.eightSecondActivationBoost(sender) || Permissions.fourSecondActivationBoost(sender));
dataCalculations();
permissionsCheck(); dataCalculations();
permissionsCheck();
player.sendMessage(LocaleLoader.getString("Skills.Header", LocaleLoader.getString(skillString + ".SkillName")));
player.sendMessage(LocaleLoader.getString("Skills.Header", LocaleLoader.getString(skillString + ".SkillName")));
if (!skill.isChildSkill()) {
player.sendMessage(LocaleLoader.getString("Commands.XPGain", LocaleLoader.getString("Commands.XPGain." + skillString))); if (!skill.isChildSkill()) {
player.sendMessage(LocaleLoader.getString("Effects.Level", profile.getSkillLevel(skill), profile.getSkillXpLevel(skill), profile.getXpToLevel(skill))); player.sendMessage(LocaleLoader.getString("Commands.XPGain", LocaleLoader.getString("Commands.XPGain." + skillString)));
} player.sendMessage(LocaleLoader.getString("Effects.Level", profile.getSkillLevel(skill), profile.getSkillXpLevel(skill), profile.getXpToLevel(skill)));
}
if (effectsHeaderPermissions()) {
player.sendMessage(LocaleLoader.getString("Skills.Header", LocaleLoader.getString("Effects.Effects"))); if (effectsHeaderPermissions()) {
} player.sendMessage(LocaleLoader.getString("Skills.Header", LocaleLoader.getString("Effects.Effects")));
}
effectsDisplay();
effectsDisplay();
if (statsHeaderPermissions()) {
player.sendMessage(LocaleLoader.getString("Skills.Header", LocaleLoader.getString("Commands.Stats.Self"))); if (statsHeaderPermissions()) {
} player.sendMessage(LocaleLoader.getString("Skills.Header", LocaleLoader.getString("Commands.Stats.Self")));
}
statsDisplay();
statsDisplay();
return SkillGuide.grabGuidePageForSkill(skill, player, args);
} return SkillGuideCommand.grabGuidePageForSkill(skill, player, args);
}
protected String calculateRank(int maxLevel, int rankChangeLevel) {
if (skillValue >= maxLevel) { protected String calculateRank(int maxLevel, int rankChangeLevel) {
return String.valueOf(maxLevel / rankChangeLevel); if (skillValue >= maxLevel) {
} return String.valueOf(maxLevel / rankChangeLevel);
}
return String.valueOf((int) (skillValue / rankChangeLevel));
} return String.valueOf((int) (skillValue / rankChangeLevel));
}
protected String[] calculateAbilityDisplayValues(double chance) {
if (isLucky) { protected String[] calculateAbilityDisplayValues(double chance) {
double luckyChance = chance * 1.3333D; if (isLucky) {
double luckyChance = chance * 1.3333D;
if (luckyChance >= 100D) {
return new String[] { percent.format(chance / 100.0D), percent.format(1.0D) }; if (luckyChance >= 100D) {
} return new String[] { percent.format(chance / 100.0D), percent.format(1.0D) };
}
return new String[] { percent.format(chance / 100.0D), percent.format(luckyChance / 100.0D) };
} return new String[] { percent.format(chance / 100.0D), percent.format(luckyChance / 100.0D) };
}
return new String[] { percent.format(chance / 100.0D), null };
} return new String[] { percent.format(chance / 100.0D), null };
}
protected String[] calculateAbilityDisplayValues(int maxBonusLevel, double maxChance) {
double abilityChance; protected String[] calculateAbilityDisplayValues(int maxBonusLevel, double maxChance) {
double abilityChance;
if (skillValue >= maxBonusLevel) {
abilityChance = maxChance; if (skillValue >= maxBonusLevel) {
} abilityChance = maxChance;
else { }
abilityChance = (maxChance / maxBonusLevel) * skillValue; else {
} abilityChance = (maxChance / maxBonusLevel) * skillValue;
}
if (isLucky) {
double luckyChance = abilityChance * 1.3333D; if (isLucky) {
double luckyChance = abilityChance * 1.3333D;
if (luckyChance >= 100D) {
return new String[] { percent.format(abilityChance / 100.0D), percent.format(1.0D) }; if (luckyChance >= 100D) {
} return new String[] { percent.format(abilityChance / 100.0D), percent.format(1.0D) };
}
return new String[] { percent.format(abilityChance / 100.0D), percent.format(luckyChance / 100.0D) };
} return new String[] { percent.format(abilityChance / 100.0D), percent.format(luckyChance / 100.0D) };
}
return new String[] { percent.format(abilityChance / 100.0D), null };
} return new String[] { percent.format(abilityChance / 100.0D), null };
}
protected String[] calculateLengthDisplayValues() {
int maxLength = skill.getAbility().getMaxTicks(); protected String[] calculateLengthDisplayValues() {
int length = 2 + (int) (skillValue / SkillTools.abilityLengthIncreaseLevel); int maxLength = skill.getAbility().getMaxTicks();
int enduranceLength = PerksUtils.handleActivationPerks(player, length, maxLength); int length = 2 + (int) (skillValue / AdvancedConfig.getInstance().getAbilityLength());
int enduranceLength = PerksUtils.handleActivationPerks(player, length, maxLength);
if (maxLength != 0) {
if (length > maxLength) { if (maxLength != 0) {
length = maxLength; if (length > maxLength) {
} length = maxLength;
} }
}
return new String[] { String.valueOf(length), String.valueOf(enduranceLength) };
} return new String[] { String.valueOf(length), String.valueOf(enduranceLength) };
}
protected void luckyEffectsDisplay() {
if (isLucky) { protected void luckyEffectsDisplay() {
String perkPrefix = LocaleLoader.getString("MOTD.PerksPrefix"); if (isLucky) {
player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Perks.lucky.name"), LocaleLoader.getString("Perks.lucky.desc", SkillTools.getSkillName(skill)))); String perkPrefix = LocaleLoader.getString("MOTD.PerksPrefix");
} player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Perks.lucky.name"), LocaleLoader.getString("Perks.lucky.desc", SkillUtils.getSkillName(skill))));
} }
}
protected abstract void dataCalculations();
protected abstract void dataCalculations();
protected abstract void permissionsCheck();
protected abstract void permissionsCheck();
protected abstract boolean effectsHeaderPermissions();
protected abstract boolean effectsHeaderPermissions();
protected abstract void effectsDisplay();
protected abstract void effectsDisplay();
protected abstract boolean statsHeaderPermissions();
protected abstract boolean statsHeaderPermissions();
protected abstract void statsDisplay();
} protected abstract void statsDisplay();
}

View File

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

View File

@ -1,133 +1,122 @@
package com.gmail.nossr50.skills.smelting; package com.gmail.nossr50.commands.skills;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.skills.SkillCommand; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.skills.smelting.Smelting;
import com.gmail.nossr50.util.Permissions;
public class SmeltingCommand extends SkillCommand { import com.gmail.nossr50.util.player.UserManager;
private String burnTimeModifier;
private String secondSmeltChance; public class SmeltingCommand extends SkillCommand {
private String secondSmeltChanceLucky; private String burnTimeModifier;
private String fluxMiningChance; private String secondSmeltChance;
private String fluxMiningChanceLucky; private String secondSmeltChanceLucky;
private String vanillaXPModifier; private String fluxMiningChance;
private String fluxMiningChanceLucky;
private boolean canFuelEfficiency;
private boolean canSecondSmelt; private int vanillaXPModifier;
private boolean canFluxMine;
private boolean canVanillaXPBoost; private boolean canFuelEfficiency;
private boolean canSecondSmelt;
public SmeltingCommand() { private boolean canFluxMine;
super(SkillType.SMELTING); private boolean canVanillaXPBoost;
}
public SmeltingCommand() {
@Override super(SkillType.SMELTING);
protected void dataCalculations() { }
//FUEL EFFICIENCY
burnTimeModifier = decimal.format(1 + ((skillValue / Smelting.burnModifierMaxLevel) * Smelting.burnTimeMultiplier)); @Override
protected void dataCalculations() {
//SECOND SMELT // FUEL EFFICIENCY
String[] secondSmeltStrings = calculateAbilityDisplayValues(Smelting.secondSmeltMaxLevel, Smelting.secondSmeltMaxChance); burnTimeModifier = decimal.format(1 + ((skillValue / Smelting.burnModifierMaxLevel) * Smelting.burnTimeMultiplier));
secondSmeltChance = secondSmeltStrings[0];
secondSmeltChanceLucky = secondSmeltStrings[1]; // SECOND SMELT
String[] secondSmeltStrings = calculateAbilityDisplayValues(Smelting.secondSmeltMaxLevel, Smelting.secondSmeltMaxChance);
//FLUX MINING secondSmeltChance = secondSmeltStrings[0];
String[] fluxMiningStrings = calculateAbilityDisplayValues(Smelting.fluxMiningChance); secondSmeltChanceLucky = secondSmeltStrings[1];
fluxMiningChance = fluxMiningStrings[0];
fluxMiningChanceLucky = fluxMiningStrings[1]; // FLUX MINING
String[] fluxMiningStrings = calculateAbilityDisplayValues(Smelting.fluxMiningChance);
//VANILLA XP BOOST fluxMiningChance = fluxMiningStrings[0];
if (skillValue >= Smelting.vanillaXPBoostRank5Level) { fluxMiningChanceLucky = fluxMiningStrings[1];
vanillaXPModifier = String.valueOf(Smelting.vanillaXPBoostRank5Multiplier);
} // VANILLA XP BOOST
else if (skillValue >= Smelting.vanillaXPBoostRank4Level) { vanillaXPModifier = UserManager.getPlayer(player).getSmeltingManager().getVanillaXpMultiplier();
vanillaXPModifier = String.valueOf(Smelting.vanillaXPBoostRank4Multiplier); }
}
else if (skillValue >= Smelting.vanillaXPBoostRank3Level) { @Override
vanillaXPModifier = String.valueOf(Smelting.vanillaXPBoostRank3Multiplier); protected void permissionsCheck() {
} canFuelEfficiency = Permissions.fuelEfficiency(player);
else if (skillValue >= Smelting.vanillaXPBoostRank2Level) { canSecondSmelt = Permissions.doubleDrops(player, skill);
vanillaXPModifier = String.valueOf(Smelting.vanillaXPBoostRank2Multiplier); canFluxMine = Permissions.fluxMining(player);
} canVanillaXPBoost = Permissions.vanillaXpBoost(player, skill);
else { }
vanillaXPModifier = String.valueOf(Smelting.vanillaXPBoostRank1Multiplier);
} @Override
} protected boolean effectsHeaderPermissions() {
return canFluxMine || canFuelEfficiency || canSecondSmelt || canVanillaXPBoost;
@Override }
protected void permissionsCheck() {
canFuelEfficiency = Permissions.fuelEfficiency(player); @Override
canSecondSmelt = Permissions.doubleDrops(player, skill); protected void effectsDisplay() {
canFluxMine = Permissions.fluxMining(player); luckyEffectsDisplay();
canVanillaXPBoost = Permissions.vanillaXpBoost(player, skill);
} if (canFuelEfficiency) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Smelting.Effect.0"), LocaleLoader.getString("Smelting.Effect.1")));
@Override }
protected boolean effectsHeaderPermissions() {
return canFluxMine || canFuelEfficiency || canSecondSmelt || canVanillaXPBoost; if (canSecondSmelt) {
} player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Smelting.Effect.2"), LocaleLoader.getString("Smelting.Effect.3")));
}
@Override
protected void effectsDisplay() { if (canVanillaXPBoost) {
luckyEffectsDisplay(); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Smelting.Effect.4"), LocaleLoader.getString("Smelting.Effect.5")));
}
if (canFuelEfficiency) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Smelting.Effect.0"), LocaleLoader.getString("Smelting.Effect.1"))); if (canFluxMine) {
} player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Smelting.Effect.6"), LocaleLoader.getString("Smelting.Effect.7")));
}
if (canSecondSmelt) { }
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Smelting.Effect.2"), LocaleLoader.getString("Smelting.Effect.3")));
} @Override
protected boolean statsHeaderPermissions() {
if (canVanillaXPBoost) { return canFluxMine || canFuelEfficiency || canSecondSmelt || canVanillaXPBoost;
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Smelting.Effect.4"), LocaleLoader.getString("Smelting.Effect.5"))); }
}
@Override
if (canFluxMine) { protected void statsDisplay() {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Smelting.Effect.6"), LocaleLoader.getString("Smelting.Effect.7"))); if (canFuelEfficiency) {
} player.sendMessage(LocaleLoader.getString("Smelting.Ability.FuelEfficiency", burnTimeModifier));
} }
@Override if (canSecondSmelt) {
protected boolean statsHeaderPermissions() { if (isLucky) {
return canFluxMine || canFuelEfficiency || canSecondSmelt || canVanillaXPBoost; player.sendMessage(LocaleLoader.getString("Smelting.Ability.SecondSmelt", secondSmeltChance) + LocaleLoader.getString("Perks.lucky.bonus", secondSmeltChanceLucky));
} }
else {
@Override player.sendMessage(LocaleLoader.getString("Smelting.Ability.SecondSmelt", secondSmeltChance));
protected void statsDisplay() { }
if (canFuelEfficiency) { }
player.sendMessage(LocaleLoader.getString("Smelting.Ability.FuelEfficiency", burnTimeModifier));
} if (canVanillaXPBoost) {
if (skillValue < AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank1Level()) {
if (canSecondSmelt) { player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Smelting.Ability.Locked.0", AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank1Level())));
if (isLucky) { }
player.sendMessage(LocaleLoader.getString("Smelting.Ability.SecondSmelt", secondSmeltChance) + LocaleLoader.getString("Perks.lucky.bonus", secondSmeltChanceLucky)); else {
} player.sendMessage(LocaleLoader.getString("Smelting.Ability.VanillaXPBoost", vanillaXPModifier));
else { }
player.sendMessage(LocaleLoader.getString("Smelting.Ability.SecondSmelt", secondSmeltChance)); }
}
} if (canFluxMine) {
if (skillValue < Smelting.fluxMiningUnlockLevel) {
if (canVanillaXPBoost) { player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Smelting.Ability.Locked.1", Smelting.fluxMiningUnlockLevel)));
if (skillValue < Smelting.vanillaXPBoostRank1Level) { }
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Smelting.Ability.Locked.0", Smelting.vanillaXPBoostRank1Level))); else if (isLucky) {
} player.sendMessage(LocaleLoader.getString("Smelting.Ability.FluxMining", fluxMiningChance) + LocaleLoader.getString("Perks.lucky.bonus", fluxMiningChanceLucky));
else { }
player.sendMessage(LocaleLoader.getString("Smelting.Ability.VanillaXPBoost", vanillaXPModifier)); else {
} player.sendMessage(LocaleLoader.getString("Smelting.Ability.FluxMining", fluxMiningChance));
} }
}
if (canFluxMine) { }
if (skillValue < Smelting.fluxMiningUnlockLevel) { }
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Smelting.Ability.Locked.1", Smelting.fluxMiningUnlockLevel)));
}
else if (isLucky) {
player.sendMessage(LocaleLoader.getString("Smelting.Ability.FluxMining", fluxMiningChance) + LocaleLoader.getString("Perks.lucky.bonus", fluxMiningChanceLucky));
}
else {
player.sendMessage(LocaleLoader.getString("Smelting.Ability.FluxMining", fluxMiningChance));
}
}
}
}

View File

@ -1,117 +1,117 @@
package com.gmail.nossr50.skills.swords; package com.gmail.nossr50.commands.skills;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.skills.SkillCommand; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.skills.swords.Swords;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
public class SwordsCommand extends SkillCommand { public class SwordsCommand extends SkillCommand {
private String counterAttackChance; private String counterAttackChance;
private String counterAttackChanceLucky; private String counterAttackChanceLucky;
private String bleedLength; private String bleedLength;
private String bleedChance; private String bleedChance;
private String bleedChanceLucky; private String bleedChanceLucky;
private String serratedStrikesLength; private String serratedStrikesLength;
private String serratedStrikesLengthEndurance; private String serratedStrikesLengthEndurance;
private boolean canCounter; private boolean canCounter;
private boolean canSerratedStrike; private boolean canSerratedStrike;
private boolean canBleed; private boolean canBleed;
public SwordsCommand() { public SwordsCommand() {
super(SkillType.SWORDS); super(SkillType.SWORDS);
} }
@Override @Override
protected void dataCalculations() { protected void dataCalculations() {
//SERRATED STRIKES // SERRATED STRIKES
String[] serratedStrikesStrings = calculateLengthDisplayValues(); String[] serratedStrikesStrings = calculateLengthDisplayValues();
serratedStrikesLength = serratedStrikesStrings[0]; serratedStrikesLength = serratedStrikesStrings[0];
serratedStrikesLengthEndurance = serratedStrikesStrings[1]; serratedStrikesLengthEndurance = serratedStrikesStrings[1];
//BLEED // BLEED
if (skillValue >= Swords.bleedMaxBonusLevel) { if (skillValue >= Swords.bleedMaxBonusLevel) {
bleedLength = String.valueOf(Swords.bleedMaxTicks); bleedLength = String.valueOf(Swords.bleedMaxTicks);
} }
else { else {
bleedLength = String.valueOf(Swords.bleedBaseTicks); bleedLength = String.valueOf(Swords.bleedBaseTicks);
} }
String[] bleedStrings = calculateAbilityDisplayValues(Swords.bleedMaxBonusLevel, Swords.bleedMaxChance); String[] bleedStrings = calculateAbilityDisplayValues(Swords.bleedMaxBonusLevel, Swords.bleedMaxChance);
bleedChance = bleedStrings[0]; bleedChance = bleedStrings[0];
bleedChanceLucky = bleedStrings[1]; bleedChanceLucky = bleedStrings[1];
//COUNTER ATTACK // COUNTER ATTACK
String[] counterAttackStrings = calculateAbilityDisplayValues(Swords.counterAttackMaxBonusLevel, Swords.counterAttackMaxChance); String[] counterAttackStrings = calculateAbilityDisplayValues(Swords.counterAttackMaxBonusLevel, Swords.counterAttackMaxChance);
counterAttackChance = counterAttackStrings[0]; counterAttackChance = counterAttackStrings[0];
counterAttackChanceLucky = counterAttackStrings[1]; counterAttackChanceLucky = counterAttackStrings[1];
} }
@Override @Override
protected void permissionsCheck() { 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 boolean effectsHeaderPermissions() { protected boolean effectsHeaderPermissions() {
return canBleed || canCounter || canSerratedStrike; return canBleed || canCounter || canSerratedStrike;
} }
@Override @Override
protected void effectsDisplay() { protected void effectsDisplay() {
luckyEffectsDisplay(); luckyEffectsDisplay();
if (canCounter) { if (canCounter) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Swords.Effect.0"), LocaleLoader.getString("Swords.Effect.1", percent.format(1.0D / Swords.counterAttackModifier)))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Swords.Effect.0"), LocaleLoader.getString("Swords.Effect.1", percent.format(1.0D / Swords.counterAttackModifier))));
} }
if (canSerratedStrike) { if (canSerratedStrike) {
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.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))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Swords.Effect.4"), LocaleLoader.getString("Swords.Effect.5", Swords.serratedStrikesBleedTicks)));
} }
if (canBleed) { if (canBleed) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Swords.Effect.6"), LocaleLoader.getString("Swords.Effect.7"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Swords.Effect.6"), LocaleLoader.getString("Swords.Effect.7")));
} }
} }
@Override @Override
protected boolean statsHeaderPermissions() { protected boolean statsHeaderPermissions() {
return canBleed || canCounter || canSerratedStrike; return canBleed || canCounter || canSerratedStrike;
} }
@Override @Override
protected void statsDisplay() { protected void statsDisplay() {
if (canCounter) { if (canCounter) {
if (isLucky) { if (isLucky) {
player.sendMessage(LocaleLoader.getString("Swords.Combat.Counter.Chance", counterAttackChance) + LocaleLoader.getString("Perks.lucky.bonus", counterAttackChanceLucky)); player.sendMessage(LocaleLoader.getString("Swords.Combat.Counter.Chance", counterAttackChance) + LocaleLoader.getString("Perks.lucky.bonus", counterAttackChanceLucky));
} }
else { else {
player.sendMessage(LocaleLoader.getString("Swords.Combat.Counter.Chance", counterAttackChance)); player.sendMessage(LocaleLoader.getString("Swords.Combat.Counter.Chance", counterAttackChance));
} }
} }
if (canBleed) { if (canBleed) {
player.sendMessage(LocaleLoader.getString("Swords.Combat.Bleed.Length", bleedLength)); player.sendMessage(LocaleLoader.getString("Swords.Combat.Bleed.Length", bleedLength));
player.sendMessage(LocaleLoader.getString("Swords.Combat.Bleed.Note")); player.sendMessage(LocaleLoader.getString("Swords.Combat.Bleed.Note"));
if (isLucky) { if (isLucky) {
player.sendMessage(LocaleLoader.getString("Swords.Combat.Bleed.Chance", bleedChance) + LocaleLoader.getString("Perks.lucky.bonus", bleedChanceLucky)); player.sendMessage(LocaleLoader.getString("Swords.Combat.Bleed.Chance", bleedChance) + LocaleLoader.getString("Perks.lucky.bonus", bleedChanceLucky));
} }
else { else {
player.sendMessage(LocaleLoader.getString("Swords.Combat.Bleed.Chance", bleedChance)); player.sendMessage(LocaleLoader.getString("Swords.Combat.Bleed.Chance", bleedChance));
} }
} }
if (canSerratedStrike) { if (canSerratedStrike) {
if (hasEndurance) { if (hasEndurance) {
player.sendMessage(LocaleLoader.getString("Swords.SS.Length", serratedStrikesLength) + LocaleLoader.getString("Perks.activationtime.bonus", serratedStrikesLengthEndurance)); player.sendMessage(LocaleLoader.getString("Swords.SS.Length", serratedStrikesLength) + LocaleLoader.getString("Perks.activationtime.bonus", serratedStrikesLengthEndurance));
} }
else { else {
player.sendMessage(LocaleLoader.getString("Swords.SS.Length", serratedStrikesLength)); player.sendMessage(LocaleLoader.getString("Swords.SS.Length", serratedStrikesLength));
} }
} }
} }
} }

View File

@ -1,150 +1,165 @@
package com.gmail.nossr50.skills.taming; package com.gmail.nossr50.commands.skills;
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.skills.SkillCommand; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.skills.taming.Taming;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
public class TamingCommand extends SkillCommand { public class TamingCommand extends SkillCommand {
private String goreChance; private String goreChance;
private String goreChanceLucky; private String goreChanceLucky;
private boolean canBeastLore; private boolean canBeastLore;
private boolean canGore; private boolean canGore;
private boolean canSharpenedClaws; private boolean canSharpenedClaws;
private boolean canEnvironmentallyAware; private boolean canEnvironmentallyAware;
private boolean canThickFur; private boolean canThickFur;
private boolean canShockProof; private boolean canShockProof;
private boolean canCallWild; private boolean canCallWild;
private boolean canFastFood; private boolean canFastFood;
private boolean canHolyHound;
public TamingCommand() {
super(SkillType.TAMING); public TamingCommand() {
} super(SkillType.TAMING);
}
@Override
protected void dataCalculations() { @Override
String[] goreStrings = calculateAbilityDisplayValues(Taming.goreMaxBonusLevel, Taming.goreMaxChance); protected void dataCalculations() {
goreChance = goreStrings[0]; String[] goreStrings = calculateAbilityDisplayValues(Taming.goreMaxBonusLevel, Taming.goreMaxChance);
goreChanceLucky = goreStrings[1]; goreChance = goreStrings[0];
} goreChanceLucky = goreStrings[1];
}
@Override
protected void permissionsCheck() { @Override
canBeastLore = Permissions.beastLore(player); protected void permissionsCheck() {
canCallWild = Permissions.callOfTheWild(player); canBeastLore = Permissions.beastLore(player);
canEnvironmentallyAware = Permissions.environmentallyAware(player); canCallWild = Permissions.callOfTheWild(player);
canFastFood = Permissions.fastFoodService(player); canEnvironmentallyAware = Permissions.environmentallyAware(player);
canGore = Permissions.gore(player); canFastFood = Permissions.fastFoodService(player);
canSharpenedClaws = Permissions.sharpenedClaws(player); canGore = Permissions.gore(player);
canShockProof = Permissions.shockProof(player); canSharpenedClaws = Permissions.sharpenedClaws(player);
canThickFur = Permissions.thickFur(player); canShockProof = Permissions.shockProof(player);
} canThickFur = Permissions.thickFur(player);
canHolyHound = Permissions.holyHound(player);
@Override }
protected boolean effectsHeaderPermissions() {
return canBeastLore || canCallWild || canEnvironmentallyAware || canFastFood || canGore || canSharpenedClaws || canShockProof || canThickFur; @Override
} protected boolean effectsHeaderPermissions() {
return canBeastLore || canCallWild || canEnvironmentallyAware || canFastFood || canGore || canSharpenedClaws || canShockProof || canThickFur || canHolyHound;
@Override }
protected void effectsDisplay() {
luckyEffectsDisplay(); @Override
protected void effectsDisplay() {
if (canBeastLore) { luckyEffectsDisplay();
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Taming.Effect.0"), LocaleLoader.getString("Taming.Effect.1")));
} 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 (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 (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 (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 (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 (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 (canFastFood) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Taming.Effect.16"), LocaleLoader.getString("Taming.Effect.17")));
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())); if (canHolyHound) {
player.sendMessage(LocaleLoader.getString("Taming.Effect.15", Config.getInstance().getTamingCOTWWolfCost())); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Taming.Effect.18"), LocaleLoader.getString("Taming.Effect.19")));
} }
}
if (canCallWild) {
@Override player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Taming.Effect.12"), LocaleLoader.getString("Taming.Effect.13")));
protected boolean statsHeaderPermissions() { player.sendMessage(LocaleLoader.getString("Taming.Effect.14", Config.getInstance().getTamingCOTWOcelotCost()));
return canEnvironmentallyAware || canFastFood || canGore || canSharpenedClaws || canShockProof || canThickFur; player.sendMessage(LocaleLoader.getString("Taming.Effect.15", Config.getInstance().getTamingCOTWWolfCost()));
} }
}
@Override
protected void statsDisplay() { @Override
if (canFastFood) { protected boolean statsHeaderPermissions() {
if (skillValue < Taming.fastFoodServiceUnlockLevel) { return canEnvironmentallyAware || canFastFood || canGore || canSharpenedClaws || canShockProof || canThickFur || canHolyHound;
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Taming.Ability.Locked.4", Taming.fastFoodServiceUnlockLevel))); }
}
else { @Override
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Taming.Ability.Bonus.8"), LocaleLoader.getString("Taming.Ability.Bonus.9", percent.format(Taming.fastFoodServiceActivationChance / 100D)))); protected void statsDisplay() {
} if (canFastFood) {
} if (skillValue < Taming.fastFoodServiceUnlockLevel) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Taming.Ability.Locked.4", Taming.fastFoodServiceUnlockLevel)));
if (canEnvironmentallyAware) { }
if (skillValue < Taming.environmentallyAwareUnlockLevel) { else {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Taming.Ability.Locked.0", Taming.environmentallyAwareUnlockLevel))); player.sendMessage(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Taming.Ability.Bonus.8"), LocaleLoader.getString("Taming.Ability.Bonus.9", percent.format(Taming.fastFoodServiceActivationChance / 100D))));
} }
else { }
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Taming.Ability.Bonus.0"), LocaleLoader.getString("Taming.Ability.Bonus.1")));
} if (canEnvironmentallyAware) {
} if (skillValue < Taming.environmentallyAwareUnlockLevel) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Taming.Ability.Locked.0", Taming.environmentallyAwareUnlockLevel)));
if (canThickFur) { }
if (skillValue < Taming.thickFurUnlockLevel) { else {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Taming.Ability.Locked.1", Taming.thickFurUnlockLevel))); player.sendMessage(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Taming.Ability.Bonus.0"), LocaleLoader.getString("Taming.Ability.Bonus.1")));
} }
else { }
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Taming.Ability.Bonus.2"), LocaleLoader.getString("Taming.Ability.Bonus.3", Taming.thickFurModifier)));
} if (canThickFur) {
} if (skillValue < Taming.thickFurUnlockLevel) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Taming.Ability.Locked.1", Taming.thickFurUnlockLevel)));
if (canShockProof) { }
if (skillValue < Taming.shockProofUnlockLevel) { else {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Taming.Ability.Locked.2", Taming.shockProofUnlockLevel))); player.sendMessage(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Taming.Ability.Bonus.2"), LocaleLoader.getString("Taming.Ability.Bonus.3", Taming.thickFurModifier)));
} }
else { }
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Taming.Ability.Bonus.4"), LocaleLoader.getString("Taming.Ability.Bonus.5", Taming.shockProofModifier)));
} if (canHolyHound) {
} if (skillValue < Taming.holyHoundUnlockLevel) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Taming.Ability.Locked.5", Taming.holyHoundUnlockLevel)));
if (canSharpenedClaws) { }
if (skillValue < Taming.sharpenedClawsUnlockLevel) { else {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Taming.Ability.Locked.3", Taming.sharpenedClawsUnlockLevel))); player.sendMessage(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Taming.Ability.Bonus.10"), LocaleLoader.getString("Taming.Ability.Bonus.11")));
} }
else { }
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Taming.Ability.Bonus.6"), LocaleLoader.getString("Taming.Ability.Bonus.7", Taming.sharpenedClawsBonusDamage)));
} if (canShockProof) {
} if (skillValue < Taming.shockProofUnlockLevel) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Taming.Ability.Locked.2", Taming.shockProofUnlockLevel)));
if (canGore) { }
if (isLucky) { else {
player.sendMessage(LocaleLoader.getString("Taming.Combat.Chance.Gore", goreChance) + LocaleLoader.getString("Perks.lucky.bonus", goreChanceLucky)); player.sendMessage(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Taming.Ability.Bonus.4"), LocaleLoader.getString("Taming.Ability.Bonus.5", Taming.shockProofModifier)));
} }
else { }
player.sendMessage(LocaleLoader.getString("Taming.Combat.Chance.Gore", goreChance));
} if (canSharpenedClaws) {
} if (skillValue < Taming.sharpenedClawsUnlockLevel) {
} player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Taming.Ability.Locked.3", Taming.sharpenedClawsUnlockLevel)));
} }
else {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Taming.Ability.Bonus.6"), LocaleLoader.getString("Taming.Ability.Bonus.7", Taming.sharpenedClawsBonusDamage)));
}
}
if (canGore) {
if (isLucky) {
player.sendMessage(LocaleLoader.getString("Taming.Combat.Chance.Gore", goreChance) + LocaleLoader.getString("Perks.lucky.bonus", goreChanceLucky));
}
else {
player.sendMessage(LocaleLoader.getString("Taming.Combat.Chance.Gore", goreChance));
}
}
}
}

View File

@ -1,146 +1,146 @@
package com.gmail.nossr50.skills.unarmed; package com.gmail.nossr50.commands.skills;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.skills.SkillCommand; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.skills.unarmed.Unarmed;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
public class UnarmedCommand extends SkillCommand { public class UnarmedCommand extends SkillCommand {
private String berserkLength; private String berserkLength;
private String berserkLengthEndurance; private String berserkLengthEndurance;
private String deflectChance; private String deflectChance;
private String deflectChanceLucky; private String deflectChanceLucky;
private String disarmChance; private String disarmChance;
private String disarmChanceLucky; private String disarmChanceLucky;
private String ironGripChance; private String ironGripChance;
private String ironGripChanceLucky; private String ironGripChanceLucky;
private String ironArmBonus; private String ironArmBonus;
private boolean canBerserk; private boolean canBerserk;
private boolean canDisarm; private boolean canDisarm;
private boolean canBonusDamage; private boolean canBonusDamage;
private boolean canDeflect; private boolean canDeflect;
private boolean canIronGrip; private boolean canIronGrip;
public UnarmedCommand() { public UnarmedCommand() {
super(SkillType.UNARMED); super(SkillType.UNARMED);
} }
@Override @Override
protected void dataCalculations() { protected void dataCalculations() {
//BERSERK // BERSERK
String[] berserkStrings = calculateLengthDisplayValues(); String[] berserkStrings = calculateLengthDisplayValues();
berserkLength = berserkStrings[0]; berserkLength = berserkStrings[0];
berserkLengthEndurance = berserkStrings[1]; berserkLengthEndurance = berserkStrings[1];
//DISARM // DISARM
String[] disarmStrings = calculateAbilityDisplayValues(Unarmed.disarmMaxBonusLevel, Unarmed.disarmMaxChance); String[] disarmStrings = calculateAbilityDisplayValues(Unarmed.disarmMaxBonusLevel, Unarmed.disarmMaxChance);
disarmChance = disarmStrings[0]; disarmChance = disarmStrings[0];
disarmChanceLucky = disarmStrings[1]; disarmChanceLucky = disarmStrings[1];
//DEFLECT // DEFLECT
String[] deflectStrings = calculateAbilityDisplayValues(Unarmed.deflectMaxBonusLevel, Unarmed.deflectMaxChance); String[] deflectStrings = calculateAbilityDisplayValues(Unarmed.deflectMaxBonusLevel, Unarmed.deflectMaxChance);
deflectChance = deflectStrings[0]; deflectChance = deflectStrings[0];
deflectChanceLucky = deflectStrings[1]; deflectChanceLucky = deflectStrings[1];
//IRON ARM // IRON ARM
if (skillValue >= ((Unarmed.ironArmMaxBonusDamage - 3) * Unarmed.ironArmIncreaseLevel)) { if (skillValue >= ((Unarmed.ironArmMaxBonusDamage - 3) * Unarmed.ironArmIncreaseLevel)) {
ironArmBonus = String.valueOf(Unarmed.ironArmMaxBonusDamage); ironArmBonus = String.valueOf(Unarmed.ironArmMaxBonusDamage);
} }
else { else {
ironArmBonus = String.valueOf(3 + (skillValue / Unarmed.ironArmIncreaseLevel)); ironArmBonus = String.valueOf(3 + (skillValue / Unarmed.ironArmIncreaseLevel));
} }
//IRON GRIP // IRON GRIP
String[] ironGripStrings = calculateAbilityDisplayValues(Unarmed.ironGripMaxBonusLevel, Unarmed.ironGripMaxChance); String[] ironGripStrings = calculateAbilityDisplayValues(Unarmed.ironGripMaxBonusLevel, Unarmed.ironGripMaxChance);
ironGripChance = ironGripStrings[0]; ironGripChance = ironGripStrings[0];
ironGripChanceLucky = ironGripStrings[1]; ironGripChanceLucky = ironGripStrings[1];
} }
@Override @Override
protected void permissionsCheck() { 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);
canDisarm = Permissions.disarm(player); canDisarm = Permissions.disarm(player);
canIronGrip = Permissions.ironGrip(player); canIronGrip = Permissions.ironGrip(player);
} }
@Override @Override
protected boolean effectsHeaderPermissions() { protected boolean effectsHeaderPermissions() {
return canBerserk || canBonusDamage || canDeflect || canDisarm || canIronGrip; return canBerserk || canBonusDamage || canDeflect || canDisarm || canIronGrip;
} }
@Override @Override
protected void effectsDisplay() { protected void effectsDisplay() {
luckyEffectsDisplay(); luckyEffectsDisplay();
if (canBerserk) { if (canBerserk) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Unarmed.Effect.0"), LocaleLoader.getString("Unarmed.Effect.1"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Unarmed.Effect.0"), LocaleLoader.getString("Unarmed.Effect.1")));
} }
if (canDisarm) { if (canDisarm) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Unarmed.Effect.2"), LocaleLoader.getString("Unarmed.Effect.3"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Unarmed.Effect.2"), LocaleLoader.getString("Unarmed.Effect.3")));
} }
if (canBonusDamage) { if (canBonusDamage) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Unarmed.Effect.4"), LocaleLoader.getString("Unarmed.Effect.5"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Unarmed.Effect.4"), LocaleLoader.getString("Unarmed.Effect.5")));
} }
if (canDeflect) { if (canDeflect) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Unarmed.Effect.6"), LocaleLoader.getString("Unarmed.Effect.7"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Unarmed.Effect.6"), LocaleLoader.getString("Unarmed.Effect.7")));
} }
if (canIronGrip) { if (canIronGrip) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Unarmed.Effect.8"), LocaleLoader.getString("Unarmed.Effect.9"))); player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Unarmed.Effect.8"), LocaleLoader.getString("Unarmed.Effect.9")));
} }
} }
@Override @Override
protected boolean statsHeaderPermissions() { protected boolean statsHeaderPermissions() {
return canBerserk || canBonusDamage || canDeflect || canDisarm || canIronGrip; return canBerserk || canBonusDamage || canDeflect || canDisarm || canIronGrip;
} }
@Override @Override
protected void statsDisplay() { protected void statsDisplay() {
if (canBonusDamage) { if (canBonusDamage) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Unarmed.Ability.Bonus.0"), LocaleLoader.getString("Unarmed.Ability.Bonus.1", ironArmBonus))); player.sendMessage(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Unarmed.Ability.Bonus.0"), LocaleLoader.getString("Unarmed.Ability.Bonus.1", ironArmBonus)));
} }
if (canDeflect) { if (canDeflect) {
if (isLucky) { if (isLucky) {
player.sendMessage(LocaleLoader.getString("Unarmed.Ability.Chance.ArrowDeflect", deflectChance) + LocaleLoader.getString("Perks.lucky.bonus", deflectChanceLucky)); player.sendMessage(LocaleLoader.getString("Unarmed.Ability.Chance.ArrowDeflect", deflectChance) + LocaleLoader.getString("Perks.lucky.bonus", deflectChanceLucky));
} }
else { else {
player.sendMessage(LocaleLoader.getString("Unarmed.Ability.Chance.ArrowDeflect", deflectChance)); player.sendMessage(LocaleLoader.getString("Unarmed.Ability.Chance.ArrowDeflect", deflectChance));
} }
} }
if (canDisarm) { if (canDisarm) {
if (isLucky) { if (isLucky) {
player.sendMessage(LocaleLoader.getString("Unarmed.Ability.Chance.Disarm", disarmChance) + LocaleLoader.getString("Perks.lucky.bonus", disarmChanceLucky)); player.sendMessage(LocaleLoader.getString("Unarmed.Ability.Chance.Disarm", disarmChance) + LocaleLoader.getString("Perks.lucky.bonus", disarmChanceLucky));
} }
else { else {
player.sendMessage(LocaleLoader.getString("Unarmed.Ability.Chance.Disarm", disarmChance)); player.sendMessage(LocaleLoader.getString("Unarmed.Ability.Chance.Disarm", disarmChance));
} }
} }
if (canIronGrip) { if (canIronGrip) {
if (isLucky) { if (isLucky) {
player.sendMessage(LocaleLoader.getString("Unarmed.Ability.Chance.IronGrip", ironGripChance) + LocaleLoader.getString("Perks.lucky.bonus", ironGripChanceLucky)); player.sendMessage(LocaleLoader.getString("Unarmed.Ability.Chance.IronGrip", ironGripChance) + LocaleLoader.getString("Perks.lucky.bonus", ironGripChanceLucky));
} }
else { else {
player.sendMessage(LocaleLoader.getString("Unarmed.Ability.Chance.IronGrip", ironGripChance)); player.sendMessage(LocaleLoader.getString("Unarmed.Ability.Chance.IronGrip", ironGripChance));
} }
} }
if (canBerserk) { if (canBerserk) {
if (hasEndurance) { if (hasEndurance) {
player.sendMessage(LocaleLoader.getString("Unarmed.Ability.Berserk.Length", berserkLength) + LocaleLoader.getString("Perks.activationtime.bonus", berserkLengthEndurance)); player.sendMessage(LocaleLoader.getString("Unarmed.Ability.Berserk.Length", berserkLength) + LocaleLoader.getString("Perks.activationtime.bonus", berserkLengthEndurance));
} }
else { else {
player.sendMessage(LocaleLoader.getString("Unarmed.Ability.Berserk.Length", berserkLength)); player.sendMessage(LocaleLoader.getString("Unarmed.Ability.Berserk.Length", berserkLength));
} }
} }
} }
} }

View File

@ -1,104 +1,103 @@
package com.gmail.nossr50.skills.woodcutting; package com.gmail.nossr50.commands.skills;
import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.skills.SkillCommand; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.skills.woodcutting.Woodcutting;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
public class WoodcuttingCommand extends SkillCommand { public class WoodcuttingCommand extends SkillCommand {
private String treeFellerLength; private String treeFellerLength;
private String treeFellerLengthEndurance; private String treeFellerLengthEndurance;
private String doubleDropChance; private String doubleDropChance;
private String doubleDropChanceLucky; private String doubleDropChanceLucky;
private boolean canTreeFell; private boolean canTreeFell;
private boolean canLeafBlow; private boolean canLeafBlow;
private boolean canDoubleDrop; private boolean canDoubleDrop;
private boolean doubleDropsDisabled; private boolean doubleDropsDisabled;
public WoodcuttingCommand() { public WoodcuttingCommand() {
super(SkillType.WOODCUTTING); super(SkillType.WOODCUTTING);
} }
@Override @Override
protected void dataCalculations() { protected void dataCalculations() {
//TREE FELLER // TREE FELLER
String[] treeFellerStrings = calculateLengthDisplayValues(); String[] treeFellerStrings = calculateLengthDisplayValues();
treeFellerLength = treeFellerStrings[0]; treeFellerLength = treeFellerStrings[0];
treeFellerLengthEndurance = treeFellerStrings[1]; treeFellerLengthEndurance = treeFellerStrings[1];
//DOUBLE DROPS // DOUBLE DROPS
AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); String[] doubleDropStrings = calculateAbilityDisplayValues(Woodcutting.doubleDropsMaxLevel, Woodcutting.doubleDropsMaxChance);
String[] doubleDropStrings = calculateAbilityDisplayValues(advancedConfig.getWoodcuttingDoubleDropMaxLevel(), advancedConfig.getWoodcuttingDoubleDropChance()); doubleDropChance = doubleDropStrings[0];
doubleDropChance = doubleDropStrings[0]; doubleDropChanceLucky = doubleDropStrings[1];
doubleDropChanceLucky = doubleDropStrings[1]; }
}
@Override
@Override protected void permissionsCheck() {
protected void permissionsCheck() { canTreeFell = Permissions.treeFeller(player);
canTreeFell = Permissions.treeFeller(player); canDoubleDrop = Permissions.doubleDrops(player, skill);
canDoubleDrop = Permissions.doubleDrops(player, skill); canLeafBlow = Permissions.leafBlower(player);
canLeafBlow = Permissions.leafBlower(player); doubleDropsDisabled = skill.getDoubleDropsDisabled();
doubleDropsDisabled = skill.getDoubleDropsDisabled(); }
}
@Override
@Override protected boolean effectsHeaderPermissions() {
protected boolean effectsHeaderPermissions() { return (canDoubleDrop && !doubleDropsDisabled) || canLeafBlow || canTreeFell;
return (canDoubleDrop && !doubleDropsDisabled) || canLeafBlow || canTreeFell; }
}
@Override
@Override protected void effectsDisplay() {
protected void effectsDisplay() { luckyEffectsDisplay();
luckyEffectsDisplay();
if (canTreeFell) {
if (canTreeFell) { player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Woodcutting.Effect.0"), LocaleLoader.getString("Woodcutting.Effect.1")));
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Woodcutting.Effect.0"), LocaleLoader.getString("Woodcutting.Effect.1"))); }
}
if (canLeafBlow) {
if (canLeafBlow) { player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Woodcutting.Effect.2"), LocaleLoader.getString("Woodcutting.Effect.3")));
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Woodcutting.Effect.2"), LocaleLoader.getString("Woodcutting.Effect.3"))); }
}
if (canDoubleDrop && !doubleDropsDisabled) {
if (canDoubleDrop && !doubleDropsDisabled) { player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Woodcutting.Effect.4"), LocaleLoader.getString("Woodcutting.Effect.5")));
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Woodcutting.Effect.4"), LocaleLoader.getString("Woodcutting.Effect.5"))); }
} }
}
@Override
@Override protected boolean statsHeaderPermissions() {
protected boolean statsHeaderPermissions() { return (canDoubleDrop && !doubleDropsDisabled) || canLeafBlow || canTreeFell;
return (canDoubleDrop && !doubleDropsDisabled) || canLeafBlow || canTreeFell; }
}
@Override
@Override protected void statsDisplay() {
protected void statsDisplay() { if (canLeafBlow) {
if (canLeafBlow) { int leafBlowerUnlockLevel = AdvancedConfig.getInstance().getLeafBlowUnlockLevel();
int leafBlowerUnlockLevel = AdvancedConfig.getInstance().getLeafBlowUnlockLevel();
if (skillValue < leafBlowerUnlockLevel) {
if (skillValue < leafBlowerUnlockLevel) { player.sendMessage(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 { player.sendMessage(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 && !doubleDropsDisabled) {
if (canDoubleDrop && !doubleDropsDisabled) { if (isLucky) {
if (isLucky) { player.sendMessage(LocaleLoader.getString("Woodcutting.Ability.Chance.DDrop", doubleDropChance) + LocaleLoader.getString("Perks.lucky.bonus", doubleDropChanceLucky));
player.sendMessage(LocaleLoader.getString("Woodcutting.Ability.Chance.DDrop", doubleDropChance) + LocaleLoader.getString("Perks.lucky.bonus", doubleDropChanceLucky)); }
} else {
else { player.sendMessage(LocaleLoader.getString("Woodcutting.Ability.Chance.DDrop", doubleDropChance));
player.sendMessage(LocaleLoader.getString("Woodcutting.Ability.Chance.DDrop", doubleDropChance)); }
} }
}
if (canTreeFell) {
if (canTreeFell) { if (hasEndurance) {
if (hasEndurance) { player.sendMessage(LocaleLoader.getString("Woodcutting.Ability.Length", treeFellerLength) + LocaleLoader.getString("Perks.activationtime.bonus", treeFellerLengthEndurance));
player.sendMessage(LocaleLoader.getString("Woodcutting.Ability.Length", treeFellerLength) + LocaleLoader.getString("Perks.activationtime.bonus", treeFellerLengthEndurance)); }
} else {
else { player.sendMessage(LocaleLoader.getString("Woodcutting.Ability.Length", treeFellerLength));
player.sendMessage(LocaleLoader.getString("Woodcutting.Ability.Length", treeFellerLength)); }
} }
} }
} }
}

View File

@ -1,29 +1,29 @@
package com.gmail.nossr50.spout.commands; package com.gmail.nossr50.commands.spout;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.datatypes.spout.huds.HudType;
import com.gmail.nossr50.spout.huds.HudType; import com.gmail.nossr50.locale.LocaleLoader;
public class MchudCommand extends SpoutCommand { public class MchudCommand extends SpoutCommand {
@Override @Override
protected boolean noArguments(Command command, CommandSender sender, String[] args) { protected boolean noArguments(Command command, CommandSender sender, String[] args) {
return false; return false;
} }
@Override @Override
protected boolean oneArgument(Command command, CommandSender sender, String[] args) { protected boolean oneArgument(Command command, CommandSender sender, String[] args) {
for (HudType hudType : HudType.values()) { for (HudType hudType : HudType.values()) {
if (hudType.toString().equalsIgnoreCase(args[0])) { if (hudType.toString().equalsIgnoreCase(args[0])) {
playerProfile.setHudType(hudType); playerProfile.setHudType(hudType);
spoutHud.initializeXpBar(); spoutHud.initializeXpBar();
spoutHud.updateXpBar(); spoutHud.updateXpBar();
return true; return true;
} }
} }
sender.sendMessage(LocaleLoader.getString("Commands.mchud.Invalid")); sender.sendMessage(LocaleLoader.getString("Commands.mchud.Invalid"));
return true; return true;
} }
} }

View File

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

View File

@ -1,64 +1,69 @@
package com.gmail.nossr50.spout.commands; package com.gmail.nossr50.commands.spout;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.skills.utilities.SkillTools; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.skills.SkillUtils;
public class XplockCommand extends SpoutCommand { public class XplockCommand extends SpoutCommand {
@Override @Override
protected boolean noArguments(Command command, CommandSender sender, String[] args) { protected boolean noArguments(Command command, CommandSender sender, String[] args) {
if (spoutHud.getXpBarLocked()) { if (spoutHud.getXpBarLocked()) {
unlockXpBar(sender); unlockXpBar(sender);
return true; return true;
} }
lockXpBar(sender, spoutHud.getLastGained()); lockXpBar(sender, spoutHud.getLastGained());
return true; return true;
} }
@Override @Override
protected boolean oneArgument(Command command, CommandSender sender, String[] args) { protected boolean oneArgument(Command command, CommandSender sender, String[] args) {
if (args[0].equalsIgnoreCase("on")) { if (args[0].equalsIgnoreCase("on")) {
lockXpBar(sender, spoutHud.getLastGained()); lockXpBar(sender, spoutHud.getLastGained());
return true; return true;
} }
if (args[0].equalsIgnoreCase("off")) { if (args[0].equalsIgnoreCase("off")) {
unlockXpBar(sender); unlockXpBar(sender);
return true; return true;
} }
if (!SkillTools.isSkill(args[0])) { if (!SkillUtils.isSkill(args[0])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid")); sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true; return true;
} }
SkillType skill = SkillType.getSkill(args[0]); SkillType skill = SkillType.getSkill(args[0]);
if (!Permissions.xplock(sender, skill)) { if (skill.isChildSkill()) {
sender.sendMessage(command.getPermissionMessage()); sender.sendMessage("Child skills are not yet supported by this command."); // TODO: Localize this
return true; return true;
} }
lockXpBar(sender, skill); if (!Permissions.xplock(sender, skill)) {
return true; sender.sendMessage(command.getPermissionMessage());
} return true;
}
private void lockXpBar(CommandSender sender, SkillType skill) {
if (skill != null) { lockXpBar(sender, skill);
spoutHud.setXpBarLocked(true); return true;
spoutHud.setSkillLock(skill); }
spoutHud.updateXpBar();
sender.sendMessage(LocaleLoader.getString("Commands.xplock.locked", SkillTools.getSkillName(skill))); private void lockXpBar(CommandSender sender, SkillType skill) {
} if (skill != null) {
} spoutHud.setXpBarLocked(true);
spoutHud.setSkillLock(skill);
private void unlockXpBar(CommandSender sender) { spoutHud.updateXpBar();
spoutHud.setXpBarLocked(false); sender.sendMessage(LocaleLoader.getString("Commands.xplock.locked", SkillUtils.getSkillName(skill)));
sender.sendMessage(LocaleLoader.getString("Commands.xplock.unlocked")); }
} }
}
private void unlockXpBar(CommandSender sender) {
spoutHud.setXpBarLocked(false);
sender.sendMessage(LocaleLoader.getString("Commands.xplock.unlocked"));
}
}

View File

@ -1,11 +1,10 @@
package com.gmail.nossr50.config; package com.gmail.nossr50.config;
public class AdvancedConfig extends ConfigLoader { public class AdvancedConfig extends AutoUpdateConfigLoader {
private static AdvancedConfig instance; private static AdvancedConfig instance;
private AdvancedConfig() { private AdvancedConfig() {
super("advanced.yml"); super("advanced.yml");
loadKeys();
} }
public static AdvancedConfig getInstance() { public static AdvancedConfig getInstance() {
@ -17,21 +16,24 @@ public class AdvancedConfig extends ConfigLoader {
} }
@Override @Override
protected void loadKeys() { protected void loadKeys() {}
// TODO Do we need to use this?
}
/* GENERAL */ /* GENERAL */
public int getAbilityLength() { return config.getInt("Skills.General.Ability_IncreaseLevel", 50); } public int getAbilityLength() { return config.getInt("Skills.General.Ability_IncreaseLevel", 50); }
/* ACROBATICS */ /* ACROBATICS */
public double getDodgeChanceMax() { return config.getDouble("Skills.Acrobatics.Dodge_ChanceMax", 20.0D); } public double getDodgeChanceMax() { return config.getDouble("Skills.Acrobatics.Dodge_ChanceMax", 20.0D); }
public int getDodgeMaxBonusLevel() { return config.getInt("Skills.Acrobatics.Dodge_MaxBonusLevel", 800); } public int getDodgeMaxBonusLevel() { return config.getInt("Skills.Acrobatics.Dodge_MaxBonusLevel", 800); }
public int getDodgeDamageModifier() { return config.getInt("Skills.Acrobatics.Dodge_DamageModifer", 2); }
public double getRollChanceMax() { return config.getDouble("Skills.Acrobatics.Roll_ChanceMax", 100.0D); } public double getRollChanceMax() { return config.getDouble("Skills.Acrobatics.Roll_ChanceMax", 100.0D); }
public int getRollMaxBonusLevel() { return config.getInt("Skills.Acrobatics.Roll_MaxBonusLevel", 1000); } public int getRollMaxBonusLevel() { return config.getInt("Skills.Acrobatics.Roll_MaxBonusLevel", 1000); }
public int getRollDamageThreshold() { return config.getInt("Skills.Acrobatics.Roll_DamageThreshold", 7); }
public double getGracefulRollChanceMax() { return config.getDouble("Skills.Acrobatics.GracefulRoll_ChanceMax", 100.0D); } public double getGracefulRollChanceMax() { return config.getDouble("Skills.Acrobatics.GracefulRoll_ChanceMax", 100.0D); }
public int getGracefulRollMaxBonusLevel() { return config.getInt("Skills.Acrobatics.GracefulRoll_MaxBonusLevel", 500); } public int getGracefulRollMaxBonusLevel() { return config.getInt("Skills.Acrobatics.GracefulRoll_MaxBonusLevel", 500); }
public int getGracefulRollDamageThreshold() { return config.getInt("Skills.Acrobatics.GracefulRoll_DamageThreshold", 14); }
public int getGracefulRollSuccessModifer() { return config.getInt("Skills.Acrobatics.GracefulRoll_SuccessModifier", 2); }
public int getDodgeXPModifier() { return config.getInt("Skills.Acrobatics.Dodge_XP_Modifier", 120); } public int getDodgeXPModifier() { return config.getInt("Skills.Acrobatics.Dodge_XP_Modifier", 120); }
public int getRollXPModifier() { return config.getInt("Skills.Acrobatics.Roll_XP_Modifier", 80); } public int getRollXPModifier() { return config.getInt("Skills.Acrobatics.Roll_XP_Modifier", 80); }
@ -63,6 +65,7 @@ public class AdvancedConfig extends ConfigLoader {
public int getGreaterImpactBonusDamage() { return config.getInt("Skills.Axes.GreaterImpact_BonusDamage", 2); } public int getGreaterImpactBonusDamage() { return config.getInt("Skills.Axes.GreaterImpact_BonusDamage", 2); }
public int getArmorImpactIncreaseLevel() { return config.getInt("Skills.Axes.ArmorImpact_IncreaseLevel", 50); } public int getArmorImpactIncreaseLevel() { return config.getInt("Skills.Axes.ArmorImpact_IncreaseLevel", 50); }
public double getImpactChance() { return config.getDouble("Skills.Axes.ArmorImpact_Chance", 25.0D); }
public double getArmorImpactMaxDurabilityDamage() { return config.getDouble("Skills.Axes.ArmorImpact_MaxPercentageDurabilityDamage", 20.0D); } public double getArmorImpactMaxDurabilityDamage() { return config.getDouble("Skills.Axes.ArmorImpact_MaxPercentageDurabilityDamage", 20.0D); }
public int getSkullSplitterModifier() { return config.getInt("Skills.Axes.SkullSplitter_DamagerModifier", 2); } public int getSkullSplitterModifier() { return config.getInt("Skills.Axes.SkullSplitter_DamagerModifier", 2); }
@ -107,7 +110,10 @@ public class AdvancedConfig extends ConfigLoader {
public int getHerbalismDoubleDropsMaxLevel() { return config.getInt("Skills.Herbalism.DoubleDrops_MaxBonusLevel", 1000); } public int getHerbalismDoubleDropsMaxLevel() { return config.getInt("Skills.Herbalism.DoubleDrops_MaxBonusLevel", 1000); }
public double getHylianLuckChanceMax() { return config.getDouble("Skills.Herbalism.HylianLuck_ChanceMax", 10.0D); } public double getHylianLuckChanceMax() { return config.getDouble("Skills.Herbalism.HylianLuck_ChanceMax", 10.0D); }
public int getHylianLucksMaxLevel() { return config.getInt("Skills.Herbalism.HylianLuck_MaxBonusLevel", 1000); } public int getHylianLuckMaxLevel() { return config.getInt("Skills.Herbalism.HylianLuck_MaxBonusLevel", 1000); }
public double getShroomThumbChanceMax() { return config.getDouble("Skills.Herbalism.ShroomThumb_ChanceMax", 50.0D); }
public int getShroomThumbMaxLevel() { return config.getInt("Skills.Herbalism.ShroomThumb_MaxBonusLevel", 1500); }
/* MINING */ /* MINING */
public double getMiningDoubleDropChance() { return config.getDouble("Skills.Mining.DoubleDrops_ChanceMax", 100.0D); } public double getMiningDoubleDropChance() { return config.getDouble("Skills.Mining.DoubleDrops_ChanceMax", 100.0D); }
@ -122,6 +128,51 @@ public class AdvancedConfig extends ConfigLoader {
public int getBlastMiningRank7() { return config.getInt("Skills.Mining.BlastMining_Rank7", 875); } public int getBlastMiningRank7() { return config.getInt("Skills.Mining.BlastMining_Rank7", 875); }
public int getBlastMiningRank8() { return config.getInt("Skills.Mining.BlastMining_Rank8", 1000); } public int getBlastMiningRank8() { return config.getInt("Skills.Mining.BlastMining_Rank8", 1000); }
public double getBlastDamageDecreaseRank1() { return config.getDouble("Skills.Mining.BlastDamageDecrease_Rank1", 0.0D); }
public double getBlastDamageDecreaseRank2() { return config.getDouble("Skills.Mining.BlastDamageDecrease_Rank2", 0.0D); }
public double getBlastDamageDecreaseRank3() { return config.getDouble("Skills.Mining.BlastDamageDecrease_Rank3", 0.0D); }
public double getBlastDamageDecreaseRank4() { return config.getDouble("Skills.Mining.BlastDamageDecrease_Rank4", 25.0D); }
public double getBlastDamageDecreaseRank5() { return config.getDouble("Skills.Mining.BlastDamageDecrease_Rank5", 25.0D); }
public double getBlastDamageDecreaseRank6() { return config.getDouble("Skills.Mining.BlastDamageDecrease_Rank6", 50.0D); }
public double getBlastDamageDecreaseRank7() { return config.getDouble("Skills.Mining.BlastDamageDecrease_Rank7", 50.0D); }
public double getBlastDamageDecreaseRank8() { return config.getDouble("Skills.Mining.BlastDamageDecrease_Rank8", 100.0D); }
public double getOreBonusRank1() { return config.getDouble("Skills.Mining.OreBonus_Rank1", 35.0D); }
public double getOreBonusRank2() { return config.getDouble("Skills.Mining.OreBonus_Rank2", 40.0D); }
public double getOreBonusRank3() { return config.getDouble("Skills.Mining.OreBonus_Rank3", 45.0D); }
public double getOreBonusRank4() { return config.getDouble("Skills.Mining.OreBonus_Rank4", 50.0D); }
public double getOreBonusRank5() { return config.getDouble("Skills.Mining.OreBonus_Rank5", 55.0D); }
public double getOreBonusRank6() { return config.getDouble("Skills.Mining.OreBonus_Rank6", 60.0D); }
public double getOreBonusRank7() { return config.getDouble("Skills.Mining.OreBonus_Rank7", 65.0D); }
public double getOreBonusRank8() { return config.getDouble("Skills.Mining.OreBonus_Rank8", 70.0D); }
public double getDebrisReductionRank1() { return config.getDouble("Skills.Mining.DebrisReduction_Rank1", 10.0D); }
public double getDebrisReductionRank2() { return config.getDouble("Skills.Mining.DebrisReduction_Rank2", 20.0D); }
public double getDebrisReductionRank3() { return config.getDouble("Skills.Mining.DebrisReduction_Rank3", 30.0D); }
public double getDebrisReductionRank4() { return config.getDouble("Skills.Mining.DebrisReduction_Rank4", 30.0D); }
public double getDebrisReductionRank5() { return config.getDouble("Skills.Mining.DebrisReduction_Rank5", 30.0D); }
public double getDebrisReductionRank6() { return config.getDouble("Skills.Mining.DebrisReduction_Rank6", 30.0D); }
public double getDebrisReductionRank7() { return config.getDouble("Skills.Mining.DebrisReduction_Rank7", 30.0D); }
public double getDebrisReductionRank8() { return config.getDouble("Skills.Mining.DebrisReduction_Rank8", 30.0D); }
public int getDropMultiplierRank1() { return config.getInt("Skills.Mining.DropMultiplier_Rank1", 1); }
public int getDropMultiplierRank2() { return config.getInt("Skills.Mining.DropMultiplier_Rank2", 1); }
public int getDropMultiplierRank3() { return config.getInt("Skills.Mining.DropMultiplier_Rank3", 1); }
public int getDropMultiplierRank4() { return config.getInt("Skills.Mining.DropMultiplier_Rank4", 1); }
public int getDropMultiplierRank5() { return config.getInt("Skills.Mining.DropMultiplier_Rank5", 2); }
public int getDropMultiplierRank6() { return config.getInt("Skills.Mining.DropMultiplier_Rank6", 2); }
public int getDropMultiplierRank7() { return config.getInt("Skills.Mining.DropMultiplier_Rank7", 3); }
public int getDropMultiplierRank8() { return config.getInt("Skills.Mining.DropMultiplier_Rank8", 3); }
public double getBlastRadiusModifierRank1() { return config.getDouble("Skills.Mining.BlastRadiusModifier_Rank1", 1.0); }
public double getBlastRadiusModifierRank2() { return config.getDouble("Skills.Mining.BlastRadiusModifier_Rank2", 1.0); }
public double getBlastRadiusModifierRank3() { return config.getDouble("Skills.Mining.BlastRadiusModifier_Rank3", 2.0); }
public double getBlastRadiusModifierRank4() { return config.getDouble("Skills.Mining.BlastRadiusModifier_Rank4", 2.0); }
public double getBlastRadiusModifierRank5() { return config.getDouble("Skills.Mining.BlastRadiusModifier_Rank5", 3.0); }
public double getBlastRadiusModifierRank6() { return config.getDouble("Skills.Mining.BlastRadiusModifier_Rank6", 3.0); }
public double getBlastRadiusModifierRank7() { return config.getDouble("Skills.Mining.BlastRadiusModifier_Rank7", 4.0); }
public double getBlastRadiusModifierRank8() { return config.getDouble("Skills.Mining.BlastRadiusModifier_Rank8", 4.0); }
/* REPAIR */ /* REPAIR */
public double getRepairMasteryMaxBonus() { return config.getDouble("Skills.Repair.RepairMastery_MaxBonusPercentage", 200.0D); } public double getRepairMasteryMaxBonus() { return config.getDouble("Skills.Repair.RepairMastery_MaxBonusPercentage", 200.0D); }
public int getRepairMasteryMaxLevel() { return config.getInt("Skills.Repair.RepairMastery_MaxBonusLevel", 1000); } public int getRepairMasteryMaxLevel() { return config.getInt("Skills.Repair.RepairMastery_MaxBonusLevel", 1000); }
@ -193,6 +244,8 @@ public class AdvancedConfig extends ConfigLoader {
public int getThickFurUnlock() { return config.getInt("Skills.Taming.ThickFur_UnlockLevel", 250); } public int getThickFurUnlock() { return config.getInt("Skills.Taming.ThickFur_UnlockLevel", 250); }
public int getThickFurModifier() { return config.getInt("Skills.Taming.ThickFur_Modifier", 2); } public int getThickFurModifier() { return config.getInt("Skills.Taming.ThickFur_Modifier", 2); }
public int getHolyHoundUnlock() {return config.getInt("Skills.Taming.HolyHound_UnlockLevel", 375); }
public int getShockProofUnlock() { return config.getInt("Skills.Taming.ShockProof_UnlockLevel", 500); } public int getShockProofUnlock() { return config.getInt("Skills.Taming.ShockProof_UnlockLevel", 500); }
public int getShockProofModifier() { return config.getInt("Skills.Taming.ShockProof_Modifier", 6); } public int getShockProofModifier() { return config.getInt("Skills.Taming.ShockProof_Modifier", 6); }

View File

@ -0,0 +1,128 @@
package com.gmail.nossr50.config;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import com.gmail.nossr50.metrics.MetricsManager;
public abstract class AutoUpdateConfigLoader extends ConfigLoader {
public AutoUpdateConfigLoader(String relativePath, String fileName) {
super(relativePath, fileName);
}
public AutoUpdateConfigLoader(String fileName) {
super(fileName);
}
@Override
protected void loadFile() {
super.loadFile();
FileConfiguration internalConfig = YamlConfiguration.loadConfiguration(plugin.getResource(fileName));
Set<String> configKeys = config.getKeys(true);
Set<String> internalConfigKeys = internalConfig.getKeys(true);
boolean needSave = false;
Set<String> oldKeys = new HashSet<String>(configKeys);
oldKeys.removeAll(internalConfigKeys);
Set<String> newKeys = new HashSet<String>(internalConfigKeys);
newKeys.removeAll(configKeys);
// Don't need a re-save if we have old keys sticking around?
// Would be less saving, but less... correct?
if (!newKeys.isEmpty() || !oldKeys.isEmpty()) {
needSave = true;
}
for (String key : oldKeys) {
plugin.debug("Removing unused key: " + key);
config.set(key, null);
}
for (String key : newKeys) {
plugin.debug("Adding new key: " + key + " = " + internalConfig.get(key));
config.set(key, internalConfig.get(key));
}
if (needSave) {
// Get Bukkit's version of an acceptable config with new keys, and no old keys
String output = config.saveToString();
// Convert to the superior 4 space indentation
output = output.replace(" ", " ");
// Rip out Bukkit's attempt to save comments at the top of the file
while (output.indexOf('#') != -1) {
output = output.substring(output.indexOf('\n', output.indexOf('#')) + 1);
}
// Read the internal config to get comments, then put them in the new one
try {
// Read internal
BufferedReader reader = new BufferedReader(new InputStreamReader(plugin.getResource(fileName)));
HashMap<String, String> comments = new HashMap<String, String>();
String temp = "";
String line;
while ((line = reader.readLine()) != null) {
if (line.contains("#")) {
temp += line + "\n";
}
else if (line.contains(":")) {
line = line.substring(0, line.indexOf(":") + 1);
if (!temp.isEmpty()) {
comments.put(line, temp);
temp = "";
}
}
}
// Dump to the new one
for (String key : comments.keySet()) {
if (output.indexOf(key) != -1) {
output = output.substring(0, output.indexOf(key)) + comments.get(key) + output.substring(output.indexOf(key));
}
}
}
catch (Exception e) {
e.printStackTrace();
}
// Save it
try {
String saveName = fileName;
// At this stage we cannot guarantee that Config has been loaded, so we do the check directly here
if (!plugin.getConfig().getBoolean("General.Config_Update_Overwrite", true)) {
saveName += ".new";
}
BufferedWriter writer = new BufferedWriter(new FileWriter(new File(plugin.getDataFolder(), saveName)));
writer.write(output);
writer.flush();
writer.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
else {
for (String key : configKeys) {
if (!config.isConfigurationSection(key) && !config.get(key).equals(internalConfig.get(key))) {
MetricsManager.customConfig();
break;
}
}
}
}
}

View File

@ -6,16 +6,15 @@ import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import com.gmail.nossr50.skills.utilities.AbilityType; import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.StringUtils;
public class Config extends ConfigLoader { public class Config extends AutoUpdateConfigLoader {
private static Config instance; private static Config instance;
private Config() { private Config() {
super("config.yml"); super("config.yml");
loadKeys();
} }
public static Config getInstance() { public static Config getInstance() {
@ -44,6 +43,8 @@ public class Config extends ConfigLoader {
public boolean getEventCallbackEnabled() { return config.getBoolean("General.Event_Callback", true); } public boolean getEventCallbackEnabled() { return config.getBoolean("General.Event_Callback", true); }
public boolean getBackupsEnabled() { return config.getBoolean("General.Generate_Backups", 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 getPartyDisplayNames() { return config.getBoolean("Commands.p.Use_Display_Names", true); } public boolean getPartyDisplayNames() { return config.getBoolean("Commands.p.Use_Display_Names", true); }
public boolean getAdminDisplayNames() { return config.getBoolean("Commands.a.Use_Display_Names", true); } public boolean getAdminDisplayNames() { return config.getBoolean("Commands.a.Use_Display_Names", true); }
@ -104,6 +105,13 @@ public class Config extends ConfigLoader {
public int getChimaeraItemId() { return config.getInt("Items.Chimaera_Wing.Item_ID", 288); } public int getChimaeraItemId() { return config.getInt("Items.Chimaera_Wing.Item_ID", 288); }
public boolean getChimaeraEnabled() { return config.getBoolean("Items.Chimaera_Wing.Enabled", true); } public boolean getChimaeraEnabled() { return config.getBoolean("Items.Chimaera_Wing.Enabled", true); }
/* Particles */
public boolean getAbilityActivationEffectEnabled() { return config.getBoolean("Particles.Ability_Activation", true); }
public boolean getAbilityDeactivationEffectEnabled() { return config.getBoolean("Particles.Ability_Deactivation", true); }
public boolean getDodgeEffectEnabled() { return config.getBoolean("Particles.Dodge", true); }
public boolean getBleedEffectEnabled() { return config.getBoolean("Particles.Bleed", true); }
public boolean getGreaterImpactEffectEnabled() { return config.getBoolean("Particles.Greater_Impact", true); }
/* PARTY SETTINGS */ /* PARTY SETTINGS */
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); }

View File

@ -1,170 +1,80 @@
package com.gmail.nossr50.config; package com.gmail.nossr50.config;
import java.io.BufferedReader; import java.io.File;
import java.io.BufferedWriter; import java.io.FileOutputStream;
import java.io.File; import java.io.InputStream;
import java.io.FileOutputStream; import java.io.OutputStream;
import java.io.FileWriter;
import java.io.InputStream; import org.bukkit.configuration.file.FileConfiguration;
import java.io.InputStreamReader; import org.bukkit.configuration.file.YamlConfiguration;
import java.io.OutputStream;
import java.util.HashMap; import com.gmail.nossr50.mcMMO;
import java.util.HashSet;
import java.util.Set; public abstract class ConfigLoader {
protected static final mcMMO plugin = mcMMO.p;
import org.bukkit.configuration.file.FileConfiguration; protected String fileName;
import org.bukkit.configuration.file.YamlConfiguration; protected File configFile;
protected FileConfiguration config;
import com.gmail.nossr50.mcMMO;
public ConfigLoader(String relativePath, String fileName) {
public abstract class ConfigLoader { this.fileName = fileName;
protected static final mcMMO plugin = mcMMO.p; configFile = new File(plugin.getDataFolder(), relativePath + File.separator + fileName);
protected String fileName; loadFile();
protected File configFile; }
protected FileConfiguration config;
public ConfigLoader(String fileName) {
public ConfigLoader(String relativePath, String fileName) { this.fileName = fileName;
this.fileName = fileName; configFile = new File(plugin.getDataFolder(), fileName);
configFile = new File(plugin.getDataFolder(), relativePath + File.separator + fileName); loadFile();
loadFile(); }
}
protected void loadFile() {
public ConfigLoader(String fileName) { if (!configFile.exists()) {
this.fileName = fileName; plugin.getLogger().info("Creating mcMMO " + fileName + " File...");
configFile = new File(plugin.getDataFolder(), fileName); createFile();
loadFile(); }
} else {
plugin.getLogger().info("Loading mcMMO " + fileName + " File...");
protected void loadFile() { }
if (!configFile.exists()) {
plugin.getLogger().info("Creating mcMMO " + fileName + " File..."); config = YamlConfiguration.loadConfiguration(configFile);
createFile(); }
}
else { protected abstract void loadKeys();
plugin.getLogger().info("Loading mcMMO " + fileName + " File...");
} protected void createFile() {
if (configFile.exists()) {
config = YamlConfiguration.loadConfiguration(configFile); return;
FileConfiguration internalConfig = YamlConfiguration.loadConfiguration(plugin.getResource(fileName)); }
Set<String> configKeys = config.getKeys(true); configFile.getParentFile().mkdirs();
Set<String> internalConfigKeys = internalConfig.getKeys(true);
InputStream inputStream = plugin.getResource(fileName);
boolean needSave = false;
if (inputStream != null) {
Set<String> oldKeys = new HashSet<String>(configKeys); try {
oldKeys.removeAll(internalConfigKeys); copyStreamToFile(inputStream, configFile);
}
Set<String> newKeys = new HashSet<String>(internalConfigKeys); catch (Exception e) {
newKeys.removeAll(configKeys); e.printStackTrace();
}
// Don't need a re-save if we have old keys sticking around? }
// Would be less saving, but less... correct? else {
if (!newKeys.isEmpty() || !oldKeys.isEmpty()) { plugin.getLogger().severe("Missing resource file: '" + fileName + "' please notify the plugin authors");
needSave = true; }
} }
for (String key : oldKeys) { private static void copyStreamToFile(InputStream inputStream, File file) throws Exception {
plugin.debug("Removing unused key: " + key); OutputStream outputStream = new FileOutputStream(file);
config.set(key, null);
} int read = 0;
byte[] bytes = new byte[1024];
for (String key : newKeys) {
plugin.debug("Adding new key: " + key + " = " + internalConfig.get(key)); while ((read = inputStream.read(bytes)) != -1) {
config.set(key, internalConfig.get(key)); outputStream.write(bytes, 0, read);
} }
if (needSave) { inputStream.close();
// Get Bukkit's version of an acceptable config with new keys, and no old keys outputStream.close();
String output = config.saveToString(); }
}
// Convert to the superior 4 space indentation
output = output.replace(" ", " ");
// Rip out Bukkit's attempt to save comments at the top of the file
while (output.indexOf('#') != -1) {
output = output.substring(output.indexOf('\n', output.indexOf('#'))+1);
}
// Read the internal config to get comments, then put them in the new one
try {
// Read internal
BufferedReader reader = new BufferedReader(new InputStreamReader(plugin.getResource(fileName)));
HashMap<String, String> comments = new HashMap<String, String>();
String temp = "";
String line;
while ((line = reader.readLine()) != null) {
if (line.contains("#")) {
temp += line + "\n";
}
else if (line.contains(":")) {
line = line.substring(0, line.indexOf(":") + 1);
if(!temp.isEmpty()) {
comments.put(line, temp);
temp = "";
}
}
}
// Dump to the new one
for (String key : comments.keySet()) {
if (output.indexOf(key) != -1) {
output = output.substring(0, output.indexOf(key)) + comments.get(key) + output.substring(output.indexOf(key));
}
}
}
catch (Exception e) {
e.printStackTrace();
}
// Save it
try {
BufferedWriter writer = new BufferedWriter(new FileWriter(new File(plugin.getDataFolder(), fileName)));
writer.write(output);
writer.flush();
writer.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
protected abstract void loadKeys();
protected void createFile() {
if (configFile.exists()) {
return;
}
configFile.getParentFile().mkdirs();
InputStream inputStream = plugin.getResource(fileName);
if (inputStream != null) {
try {
copyStreamToFile(inputStream, configFile);
} catch (Exception e) {
e.printStackTrace();
}
}
else {
plugin.getLogger().severe("Missing resource file: '" + fileName + "' please notify the plugin authors");
}
}
private static void copyStreamToFile(InputStream inputStream, File file) throws Exception {
OutputStream outputStream = new FileOutputStream(file);
int read = 0;
byte[] bytes = new byte[1024];
while ((read = inputStream.read(bytes)) != -1) {
outputStream.write(bytes, 0, read);
}
inputStream.close();
outputStream.close();
}
}

View File

@ -1,94 +1,101 @@
package com.gmail.nossr50.mods.config; package com.gmail.nossr50.config.mods;
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.Set; import java.util.Set;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import com.gmail.nossr50.config.ConfigLoader; import com.gmail.nossr50.config.ConfigLoader;
import com.gmail.nossr50.mods.datatypes.CustomItem; import com.gmail.nossr50.datatypes.mods.CustomItem;
import com.gmail.nossr50.skills.repair.Repairable; import com.gmail.nossr50.skills.repair.Repairable;
import com.gmail.nossr50.skills.repair.RepairableFactory; import com.gmail.nossr50.skills.repair.RepairableFactory;
public class CustomArmorConfig extends ConfigLoader{ public class CustomArmorConfig extends ConfigLoader {
private static CustomArmorConfig instance; private static CustomArmorConfig instance;
private List<Repairable> repairables;
public List<Integer> customBootIDs = new ArrayList<Integer>(); private List<Repairable> repairables;
public List<Integer> customChestplateIDs = new ArrayList<Integer>();
public List<Integer> customHelmetIDs = new ArrayList<Integer>(); public List<Integer> customBootIDs = new ArrayList<Integer>();
public List<Integer> customLeggingIDs = new ArrayList<Integer>(); public List<Integer> customChestplateIDs = new ArrayList<Integer>();
public List<Integer> customIDs = new ArrayList<Integer>(); public List<Integer> customHelmetIDs = new ArrayList<Integer>();
public List<CustomItem> customArmorList = new ArrayList<CustomItem>(); public List<Integer> customLeggingIDs = new ArrayList<Integer>();
public HashMap<Integer, CustomItem> customArmor = new HashMap<Integer, CustomItem>(); public List<Integer> customIDs = new ArrayList<Integer>();
public CustomArmorConfig() { public List<CustomItem> customArmorList = new ArrayList<CustomItem>();
super("ModConfigs", "armor.yml"); public HashMap<Integer, CustomItem> customArmor = new HashMap<Integer, CustomItem>();
loadKeys();
} public CustomArmorConfig() {
super("ModConfigs", "armor.yml");
public static CustomArmorConfig getInstance() { loadKeys();
if (instance == null) { }
instance = new CustomArmorConfig();
} public static CustomArmorConfig getInstance() {
if (instance == null) {
return instance; instance = new CustomArmorConfig();
} }
@Override return instance;
protected void loadKeys() { }
repairables = new ArrayList<Repairable>();
public List<Repairable> getLoadedRepairables() {
loadArmor("Boots", customBootIDs); if (repairables == null) {
loadArmor("Chestplates", customChestplateIDs); return new ArrayList<Repairable>();
loadArmor("Helmets", customHelmetIDs); }
loadArmor("Leggings", customLeggingIDs);
} return repairables;
}
private void loadArmor(String armorType, List<Integer> idList) {
ConfigurationSection armorSection = config.getConfigurationSection(armorType); @Override
protected void loadKeys() {
if (armorSection == null) repairables = new ArrayList<Repairable>();
return;
loadArmor("Boots", customBootIDs);
Set<String> armorConfigSet = armorSection.getKeys(false); loadArmor("Chestplates", customChestplateIDs);
loadArmor("Helmets", customHelmetIDs);
for (String armorName : armorConfigSet) { loadArmor("Leggings", customLeggingIDs);
int id = config.getInt(armorType + "." + armorName + ".ID", 0); }
boolean repairable = config.getBoolean(armorType + "." + armorName + ".Repairable");
int repairID = config.getInt(armorType + "." + armorName + ".Repair_Material_ID", 0); private void loadArmor(String armorType, List<Integer> idList) {
byte repairData = (byte) config.getInt(armorType + "." + armorName + ".Repair_Material_Data_Value", 0); ConfigurationSection armorSection = config.getConfigurationSection(armorType);
int repairQuantity = config.getInt(armorType + "." + armorName + ".Repair_Material_Quantity", 0);
short durability = (short) config.getInt(armorType + "." + armorName + ".Durability", 0); if (armorSection == null) {
return;
if (id == 0) { }
plugin.getLogger().warning("Missing ID. This item will be skipped.");
continue; Set<String> armorConfigSet = armorSection.getKeys(false);
}
for (String armorName : armorConfigSet) {
if (repairable && (repairID == 0 || repairQuantity == 0 || durability == 0)) { int id = config.getInt(armorType + "." + armorName + ".ID", 0);
plugin.getLogger().warning("Incomplete repair information. This item will be unrepairable."); boolean repairable = config.getBoolean(armorType + "." + armorName + ".Repairable");
repairable = false; 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);
CustomItem armor; short durability = (short) config.getInt(armorType + "." + armorName + ".Durability", 0);
if (repairable) { if (id == 0) {
repairables.add(RepairableFactory.getRepairable(id, repairID, repairData, repairQuantity, durability)); plugin.getLogger().warning("Missing ID. This item will be skipped.");
} continue;
}
armor = new CustomItem(id, durability);
if (repairable && (repairID == 0 || repairQuantity == 0 || durability == 0)) {
idList.add(id); plugin.getLogger().warning("Incomplete repair information. This item will be unrepairable.");
customIDs.add(id); repairable = false;
customArmorList.add(armor); }
customArmor.put(id, armor);
} CustomItem armor;
}
if (repairable) {
public List<Repairable> getLoadedRepairables() { repairables.add(RepairableFactory.getRepairable(id, repairID, repairData, repairQuantity, durability));
if (repairables == null) return new ArrayList<Repairable>(); }
return repairables;
} armor = new CustomItem(id, durability);
}
idList.add(id);
customIDs.add(id);
customArmorList.add(armor);
customArmor.put(id, armor);
}
}
}

View File

@ -1,117 +1,120 @@
package com.gmail.nossr50.mods.config; package com.gmail.nossr50.config.mods;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack; 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;
import com.gmail.nossr50.mods.datatypes.CustomBlock; import com.gmail.nossr50.datatypes.mods.CustomBlock;
public class CustomBlocksConfig extends ConfigLoader { public class CustomBlockConfig extends ConfigLoader {
private static CustomBlocksConfig instance; private static CustomBlockConfig instance;
public List<ItemStack> customExcavationBlocks = new ArrayList<ItemStack>();
public List<ItemStack> customHerbalismBlocks = new ArrayList<ItemStack>(); public List<ItemStack> customExcavationBlocks = new ArrayList<ItemStack>();
public List<ItemStack> customMiningBlocks = new ArrayList<ItemStack>(); public List<ItemStack> customHerbalismBlocks = new ArrayList<ItemStack>();
public List<ItemStack> customWoodcuttingBlocks = new ArrayList<ItemStack>(); public List<ItemStack> customMiningBlocks = new ArrayList<ItemStack>();
public List<ItemStack> customOres = new ArrayList<ItemStack>(); public List<ItemStack> customWoodcuttingBlocks = new ArrayList<ItemStack>();
public List<ItemStack> customLogs = new ArrayList<ItemStack>(); public List<ItemStack> customOres = new ArrayList<ItemStack>();
public List<ItemStack> customLeaves = new ArrayList<ItemStack>(); public List<ItemStack> customLogs = new ArrayList<ItemStack>();
public List<ItemStack> customAbilityBlocks = new ArrayList<ItemStack>(); public List<ItemStack> customLeaves = new ArrayList<ItemStack>();
public List<ItemStack> customItems = new ArrayList<ItemStack>(); public List<ItemStack> customAbilityBlocks = new ArrayList<ItemStack>();
public List<CustomBlock> customBlocks = new ArrayList<CustomBlock>(); public List<ItemStack> customItems = new ArrayList<ItemStack>();
public CustomBlocksConfig() { public List<CustomBlock> customBlocks = new ArrayList<CustomBlock>();
super("ModConfigs", "blocks.yml");
loadKeys(); public CustomBlockConfig() {
} super("ModConfigs", "blocks.yml");
loadKeys();
public static CustomBlocksConfig getInstance() { }
if (instance == null) {
instance = new CustomBlocksConfig(); public static CustomBlockConfig getInstance() {
} if (instance == null) {
instance = new CustomBlockConfig();
return instance; }
}
return instance;
@Override }
protected void loadKeys() {
loadBlocks("Excavation", customExcavationBlocks); @Override
loadBlocks("Herbalism", customHerbalismBlocks); protected void loadKeys() {
loadBlocks("Mining", customMiningBlocks); loadBlocks("Excavation", customExcavationBlocks);
loadBlocks("Woodcutting", customWoodcuttingBlocks); loadBlocks("Herbalism", customHerbalismBlocks);
loadBlocks("Ability_Blocks", customAbilityBlocks); loadBlocks("Mining", customMiningBlocks);
} loadBlocks("Woodcutting", customWoodcuttingBlocks);
loadBlocks("Ability_Blocks", customAbilityBlocks);
private void loadBlocks(String skillType, List<ItemStack> blockList) { }
ConfigurationSection skillSection = config.getConfigurationSection(skillType);
private void loadBlocks(String skillType, List<ItemStack> blockList) {
if (skillSection == null) ConfigurationSection skillSection = config.getConfigurationSection(skillType);
return;
if (skillSection == null) {
Set<String> skillConfigSet = skillSection.getKeys(false); return;
}
for (String blockName : skillConfigSet) {
int id = config.getInt(skillType + "." + blockName + ".ID", 0); Set<String> skillConfigSet = skillSection.getKeys(false);
byte data = (byte) config.getInt(skillType + "." + blockName + ".Data_Value", 0);
int xp = config.getInt(skillType + "." + blockName + ".XP_Gain", 0); for (String blockName : skillConfigSet) {
int tier = config.getInt(skillType + "." + blockName + ".Tier", 1); int id = config.getInt(skillType + "." + blockName + ".ID", 0);
boolean dropItem = config.getBoolean(skillType + "." + blockName + ".Drop_Item", false); byte data = (byte) config.getInt(skillType + "." + blockName + ".Data_Value", 0);
int dropID = config.getInt(skillType + "." + blockName + ".Drop_Item_ID", 0); int xp = config.getInt(skillType + "." + blockName + ".XP_Gain", 0);
byte dropData = (byte) config.getInt(skillType + "." + blockName + ".Drop_Item_Data_Value", 0); int tier = config.getInt(skillType + "." + blockName + ".Tier", 1);
int minimumDropAmount = config.getInt(skillType + "." + blockName + ".Min_Drop_Item_Amount", 1); boolean dropItem = config.getBoolean(skillType + "." + blockName + ".Drop_Item", false);
int maxiumDropAmount = config.getInt(skillType + "." + blockName + ".Max_Drop_Item_Amount", 1); int dropID = config.getInt(skillType + "." + blockName + ".Drop_Item_ID", 0);
byte dropData = (byte) config.getInt(skillType + "." + blockName + ".Drop_Item_Data_Value", 0);
CustomBlock block; int minimumDropAmount = config.getInt(skillType + "." + blockName + ".Min_Drop_Item_Amount", 1);
ItemStack itemDrop; int maxiumDropAmount = config.getInt(skillType + "." + blockName + ".Max_Drop_Item_Amount", 1);
ItemStack blockItem;
CustomBlock block;
if (id == 0) { ItemStack itemDrop;
plugin.getLogger().warning("Missing ID. This block will be skipped."); ItemStack blockItem;
continue;
} if (id == 0) {
plugin.getLogger().warning("Missing ID. This block will be skipped.");
if (skillType.equals("Ability_Blocks")) { continue;
blockItem = (new MaterialData(id, data)).toItemStack(1); }
blockList.add(blockItem); if (skillType.equals("Ability_Blocks")) {
continue; blockItem = (new MaterialData(id, data)).toItemStack(1);
}
blockList.add(blockItem);
if (dropItem && dropID == 0) { continue;
plugin.getLogger().warning("Incomplete item drop information. This block will drop itself."); }
dropItem = false;
} if (dropItem && dropID == 0) {
plugin.getLogger().warning("Incomplete item drop information. This block will drop itself.");
if (dropItem) { dropItem = false;
itemDrop = (new MaterialData(dropID, dropData)).toItemStack(1); }
}
else { if (dropItem) {
itemDrop = (new MaterialData(id, data)).toItemStack(1); itemDrop = (new MaterialData(dropID, dropData)).toItemStack(1);
} }
else {
block = new CustomBlock(minimumDropAmount, maxiumDropAmount, itemDrop, tier, xp, data, id); itemDrop = (new MaterialData(id, data)).toItemStack(1);
blockItem = (new MaterialData(id, data)).toItemStack(1); }
if (skillType.equals("Mining") && config.getBoolean(skillType + "." + blockName + ".Is_Ore")) { block = new CustomBlock(minimumDropAmount, maxiumDropAmount, itemDrop, tier, xp, data, id);
customOres.add(blockItem); blockItem = (new MaterialData(id, data)).toItemStack(1);
}
else if (skillType.equals("Woodcutting")) { if (skillType.equals("Mining") && config.getBoolean(skillType + "." + blockName + ".Is_Ore")) {
if (config.getBoolean(skillType + "." + blockName + ".Is_Log")) { customOres.add(blockItem);
customLogs.add(blockItem); }
} else if (skillType.equals("Woodcutting")) {
else { if (config.getBoolean(skillType + "." + blockName + ".Is_Log")) {
customLeaves.add(blockItem); customLogs.add(blockItem);
block.setXpGain(0); //Leaves don't grant XP }
} else {
} customLeaves.add(blockItem);
block.setXpGain(0); // Leaves don't grant XP
blockList.add(blockItem); }
customItems.add(blockItem); }
customBlocks.add(block);
} blockList.add(blockItem);
} customItems.add(blockItem);
} customBlocks.add(block);
}
}
}

View File

@ -1,82 +1,84 @@
package com.gmail.nossr50.mods.config; package com.gmail.nossr50.config.mods;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.config.ConfigLoader; import com.gmail.nossr50.config.ConfigLoader;
import com.gmail.nossr50.mods.datatypes.CustomEntity; import com.gmail.nossr50.datatypes.mods.CustomEntity;
public class CustomEntityConfig extends ConfigLoader { public class CustomEntityConfig extends ConfigLoader {
private static CustomEntityConfig instance; private static CustomEntityConfig instance;
public List<Integer> customEntityIds = new ArrayList<Integer>();
public List<Integer> customHostileEntityIds = new ArrayList<Integer>(); public List<Integer> customEntityIds = new ArrayList<Integer>();
public List<Integer> customNeutralEntityIds = new ArrayList<Integer>(); public List<Integer> customHostileEntityIds = new ArrayList<Integer>();
public List<Integer> customPassiveEntityIds = new ArrayList<Integer>(); public List<Integer> customNeutralEntityIds = new ArrayList<Integer>();
public List<EntityType> customEntityTypes = new ArrayList<EntityType>(); public List<Integer> customPassiveEntityIds = new ArrayList<Integer>();
public List<CustomEntity> customEntities = new ArrayList<CustomEntity>();
public List<EntityType> customEntityTypes = new ArrayList<EntityType>();
public CustomEntityConfig() { public List<CustomEntity> customEntities = new ArrayList<CustomEntity>();
super("ModConfigs", "entities.yml");
loadKeys(); public CustomEntityConfig() {
} super("ModConfigs", "entities.yml");
loadKeys();
public static CustomEntityConfig getInstance() { }
if (instance == null) {
instance = new CustomEntityConfig(); public static CustomEntityConfig getInstance() {
} if (instance == null) {
instance = new CustomEntityConfig();
return instance; }
}
return instance;
@Override }
protected void loadKeys() {
loadMobs("Hostile", customHostileEntityIds); @Override
loadMobs("Neutral", customNeutralEntityIds); protected void loadKeys() {
loadMobs("Passive", customPassiveEntityIds); loadMobs("Hostile", customHostileEntityIds);
} loadMobs("Neutral", customNeutralEntityIds);
loadMobs("Passive", customPassiveEntityIds);
private void loadMobs(String entityType, List<Integer> entityIdList) { }
ConfigurationSection entitySection = config.getConfigurationSection(entityType);
private void loadMobs(String entityType, List<Integer> entityIdList) {
if (entitySection == null) { ConfigurationSection entitySection = config.getConfigurationSection(entityType);
return;
} if (entitySection == null) {
return;
Set<String> entityConfigSet = entitySection.getKeys(false); }
for (String entityName : entityConfigSet) { Set<String> entityConfigSet = entitySection.getKeys(false);
int id = config.getInt(entityType + "." + entityName + ".ID", 0);
EntityType type = EntityType.fromId(id); for (String entityName : entityConfigSet) {
double xpMultiplier = config.getDouble(entityType + "." + entityName + ".XP_Multiplier", 1.0D); int id = config.getInt(entityType + "." + entityName + ".ID", 0);
boolean canBeTamed = config.getBoolean(entityType + "." + entityName + ".Tameable", false); EntityType type = EntityType.fromId(id);
int tamingXp = config.getInt(entityType + "." + entityName + "Taming_XP", 0); double xpMultiplier = config.getDouble(entityType + "." + entityName + ".XP_Multiplier", 1.0D);
boolean canBeSummoned = config.getBoolean(entityType + "." + entityName + "CanBeSummoned", false); boolean canBeTamed = config.getBoolean(entityType + "." + entityName + ".Tameable", false);
int callOfTheWildId = config.getInt(entityType + "." + entityName + "COTW_Material_ID", 0); int tamingXp = config.getInt(entityType + "." + entityName + "Taming_XP", 0);
int callOfTheWildData = config.getInt(entityType + "." + entityName + "COTW_Material_Data", 0); boolean canBeSummoned = config.getBoolean(entityType + "." + entityName + "CanBeSummoned", false);
int callOfTheWildAmount = config.getInt(entityType + "." + entityName + "COTW_Material_Amount", 0); int callOfTheWildId = config.getInt(entityType + "." + entityName + "COTW_Material_ID", 0);
int callOfTheWildData = config.getInt(entityType + "." + entityName + "COTW_Material_Data", 0);
CustomEntity entity; int callOfTheWildAmount = config.getInt(entityType + "." + entityName + "COTW_Material_Amount", 0);
if (id == 0) { CustomEntity entity;
plugin.getLogger().warning("Missing ID. This block will be skipped.");
continue; if (id == 0) {
} plugin.getLogger().warning("Missing ID. This block will be skipped.");
continue;
if (canBeSummoned && (callOfTheWildId == 0 || callOfTheWildAmount == 0)) { }
plugin.getLogger().warning("Incomplete Call of the Wild information. This enitity will not be able to be summoned by Call of the Wild.");
canBeSummoned = false; if (canBeSummoned && (callOfTheWildId == 0 || callOfTheWildAmount == 0)) {
} plugin.getLogger().warning("Incomplete Call of the Wild information. This enitity will not be able to be summoned by Call of the Wild.");
canBeSummoned = false;
entity = new CustomEntity(id, type, xpMultiplier, canBeTamed, tamingXp, canBeSummoned, new ItemStack(callOfTheWildId, callOfTheWildData), callOfTheWildAmount); }
entityIdList.add(id); entity = new CustomEntity(id, type, xpMultiplier, canBeTamed, tamingXp, canBeSummoned, new ItemStack(callOfTheWildId, callOfTheWildData), callOfTheWildAmount);
customEntityTypes.add(type);
customEntities.add(entity); entityIdList.add(id);
} customEntityTypes.add(type);
} customEntities.add(entity);
} }
}
}

View File

@ -1,101 +1,105 @@
package com.gmail.nossr50.mods.config; package com.gmail.nossr50.config.mods;
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.Set; import java.util.Set;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import com.gmail.nossr50.config.ConfigLoader; import com.gmail.nossr50.config.ConfigLoader;
import com.gmail.nossr50.mods.datatypes.CustomTool; import com.gmail.nossr50.datatypes.mods.CustomTool;
import com.gmail.nossr50.skills.repair.Repairable; import com.gmail.nossr50.skills.repair.Repairable;
import com.gmail.nossr50.skills.repair.RepairableFactory; import com.gmail.nossr50.skills.repair.RepairableFactory;
public class CustomToolsConfig extends ConfigLoader { public class CustomToolConfig extends ConfigLoader {
private static CustomToolsConfig instance; private static CustomToolConfig instance;
private List<Repairable> repairables; private List<Repairable> repairables;
public List<Integer> customAxeIDs = new ArrayList<Integer>(); public List<Integer> customAxeIDs = new ArrayList<Integer>();
public List<Integer> customBowIDs = new ArrayList<Integer>(); public List<Integer> customBowIDs = new ArrayList<Integer>();
public List<Integer> customHoeIDs = new ArrayList<Integer>(); public List<Integer> customHoeIDs = new ArrayList<Integer>();
public List<Integer> customPickaxeIDs = new ArrayList<Integer>(); public List<Integer> customPickaxeIDs = new ArrayList<Integer>();
public List<Integer> customShovelIDs = new ArrayList<Integer>(); public List<Integer> customShovelIDs = new ArrayList<Integer>();
public List<Integer> customSwordIDs = new ArrayList<Integer>(); public List<Integer> customSwordIDs = new ArrayList<Integer>();
public List<Integer> customIDs = new ArrayList<Integer>(); public List<Integer> customIDs = new ArrayList<Integer>();
public List<CustomTool> customToolList = new ArrayList<CustomTool>(); public List<CustomTool> customToolList = new ArrayList<CustomTool>();
public HashMap<Integer, CustomTool> customTools = new HashMap<Integer, CustomTool>(); public HashMap<Integer, CustomTool> customTools = new HashMap<Integer, CustomTool>();
private CustomToolsConfig() { private CustomToolConfig() {
super("ModConfigs", "tools.yml"); super("ModConfigs", "tools.yml");
loadKeys(); loadKeys();
} }
public static CustomToolsConfig getInstance() { public static CustomToolConfig getInstance() {
if (instance == null) { if (instance == null) {
instance = new CustomToolsConfig(); instance = new CustomToolConfig();
} }
return instance; return instance;
} }
@Override public List<Repairable> getLoadedRepairables() {
protected void loadKeys() { if (repairables == null) {
repairables = new ArrayList<Repairable>(); return new ArrayList<Repairable>();
}
loadTool("Axes", customAxeIDs);
loadTool("Bows", customBowIDs); return repairables;
loadTool("Hoes", customHoeIDs); }
loadTool("Pickaxes", customPickaxeIDs);
loadTool("Shovels", customShovelIDs); @Override
loadTool("Swords", customSwordIDs); protected void loadKeys() {
} repairables = new ArrayList<Repairable>();
private void loadTool(String toolType, List<Integer> idList) { loadTool("Axes", customAxeIDs);
ConfigurationSection toolSection = config.getConfigurationSection(toolType); loadTool("Bows", customBowIDs);
loadTool("Hoes", customHoeIDs);
if (toolSection == null) loadTool("Pickaxes", customPickaxeIDs);
return; loadTool("Shovels", customShovelIDs);
loadTool("Swords", customSwordIDs);
Set<String> toolConfigSet = toolSection.getKeys(false); }
for (String toolName : toolConfigSet) { private void loadTool(String toolType, List<Integer> idList) {
int id = config.getInt(toolType + "." + toolName + ".ID", 0); ConfigurationSection toolSection = config.getConfigurationSection(toolType);
double multiplier = config.getDouble(toolType + "." + toolName + ".XP_Modifier", 1.0);
boolean abilityEnabled = config.getBoolean(toolType + "." + toolName + ".Ability_Enabled", true); if (toolSection == null) {
int tier = config.getInt(toolType + "." + toolName + ".Tier", 1); return;
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); Set<String> toolConfigSet = toolSection.getKeys(false);
int repairQuantity = config.getInt(toolType + "." + toolName + ".Repair_Material_Quantity", 0);
short durability = (short) config.getInt(toolType + "." + toolName + ".Durability", 0); for (String toolName : toolConfigSet) {
int id = config.getInt(toolType + "." + toolName + ".ID", 0);
if (id == 0) { double multiplier = config.getDouble(toolType + "." + toolName + ".XP_Modifier", 1.0);
plugin.getLogger().warning("Missing ID. This item will be skipped."); boolean abilityEnabled = config.getBoolean(toolType + "." + toolName + ".Ability_Enabled", true);
continue; 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);
if (repairable && (repairID == 0 || repairQuantity == 0 || durability == 0)) { byte repairData = (byte) config.getInt(toolType + "." + toolName + ".Repair_Material_Data_Value", 0);
plugin.getLogger().warning("Incomplete repair information. This item will be unrepairable."); int repairQuantity = config.getInt(toolType + "." + toolName + ".Repair_Material_Quantity", 0);
repairable = false; short durability = (short) config.getInt(toolType + "." + toolName + ".Durability", 0);
}
if (id == 0) {
CustomTool tool; plugin.getLogger().warning("Missing ID. This item will be skipped.");
continue;
if (repairable) { }
repairables.add(RepairableFactory.getRepairable(id, repairID, repairData, repairQuantity, durability));
} if (repairable && (repairID == 0 || repairQuantity == 0 || durability == 0)) {
plugin.getLogger().warning("Incomplete repair information. This item will be unrepairable.");
tool = new CustomTool(tier, abilityEnabled, multiplier, durability, id); repairable = false;
}
idList.add(id);
customIDs.add(id); CustomTool tool;
customToolList.add(tool);
customTools.put(id, tool); if (repairable) {
} repairables.add(RepairableFactory.getRepairable(id, repairID, repairData, repairQuantity, durability));
} }
public List<Repairable> getLoadedRepairables() { tool = new CustomTool(tier, abilityEnabled, multiplier, durability, id);
if (repairables == null) return new ArrayList<Repairable>();
return repairables; idList.add(id);
} customIDs.add(id);
} customToolList.add(tool);
customTools.put(id, tool);
}
}
}

View File

@ -0,0 +1,35 @@
package com.gmail.nossr50.config.party;
import org.bukkit.Material;
import com.gmail.nossr50.config.ConfigLoader;
import com.gmail.nossr50.util.StringUtils;
public class ItemWeightConfig extends ConfigLoader {
private static ItemWeightConfig instance;
private ItemWeightConfig() {
super("itemweights.yml");
}
public static ItemWeightConfig getInstance() {
if (instance == null) {
instance = new ItemWeightConfig();
}
return instance;
}
public int getItemWeight(Material material) {
String materialName = StringUtils.getPrettyItemString(material).replace(" ", "_");
int itemWeight = config.getInt("Item_Weights.Default");
if (config.getInt("Item_Weights." + materialName) > 0) {
itemWeight = config.getInt("Item_Weights." + materialName);
}
return itemWeight;
}
@Override
protected void loadKeys() {}
}

View File

@ -0,0 +1,65 @@
package com.gmail.nossr50.config.spout;
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;
public HudType defaultHudType;
private SpoutConfig() {
super("spout.yml");
loadKeys();
}
public static SpoutConfig getInstance() {
if (instance == null) {
instance = new SpoutConfig();
}
return instance;
}
@Override
protected void loadKeys() {
// Setup default HUD
String temp = config.getString("Spout.HUD.Default", "STANDARD");
for (HudType hudType : HudType.values()) {
if (hudType.toString().equalsIgnoreCase(temp)) {
defaultHudType = hudType;
break;
}
}
if (defaultHudType == null) {
defaultHudType = HudType.STANDARD;
}
}
public boolean getShowPowerLevel() { return config.getBoolean("HUD.Show_Power_Level", true); }
public String getMenuKey() { return config.getString("Menu.Key", "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); }
}

View File

@ -1,285 +1,292 @@
package com.gmail.nossr50.config; 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;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData; import org.bukkit.material.MaterialData;
import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure; import com.gmail.nossr50.config.ConfigLoader;
import com.gmail.nossr50.datatypes.treasure.FishingTreasure; import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure;
import com.gmail.nossr50.datatypes.treasure.HylianTreasure; import com.gmail.nossr50.datatypes.treasure.FishingTreasure;
import com.gmail.nossr50.datatypes.treasure.Treasure; import com.gmail.nossr50.datatypes.treasure.HylianTreasure;
import com.gmail.nossr50.datatypes.treasure.Treasure;
public class TreasuresConfig extends ConfigLoader {
private static TreasuresConfig instance; public class TreasureConfig extends ConfigLoader {
public List<ExcavationTreasure> excavationFromDirt = new ArrayList<ExcavationTreasure>(); private static TreasureConfig instance;
public List<ExcavationTreasure> excavationFromGrass = new ArrayList<ExcavationTreasure>();
public List<ExcavationTreasure> excavationFromSand = new ArrayList<ExcavationTreasure>(); public List<ExcavationTreasure> excavationFromDirt = new ArrayList<ExcavationTreasure>();
public List<ExcavationTreasure> excavationFromGravel = new ArrayList<ExcavationTreasure>(); public List<ExcavationTreasure> excavationFromGrass = new ArrayList<ExcavationTreasure>();
public List<ExcavationTreasure> excavationFromClay = new ArrayList<ExcavationTreasure>(); public List<ExcavationTreasure> excavationFromSand = new ArrayList<ExcavationTreasure>();
public List<ExcavationTreasure> excavationFromMycel = new ArrayList<ExcavationTreasure>(); public List<ExcavationTreasure> excavationFromGravel = new ArrayList<ExcavationTreasure>();
public List<ExcavationTreasure> excavationFromSoulSand = new ArrayList<ExcavationTreasure>(); public List<ExcavationTreasure> excavationFromClay = new ArrayList<ExcavationTreasure>();
public List<ExcavationTreasure> excavationFromMycel = new ArrayList<ExcavationTreasure>();
public List<HylianTreasure> hylianFromBushes = new ArrayList<HylianTreasure>(); public List<ExcavationTreasure> excavationFromSoulSand = new ArrayList<ExcavationTreasure>();
public List<HylianTreasure> hylianFromFlowers = new ArrayList<HylianTreasure>();
public List<HylianTreasure> hylianFromPots = new ArrayList<HylianTreasure>(); public List<HylianTreasure> hylianFromBushes = new ArrayList<HylianTreasure>();
public List<HylianTreasure> hylianFromFlowers = new ArrayList<HylianTreasure>();
public List<FishingTreasure> fishingRewards = new ArrayList<FishingTreasure>(); public List<HylianTreasure> hylianFromPots = new ArrayList<HylianTreasure>();
private TreasuresConfig() { public List<FishingTreasure> fishingRewards = new ArrayList<FishingTreasure>();
super("treasures.yml");
loadKeys(); private TreasureConfig() {
} super("treasures.yml");
loadKeys();
public static TreasuresConfig getInstance() { }
if (instance == null) {
instance = new TreasuresConfig(); public static TreasureConfig getInstance() {
} if (instance == null) {
instance = new TreasureConfig();
return instance; }
}
return instance;
@Override }
protected void loadKeys() {
Map<String, Treasure> treasures = new HashMap<String, Treasure>(); @Override
ConfigurationSection treasureSection = config.getConfigurationSection("Treasures"); protected void loadKeys() {
Set<String> treasureConfigSet = treasureSection.getKeys(false); Map<String, Treasure> treasures = new HashMap<String, Treasure>();
ConfigurationSection treasureSection = config.getConfigurationSection("Treasures");
for (String treasureName : treasureConfigSet) {
if (treasureSection == null) {
// Validate all the things! return;
List<String> reason = new ArrayList<String>(); }
/* Set<String> treasureConfigSet = treasureSection.getKeys(false);
* ID, Amount, and Data
*/ for (String treasureName : treasureConfigSet) {
if (!config.contains("Treasures." + treasureName + ".ID")) { // Validate all the things!
reason.add("Missing ID"); List<String> reason = new ArrayList<String>();
}
/*
if (!config.contains("Treasures." + treasureName + ".Amount")) { * ID, Amount, and Data
reason.add("Missing Amount"); */
}
if (!config.contains("Treasures." + treasureName + ".ID")) {
if (!config.contains("Treasures." + treasureName + ".Data")) { reason.add("Missing ID");
reason.add("Missing Data"); }
}
if (!config.contains("Treasures." + treasureName + ".Amount")) {
int id = config.getInt("Treasures." + treasureName + ".ID"); reason.add("Missing Amount");
int amount = config.getInt("Treasures." + treasureName + ".Amount"); }
int data = config.getInt("Treasures." + treasureName + ".Data");
if (!config.contains("Treasures." + treasureName + ".Data")) {
if (Material.getMaterial(id) == null) { reason.add("Missing Data");
reason.add("Invalid id: " + id); }
}
int id = config.getInt("Treasures." + treasureName + ".ID");
if (amount < 1) { int amount = config.getInt("Treasures." + treasureName + ".Amount");
reason.add("Invalid amount: " + amount); int data = config.getInt("Treasures." + treasureName + ".Data");
}
if (Material.getMaterial(id) == null) {
if (data > 127 || data < -128) { reason.add("Invalid id: " + id);
reason.add("Invalid data: " + data); }
}
if (amount < 1) {
/* reason.add("Invalid amount: " + amount);
* XP, Drop Chance, and Drop Level }
*/
if (data > 127 || data < -128) {
if (!config.contains("Treasures." + treasureName + ".XP")) { reason.add("Invalid data: " + data);
reason.add("Missing XP"); }
}
/*
if (!config.contains("Treasures." + treasureName + ".Drop_Chance")) { * XP, Drop Chance, and Drop Level
reason.add("Missing Drop_Chance"); */
}
if (!config.contains("Treasures." + treasureName + ".XP")) {
if (!config.contains("Treasures." + treasureName + ".Drop_Level")) { reason.add("Missing XP");
reason.add("Missing Drop_Level"); }
}
if (!config.contains("Treasures." + treasureName + ".Drop_Chance")) {
int xp = config.getInt("Treasures." + treasureName + ".XP"); reason.add("Missing Drop_Chance");
Double dropChance = config.getDouble("Treasures." + treasureName + ".Drop_Chance"); }
int dropLevel = config.getInt("Treasures." + treasureName + ".Drop_Level");
if (!config.contains("Treasures." + treasureName + ".Drop_Level")) {
if (xp < 0) { reason.add("Missing Drop_Level");
reason.add("Invalid xp: " + xp); }
}
int xp = config.getInt("Treasures." + treasureName + ".XP");
if (dropChance < 0) { Double dropChance = config.getDouble("Treasures." + treasureName + ".Drop_Chance");
reason.add("Invalid Drop_Chance: " + dropChance); int dropLevel = config.getInt("Treasures." + treasureName + ".Drop_Level");
}
if (xp < 0) {
if (dropLevel < 0) { reason.add("Invalid xp: " + xp);
reason.add("Invalid Drop_Level: " + dropLevel); }
}
if (dropChance < 0) {
/* reason.add("Invalid Drop_Chance: " + dropChance);
* Drops From & Max Level }
*/
if (dropLevel < 0) {
ItemStack item = (new MaterialData(id, (byte) data)).toItemStack(amount); reason.add("Invalid Drop_Level: " + dropLevel);
}
if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Fishing", false)) {
if (config.getConfigurationSection("Treasures." + treasureName + ".Drops_From").getKeys(false).size() != 1) { /*
reason.add("Fishing drops cannot also be excavation drops"); * Drops From & Max Level
} */
if (!config.contains("Treasures." + treasureName + ".Max_Level")) { ItemStack item = (new MaterialData(id, (byte) data)).toItemStack(amount);
reason.add("Missing Max_Level");
} if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Fishing", false)) {
if (config.getConfigurationSection("Treasures." + treasureName + ".Drops_From").getKeys(false).size() != 1) {
int maxLevel = config.getInt("Treasures." + treasureName + ".Max_Level"); reason.add("Fishing drops cannot also be excavation drops");
}
if (noErrorsInTreasure(reason)) {
FishingTreasure fTreasure = new FishingTreasure(item, xp, dropChance, dropLevel, maxLevel); if (!config.contains("Treasures." + treasureName + ".Max_Level")) {
treasures.put(treasureName, fTreasure); reason.add("Missing Max_Level");
} }
}
else { int maxLevel = config.getInt("Treasures." + treasureName + ".Max_Level");
ExcavationTreasure eTreasure = new ExcavationTreasure(item, xp, dropChance, dropLevel);
HylianTreasure hTreasure = new HylianTreasure(item, xp, dropChance, dropLevel); if (noErrorsInTreasure(reason)) {
FishingTreasure fTreasure = new FishingTreasure(item, xp, dropChance, dropLevel, maxLevel);
if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Dirt", false)) { treasures.put(treasureName, fTreasure);
eTreasure.setDropsFromDirt(); }
} }
else {
if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Grass", false)) { ExcavationTreasure eTreasure = new ExcavationTreasure(item, xp, dropChance, dropLevel);
eTreasure.setDropsFromGrass(); HylianTreasure hTreasure = new HylianTreasure(item, xp, dropChance, dropLevel);
}
if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Dirt", false)) {
if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Sand", false)) { eTreasure.setDropsFromDirt();
eTreasure.setDropsFromSand(); }
}
if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Grass", false)) {
if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Gravel", false)) { eTreasure.setDropsFromGrass();
eTreasure.setDropsFromGravel(); }
}
if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Sand", false)) {
if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Clay", false)) { eTreasure.setDropsFromSand();
eTreasure.setDropsFromClay(); }
}
if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Gravel", false)) {
if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Mycelium", false)) { eTreasure.setDropsFromGravel();
eTreasure.setDropsFromMycel(); }
}
if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Clay", false)) {
if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Soul_Sand", false)) { eTreasure.setDropsFromClay();
eTreasure.setDropsFromSoulSand(); }
}
if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Mycelium", false)) {
if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Bushes", false)) { eTreasure.setDropsFromMycel();
hTreasure.setDropsFromBushes(); }
}
if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Soul_Sand", false)) {
if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Flowers", false)) { eTreasure.setDropsFromSoulSand();
hTreasure.setDropsFromFlowers(); }
}
if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Bushes", false)) {
if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Pots", false)) { hTreasure.setDropsFromBushes();
hTreasure.setDropsFromPots(); }
}
if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Flowers", false)) {
if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Fishing", false)) { hTreasure.setDropsFromFlowers();
reason.add("Excavation drops cannot also be fishing drops"); }
}
if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Pots", false)) {
if (noErrorsInTreasure(reason) && hTreasure.getDropsFrom() == (byte) 0x0) { hTreasure.setDropsFromPots();
treasures.put(treasureName, eTreasure); }
}
else if (noErrorsInTreasure(reason) && eTreasure.getDropsFrom() == (byte) 0x0){ if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Fishing", false)) {
treasures.put(treasureName, hTreasure); reason.add("Excavation drops cannot also be fishing drops");
} }
}
} if (noErrorsInTreasure(reason) && hTreasure.getDropsFrom() == (byte) 0x0) {
treasures.put(treasureName, eTreasure);
List<String> excavationTreasures = config.getStringList("Excavation.Treasure"); }
List<String> fishingTreasures = config.getStringList("Fishing.Treasure"); else if (noErrorsInTreasure(reason) && eTreasure.getDropsFrom() == (byte) 0x0) {
List<String> hylianTreasures = config.getStringList("Hylian_Luck.Treasure"); treasures.put(treasureName, hTreasure);
}
for (Entry<String,Treasure> nextEntry : treasures.entrySet()) { }
String treasureKey = nextEntry.getKey(); }
Treasure treasure = nextEntry.getValue();
List<String> excavationTreasures = config.getStringList("Excavation.Treasure");
if (treasure instanceof FishingTreasure) { List<String> fishingTreasures = config.getStringList("Fishing.Treasure");
if (!fishingTreasures.contains(treasureKey)) { List<String> hylianTreasures = config.getStringList("Hylian_Luck.Treasure");
continue;
} for (Entry<String, Treasure> nextEntry : treasures.entrySet()) {
String treasureKey = nextEntry.getKey();
fishingRewards.add((FishingTreasure) treasure); Treasure treasure = nextEntry.getValue();
}
else if (treasure instanceof HylianTreasure) { if (treasure instanceof FishingTreasure) {
if (!hylianTreasures.contains(treasureKey)) { if (fishingTreasures == null || !fishingTreasures.contains(treasureKey)) {
continue; continue;
} }
HylianTreasure hTreasure = (HylianTreasure) treasure; fishingRewards.add((FishingTreasure) treasure);
}
if (hTreasure.getDropsFromBushes()) { else if (treasure instanceof HylianTreasure) {
hylianFromBushes.add(hTreasure); if (hylianTreasures == null || !hylianTreasures.contains(treasureKey)) {
} continue;
}
if (hTreasure.getDropsFromFlowers()) {
hylianFromFlowers.add(hTreasure); HylianTreasure hTreasure = (HylianTreasure) treasure;
}
if (hTreasure.getDropsFromBushes()) {
if (hTreasure.getDropsFromPots()) { hylianFromBushes.add(hTreasure);
hylianFromPots.add(hTreasure); }
}
} if (hTreasure.getDropsFromFlowers()) {
else if (treasure instanceof ExcavationTreasure) { hylianFromFlowers.add(hTreasure);
if (!excavationTreasures.contains(treasureKey)) { }
continue;
} if (hTreasure.getDropsFromPots()) {
hylianFromPots.add(hTreasure);
ExcavationTreasure eTreasure = (ExcavationTreasure) treasure; }
}
if (eTreasure.getDropsFromDirt()) { else if (treasure instanceof ExcavationTreasure) {
excavationFromDirt.add(eTreasure); if (excavationTreasures == null || !excavationTreasures.contains(treasureKey)) {
} continue;
}
if (eTreasure.getDropsFromGrass()) {
excavationFromGrass.add(eTreasure); ExcavationTreasure eTreasure = (ExcavationTreasure) treasure;
}
if (eTreasure.getDropsFromDirt()) {
if (eTreasure.getDropsFromSand()) { excavationFromDirt.add(eTreasure);
excavationFromSand.add(eTreasure); }
}
if (eTreasure.getDropsFromGrass()) {
if (eTreasure.getDropsFromGravel()) { excavationFromGrass.add(eTreasure);
excavationFromGravel.add(eTreasure); }
}
if (eTreasure.getDropsFromSand()) {
if (eTreasure.getDropsFromClay()) { excavationFromSand.add(eTreasure);
excavationFromClay.add(eTreasure); }
}
if (eTreasure.getDropsFromGravel()) {
if (eTreasure.getDropsFromMycel()) { excavationFromGravel.add(eTreasure);
excavationFromMycel.add(eTreasure); }
}
if (eTreasure.getDropsFromClay()) {
if (eTreasure.getDropsFromSoulSand()) { excavationFromClay.add(eTreasure);
excavationFromSoulSand.add(eTreasure); }
}
} if (eTreasure.getDropsFromMycel()) {
} excavationFromMycel.add(eTreasure);
} }
private boolean noErrorsInTreasure(List<String> issues) { if (eTreasure.getDropsFromSoulSand()) {
if (issues.isEmpty()) { excavationFromSoulSand.add(eTreasure);
return true; }
} }
}
for (String issue : issues) { }
plugin.getLogger().warning(issue);
} private boolean noErrorsInTreasure(List<String> issues) {
return false; if (issues.isEmpty()) {
} return true;
} }
for (String issue : issues) {
plugin.getLogger().warning(issue);
}
return false;
}
}

View File

@ -10,19 +10,19 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player; 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.database.runnables.SQLReconnect; import com.gmail.nossr50.datatypes.database.DatabaseUpdateType;
import com.gmail.nossr50.datatypes.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.spout.SpoutTools; import com.gmail.nossr50.datatypes.spout.huds.McMMOHud;
import com.gmail.nossr50.spout.huds.SpoutHud; import com.gmail.nossr50.runnables.database.SQLReconnectTask;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.spout.SpoutUtils;
public final class Database { public final class DatabaseManager {
private static String connectionString; private static String connectionString;
private static String tablePrefix = Config.getInstance().getMySQLTablePrefix(); private static String tablePrefix = Config.getInstance().getMySQLTablePrefix();
@ -32,7 +32,7 @@ public final class Database {
private static final double SCALING_FACTOR = 40; private static final double SCALING_FACTOR = 40;
// Minimum wait in nanoseconds (default 500ms) // Minimum wait in nanoseconds (default 500ms)
private static final long MIN_WAIT = 500L*1000000L; private static final long MIN_WAIT = 500L * 1000000L;
// Maximum time to wait between reconnects (default 5 minutes) // Maximum time to wait between reconnects (default 5 minutes)
private static final long MAX_WAIT = 5L * 60L * 1000L * 1000000L; private static final long MAX_WAIT = 5L * 60L * 1000L * 1000000L;
@ -43,10 +43,12 @@ public final class Database {
// When next to try connecting to Database in nanoseconds // When next to try connecting to Database in nanoseconds
private static long nextReconnectTimestamp = 0L; private static long nextReconnectTimestamp = 0L;
// How many connection attemtps have failed // How many connection attempts have failed
private static int reconnectAttempt = 0; private static int reconnectAttempt = 0;
private Database() {} private static final long ONE_MONTH = 2630000000L;
private DatabaseManager() {}
/** /**
* Attempt to connect to the mySQL database. * Attempt to connect to the mySQL database.
@ -68,13 +70,17 @@ public final class Database {
connection = DriverManager.getConnection(connectionString, connectionProperties); connection = DriverManager.getConnection(connectionString, connectionProperties);
mcMMO.p.getLogger().info("Connection to MySQL was a success!"); mcMMO.p.getLogger().info("Connection to MySQL was a success!");
} catch (SQLException ex) { }
catch (SQLException ex) {
connection = null; connection = null;
if (reconnectAttempt == 0 || reconnectAttempt >= 11) { if (reconnectAttempt == 0 || reconnectAttempt >= 11) {
mcMMO.p.getLogger().info("Connection to MySQL failed!"); mcMMO.p.getLogger().info("Connection to MySQL failed!");
} }
} catch (ClassNotFoundException ex) { }
catch (ClassNotFoundException ex) {
connection = null; connection = null;
if (reconnectAttempt == 0 || reconnectAttempt >= 11) { if (reconnectAttempt == 0 || reconnectAttempt >= 11) {
mcMMO.p.getLogger().info("MySQL database driver not found!"); mcMMO.p.getLogger().info("MySQL database driver not found!");
} }
@ -147,108 +153,10 @@ public final class Database {
+ "FOREIGN KEY (`user_id`) REFERENCES `" + tablePrefix + "users` (`id`) " + "FOREIGN KEY (`user_id`) REFERENCES `" + tablePrefix + "users` (`id`) "
+ "ON DELETE CASCADE) ENGINE=MyISAM DEFAULT CHARSET=latin1;"); + "ON DELETE CASCADE) ENGINE=MyISAM DEFAULT CHARSET=latin1;");
checkDatabaseStructure(DatabaseUpdate.FISHING); checkDatabaseStructure(DatabaseUpdateType.FISHING);
checkDatabaseStructure(DatabaseUpdate.BLAST_MINING); checkDatabaseStructure(DatabaseUpdateType.BLAST_MINING);
checkDatabaseStructure(DatabaseUpdate.CASCADE_DELETE); checkDatabaseStructure(DatabaseUpdateType.CASCADE_DELETE);
checkDatabaseStructure(DatabaseUpdate.INDEX); checkDatabaseStructure(DatabaseUpdateType.INDEX);
}
/**
* Check database structure for missing values.
*
* @param update Type of data to check updates for
*/
private static void checkDatabaseStructure(DatabaseUpdate update) {
String sql = null;
ResultSet resultSet = null;
HashMap<Integer, ArrayList<String>> rows = new HashMap<Integer, ArrayList<String>>();
switch (update) {
case BLAST_MINING:
sql = "SELECT * FROM `" + tablePrefix + "cooldowns` ORDER BY `" + tablePrefix + "cooldowns`.`blast_mining` ASC LIMIT 0 , 30";
break;
case CASCADE_DELETE:
write("ALTER TABLE `" + tablePrefix + "huds` ADD FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE;");
write("ALTER TABLE `" + tablePrefix + "experience` ADD FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE;");
write("ALTER TABLE `" + tablePrefix + "cooldowns` ADD FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE;");
write("ALTER TABLE `" + tablePrefix + "skills` ADD FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE;");
break;
case FISHING:
sql = "SELECT * FROM `" + tablePrefix + "experience` ORDER BY `" + tablePrefix + "experience`.`fishing` ASC LIMIT 0 , 30";
break;
case INDEX:
if (read("SHOW INDEX FROM " + tablePrefix + "skills").size() != 13 && checkConnected()) {
mcMMO.p.getLogger().info("Indexing tables, this may take a while on larger databases");
write("ALTER TABLE `" + tablePrefix + "skills` ADD INDEX `idx_taming` (`taming`) USING BTREE, "
+ "ADD INDEX `idx_mining` (`mining`) USING BTREE, "
+ "ADD INDEX `idx_woodcutting` (`woodcutting`) USING BTREE, "
+ "ADD INDEX `idx_repair` (`repair`) USING BTREE, "
+ "ADD INDEX `idx_unarmed` (`unarmed`) USING BTREE, "
+ "ADD INDEX `idx_herbalism` (`herbalism`) USING BTREE, "
+ "ADD INDEX `idx_excavation` (`excavation`) USING BTREE, "
+ "ADD INDEX `idx_archery` (`archery`) USING BTREE, "
+ "ADD INDEX `idx_swords` (`swords`) USING BTREE, "
+ "ADD INDEX `idx_axes` (`axes`) USING BTREE, "
+ "ADD INDEX `idx_acrobatics` (`acrobatics`) USING BTREE, "
+ "ADD INDEX `idx_fishing` (`fishing`) USING BTREE;");
}
break;
default:
break;
}
PreparedStatement statement = null;
try {
if (!checkConnected()) return;
statement = connection.prepareStatement(sql);
resultSet = statement.executeQuery();
while (resultSet.next()) {
ArrayList<String> column = new ArrayList<String>();
for (int i = 1; i <= resultSet.getMetaData().getColumnCount(); i++) {
column.add(resultSet.getString(i));
}
rows.put(resultSet.getRow(), column);
}
}
catch (SQLException ex) {
switch (update) {
case BLAST_MINING:
mcMMO.p.getLogger().info("Updating mcMMO MySQL tables for Blast Mining...");
write("ALTER TABLE `"+tablePrefix + "cooldowns` ADD `blast_mining` int(32) NOT NULL DEFAULT '0' ;");
break;
case FISHING:
mcMMO.p.getLogger().info("Updating mcMMO MySQL tables for Fishing...");
write("ALTER TABLE `"+tablePrefix + "skills` ADD `fishing` int(10) NOT NULL DEFAULT '0' ;");
write("ALTER TABLE `"+tablePrefix + "experience` ADD `fishing` int(10) NOT NULL DEFAULT '0' ;");
break;
default:
break;
}
} finally {
if (resultSet != null) {
try {
resultSet.close();
} catch (SQLException e) {
// Ignore the error, we're leaving
}
}
if (statement != null) {
try {
statement.close();
} catch (SQLException e) {
// Ignore the error, we're leaving
}
}
}
} }
/** /**
@ -258,29 +166,31 @@ public final class Database {
* @return true if the query was successfully written, false otherwise. * @return true if the query was successfully written, false otherwise.
*/ */
public static boolean write(String sql) { public static boolean write(String sql) {
if (checkConnected()) { if (!checkConnected()) {
PreparedStatement statement = null; return false;
try { }
statement = connection.prepareStatement(sql);
statement.executeUpdate(); PreparedStatement statement = null;
return true; try {
} statement = connection.prepareStatement(sql);
catch (SQLException ex) { statement.executeUpdate();
printErrors(ex); return true;
return false; }
} finally { catch (SQLException ex) {
if (statement != null) { printErrors(ex);
try { return false;
statement.close(); }
} catch (SQLException e) { finally {
printErrors(e); if (statement != null) {
return false; try {
} statement.close();
}
catch (SQLException e) {
printErrors(e);
return false;
} }
} }
} }
return false;
} }
/** /**
@ -291,22 +201,23 @@ public final class Database {
*/ */
public static int update(String sql) { public static int update(String sql) {
int ret = 0; int ret = 0;
if (checkConnected()) { if (checkConnected()) {
PreparedStatement statement = null; PreparedStatement statement = null;
try { try {
statement = connection.prepareStatement(sql); statement = connection.prepareStatement(sql);
ret = statement.executeUpdate(); ret = statement.executeUpdate();
return ret; }
} catch (SQLException ex) { catch (SQLException ex) {
printErrors(ex); printErrors(ex);
return 0; }
} finally { finally {
if (statement != null) { if (statement != null) {
try { try {
statement.close(); statement.close();
} catch (SQLException e) { }
catch (SQLException e) {
printErrors(e); printErrors(e);
return 0;
} }
} }
} }
@ -322,12 +233,14 @@ public final class Database {
* @return the value in the first row / first field * @return the value in the first row / first field
*/ */
public static int getInt(String sql) { public static int getInt(String sql) {
ResultSet resultSet; ResultSet resultSet = null;
int result = 0; int result = 0;
if (checkConnected()) { if (checkConnected()) {
PreparedStatement statement = null;
try { try {
PreparedStatement statement = connection.prepareStatement(sql); statement = connection.prepareStatement(sql);
resultSet = statement.executeQuery(); resultSet = statement.executeQuery();
if (resultSet.next()) { if (resultSet.next()) {
@ -336,12 +249,20 @@ public final class Database {
else { else {
result = 0; result = 0;
} }
statement.close();
} }
catch (SQLException ex) { catch (SQLException ex) {
printErrors(ex); printErrors(ex);
} }
finally {
if (statement != null) {
try {
statement.close();
}
catch (SQLException e) {
printErrors(e);
}
}
}
} }
return result; return result;
@ -375,7 +296,8 @@ public final class Database {
if (exists) { if (exists) {
try { try {
isClosed = connection.isClosed(); isClosed = connection.isClosed();
} catch (SQLException e) { }
catch (SQLException e) {
isClosed = true; isClosed = true;
e.printStackTrace(); e.printStackTrace();
printErrors(e); printErrors(e);
@ -384,9 +306,9 @@ public final class Database {
if (!isClosed) { if (!isClosed) {
try { try {
isValid = connection.isValid(VALID_TIMEOUT); isValid = connection.isValid(VALID_TIMEOUT);
} catch (SQLException e) { }
// Don't print stack trace because it's valid to lose idle connections catch (SQLException e) {
// to the server and have to restart them. // Don't print stack trace because it's valid to lose idle connections to the server and have to restart them.
isValid = false; isValid = false;
} }
} }
@ -404,7 +326,8 @@ public final class Database {
if (exists && !isClosed) { if (exists && !isClosed) {
try { try {
connection.close(); connection.close();
} catch (SQLException ex) { }
catch (SQLException ex) {
// This is a housekeeping exercise, ignore errors // This is a housekeeping exercise, ignore errors
} }
} }
@ -417,22 +340,21 @@ public final class Database {
if (connection != null && !connection.isClosed()) { if (connection != null && !connection.isClosed()) {
// Schedule a database save if we really had an outage // Schedule a database save if we really had an outage
if (reconnectAttempt > 1) { if (reconnectAttempt > 1) {
mcMMO.p.getServer().getScheduler().scheduleSyncDelayedTask(mcMMO.p, new SQLReconnect(), 5); mcMMO.p.getServer().getScheduler().scheduleSyncDelayedTask(mcMMO.p, new SQLReconnectTask(), 5);
} }
nextReconnectTimestamp = 0; nextReconnectTimestamp = 0;
reconnectAttempt = 0; reconnectAttempt = 0;
return true; return true;
} }
} catch (SQLException e) { }
catch (SQLException e) {
// Failed to check isClosed, so presume connection is bad and attempt later // Failed to check isClosed, so presume connection is bad and attempt later
e.printStackTrace(); e.printStackTrace();
printErrors(e); printErrors(e);
} }
reconnectAttempt++; reconnectAttempt++;
nextReconnectTimestamp = (long)(System.nanoTime() + Math.min(MAX_WAIT, (reconnectAttempt * SCALING_FACTOR * MIN_WAIT)));
nextReconnectTimestamp = (long)(System.nanoTime() + Math.min(MAX_WAIT, (reconnectAttempt*SCALING_FACTOR*MIN_WAIT)));
return false; return false;
} }
@ -447,8 +369,10 @@ public final class Database {
HashMap<Integer, ArrayList<String>> rows = new HashMap<Integer, ArrayList<String>>(); HashMap<Integer, ArrayList<String>> rows = new HashMap<Integer, ArrayList<String>>();
if (checkConnected()) { if (checkConnected()) {
PreparedStatement statement = null;
try { try {
PreparedStatement statement = connection.prepareStatement(sql); statement = connection.prepareStatement(sql);
resultSet = statement.executeQuery(); resultSet = statement.executeQuery();
while (resultSet.next()) { while (resultSet.next()) {
@ -460,12 +384,20 @@ public final class Database {
rows.put(resultSet.getRow(), column); rows.put(resultSet.getRow(), column);
} }
statement.close();
} }
catch (SQLException ex) { catch (SQLException ex) {
printErrors(ex); printErrors(ex);
} }
finally {
if (statement != null) {
try {
statement.close();
}
catch (SQLException e) {
printErrors(e);
}
}
}
} }
return rows; return rows;
@ -477,12 +409,15 @@ public final class Database {
if (checkConnected()) { if (checkConnected()) {
try { try {
for (SkillType skillType: SkillType.values()) { for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) { if (skillType.isChildSkill()) {
continue; continue;
} }
String sql = "SELECT COUNT(*) AS rank FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id WHERE " + skillType.name().toLowerCase() + " > 0 AND " + skillType.name().toLowerCase() + " > (SELECT " + skillType.name().toLowerCase() + " FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id WHERE user = '" + playerName + "')"; String skillName = skillType.name().toLowerCase();
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 " +
"WHERE user = '" + playerName + "')";
PreparedStatement statement = connection.prepareStatement(sql); PreparedStatement statement = connection.prepareStatement(sql);
resultSet = statement.executeQuery(); resultSet = statement.executeQuery();
@ -491,7 +426,9 @@ public final class Database {
int rank = resultSet.getInt("rank"); int rank = resultSet.getInt("rank");
sql = "SELECT user, " + skillType.name().toLowerCase() + " FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id WHERE " + skillType.name().toLowerCase() + " > 0 AND " + skillType.name().toLowerCase() + " = (SELECT " + skillType.name().toLowerCase() + " FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id WHERE user = '" + playerName + "') ORDER BY user"; sql = "SELECT user, " + skillName + " 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 " +
"WHERE user = '" + playerName + "') ORDER BY user";
statement = connection.prepareStatement(sql); statement = connection.prepareStatement(sql);
resultSet = statement.executeQuery(); resultSet = statement.executeQuery();
@ -506,7 +443,11 @@ public final class Database {
statement.close(); statement.close();
} }
String sql = "SELECT COUNT(*) AS rank FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id WHERE taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing > 0 AND taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing > (SELECT taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id WHERE user = '" + playerName + "')"; String sql = "SELECT COUNT(*) AS rank FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id " +
"WHERE taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing > 0 " +
"AND taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing > " +
"(SELECT taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing " +
"FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id WHERE user = '" + playerName + "')";
PreparedStatement statement = connection.prepareStatement(sql); PreparedStatement statement = connection.prepareStatement(sql);
resultSet = statement.executeQuery(); resultSet = statement.executeQuery();
@ -515,7 +456,12 @@ public final class Database {
int rank = resultSet.getInt("rank"); int rank = resultSet.getInt("rank");
sql = "SELECT user, taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id WHERE taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing > 0 AND taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing = (SELECT taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id WHERE user = '" + playerName + "') ORDER BY user"; sql = "SELECT user, taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing " +
"FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id " +
"WHERE taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing > 0 " +
"AND taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing = " +
"(SELECT taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing " +
"FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id WHERE user = '" + playerName + "') ORDER BY user";
statement = connection.prepareStatement(sql); statement = connection.prepareStatement(sql);
resultSet = statement.executeQuery(); resultSet = statement.executeQuery();
@ -539,14 +485,20 @@ public final class Database {
public static void purgePowerlessSQL() { public static void purgePowerlessSQL() {
mcMMO.p.getLogger().info("Purging powerless users..."); mcMMO.p.getLogger().info("Purging powerless users...");
HashMap<Integer, 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"); HashMap<Integer, ArrayList<String>> usernames;
write("DELETE FROM " + tablePrefix + "users WHERE " + tablePrefix + "users.id IN (SELECT * FROM (SELECT u.id 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) AS p)");
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");
write("DELETE FROM " + tablePrefix + "users WHERE " + tablePrefix + "users.id IN (SELECT * FROM " +
"(SELECT u.id 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) AS p)");
int purgedUsers = 0; int purgedUsers = 0;
for (int i = 1; i <= usernames.size(); i++) { for (int i = 1; i <= usernames.size(); i++) {
String playerName = usernames.get(i).get(0); String playerName = usernames.get(i).get(0);
if (playerName == null || Bukkit.getOfflinePlayer(playerName).isOnline()) { if (playerName == null || mcMMO.p.getServer().getOfflinePlayer(playerName).isOnline()) {
continue; continue;
} }
@ -560,7 +512,7 @@ public final class Database {
public static void purgeOldSQL() { public static void purgeOldSQL() {
mcMMO.p.getLogger().info("Purging old users..."); mcMMO.p.getLogger().info("Purging old users...");
long currentTime = System.currentTimeMillis(); long currentTime = System.currentTimeMillis();
long purgeTime = 2630000000L * Config.getInstance().getOldUsersCutoff(); long purgeTime = ONE_MONTH * Config.getInstance().getOldUsersCutoff();
HashMap<Integer, ArrayList<String>> usernames = read("SELECT user FROM " + tablePrefix + "users WHERE ((" + currentTime + " - lastlogin*1000) > " + purgeTime + ")"); HashMap<Integer, ArrayList<String>> usernames = read("SELECT user FROM " + tablePrefix + "users WHERE ((" + currentTime + " - lastlogin*1000) > " + purgeTime + ")");
write("DELETE FROM " + tablePrefix + "users WHERE " + tablePrefix + "users.id IN (SELECT * FROM (SELECT id FROM " + tablePrefix + "users WHERE ((" + currentTime + " - lastlogin*1000) > " + purgeTime + ")) AS p)"); write("DELETE FROM " + tablePrefix + "users WHERE " + tablePrefix + "users.id IN (SELECT * FROM (SELECT id FROM " + tablePrefix + "users WHERE ((" + currentTime + " - lastlogin*1000) > " + purgeTime + ")) AS p)");
@ -579,32 +531,137 @@ public final class Database {
mcMMO.p.getLogger().info("Purged " + purgedUsers + " users from the database."); mcMMO.p.getLogger().info("Purged " + purgedUsers + " users from the database.");
} }
private static void printErrors(SQLException ex) {
mcMMO.p.getLogger().severe("SQLException: " + ex.getMessage());
mcMMO.p.getLogger().severe("SQLState: " + ex.getSQLState());
mcMMO.p.getLogger().severe("VendorError: " + ex.getErrorCode());
}
public static void profileCleanup(String playerName) { public static void profileCleanup(String playerName) {
McMMOPlayer mcmmoPlayer = Users.getPlayer(playerName); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(playerName);
if (mcmmoPlayer != null) { if (mcMMOPlayer != null) {
Player player = mcmmoPlayer.getPlayer(); Player player = mcMMOPlayer.getPlayer();
SpoutHud spoutHud = mcmmoPlayer.getProfile().getSpoutHud(); McMMOHud spoutHud = mcMMOPlayer.getProfile().getSpoutHud();
if (spoutHud != null) { if (spoutHud != null) {
spoutHud.removeWidgets(); spoutHud.removeWidgets();
} }
Users.remove(playerName); UserManager.remove(playerName);
if (player.isOnline()) { if (player.isOnline()) {
Users.addUser(player); UserManager.addUser(player);
if (mcMMO.spoutEnabled) { if (mcMMO.spoutEnabled) {
SpoutTools.reloadSpoutPlayer(player); SpoutUtils.reloadSpoutPlayer(player);
} }
} }
} }
} }
/**
* Check database structure for missing values.
*
* @param update Type of data to check updates for
*/
private static void checkDatabaseStructure(DatabaseUpdateType update) {
String sql = null;
ResultSet resultSet = null;
HashMap<Integer, ArrayList<String>> rows = new HashMap<Integer, ArrayList<String>>();
switch (update) {
case BLAST_MINING:
sql = "SELECT * FROM `" + tablePrefix + "cooldowns` ORDER BY `" + tablePrefix + "cooldowns`.`blast_mining` ASC LIMIT 0 , 30";
break;
case CASCADE_DELETE:
write("ALTER TABLE `" + tablePrefix + "huds` ADD FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE;");
write("ALTER TABLE `" + tablePrefix + "experience` ADD FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE;");
write("ALTER TABLE `" + tablePrefix + "cooldowns` ADD FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE;");
write("ALTER TABLE `" + tablePrefix + "skills` ADD FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE;");
break;
case FISHING:
sql = "SELECT * FROM `" + tablePrefix + "experience` ORDER BY `" + tablePrefix + "experience`.`fishing` ASC LIMIT 0 , 30";
break;
case INDEX:
if (read("SHOW INDEX FROM " + tablePrefix + "skills").size() != 13 && checkConnected()) {
mcMMO.p.getLogger().info("Indexing tables, this may take a while on larger databases");
write("ALTER TABLE `" + tablePrefix + "skills` ADD INDEX `idx_taming` (`taming`) USING BTREE, "
+ "ADD INDEX `idx_mining` (`mining`) USING BTREE, "
+ "ADD INDEX `idx_woodcutting` (`woodcutting`) USING BTREE, "
+ "ADD INDEX `idx_repair` (`repair`) USING BTREE, "
+ "ADD INDEX `idx_unarmed` (`unarmed`) USING BTREE, "
+ "ADD INDEX `idx_herbalism` (`herbalism`) USING BTREE, "
+ "ADD INDEX `idx_excavation` (`excavation`) USING BTREE, "
+ "ADD INDEX `idx_archery` (`archery`) USING BTREE, "
+ "ADD INDEX `idx_swords` (`swords`) USING BTREE, "
+ "ADD INDEX `idx_axes` (`axes`) USING BTREE, "
+ "ADD INDEX `idx_acrobatics` (`acrobatics`) USING BTREE, "
+ "ADD INDEX `idx_fishing` (`fishing`) USING BTREE;");
}
break;
default:
break;
}
PreparedStatement statement = null;
try {
if (!checkConnected()) {
return;
}
statement = connection.prepareStatement(sql);
resultSet = statement.executeQuery();
while (resultSet.next()) {
ArrayList<String> column = new ArrayList<String>();
for (int i = 1; i <= resultSet.getMetaData().getColumnCount(); i++) {
column.add(resultSet.getString(i));
}
rows.put(resultSet.getRow(), column);
}
}
catch (SQLException ex) {
switch (update) {
case BLAST_MINING:
mcMMO.p.getLogger().info("Updating mcMMO MySQL tables for Blast Mining...");
write("ALTER TABLE `"+tablePrefix + "cooldowns` ADD `blast_mining` int(32) NOT NULL DEFAULT '0' ;");
break;
case FISHING:
mcMMO.p.getLogger().info("Updating mcMMO MySQL tables for Fishing...");
write("ALTER TABLE `"+tablePrefix + "skills` ADD `fishing` int(10) NOT NULL DEFAULT '0' ;");
write("ALTER TABLE `"+tablePrefix + "experience` ADD `fishing` int(10) NOT NULL DEFAULT '0' ;");
break;
default:
break;
}
}
finally {
if (resultSet != null) {
try {
resultSet.close();
}
catch (SQLException e) {
// Ignore the error, we're leaving
}
}
if (statement != null) {
try {
statement.close();
}
catch (SQLException e) {
// Ignore the error, we're leaving
}
}
}
}
private static void printErrors(SQLException ex) {
mcMMO.p.getLogger().severe("SQLException: " + ex.getMessage());
mcMMO.p.getLogger().severe("SQLState: " + ex.getSQLState());
mcMMO.p.getLogger().severe("VendorError: " + ex.getErrorCode());
}
} }

View File

@ -1,8 +0,0 @@
package com.gmail.nossr50.database;
public enum DatabaseUpdate {
FISHING,
BLAST_MINING,
CASCADE_DELETE,
INDEX;
}

View File

@ -10,48 +10,49 @@ import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import org.bukkit.Bukkit;
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.skills.utilities.SkillType; import com.gmail.nossr50.datatypes.database.PlayerStat;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.StringUtils;
public final class Leaderboard { public final class LeaderboardManager {
private static HashMap<SkillType, List<PlayerStat>> playerStatHash = new HashMap<SkillType, List<PlayerStat>>(); private static HashMap<SkillType, List<PlayerStat>> playerStatHash = new HashMap<SkillType, List<PlayerStat>>();
private static List<PlayerStat> powerLevels = new ArrayList<PlayerStat>(); private static List<PlayerStat> powerLevels = new ArrayList<PlayerStat>();
private static long lastUpdate = 0; private static long lastUpdate = 0;
private Leaderboard() {} private static final long UPDATE_WAIT_TIME = 600000L; // 10 minutes
private static final long ONE_MONTH = 2630000000L;
private LeaderboardManager() {}
/** /**
* Update the leader boards. * Update the leader boards.
*/ */
public static void updateLeaderboards() { public static void updateLeaderboards() {
if(System.currentTimeMillis() < lastUpdate + 600000) { // Only update FFS leaderboards every 10 minutes.. this puts a lot of strain on the server (depending on the size of the database) and should not be done frequently
return; //Only update FFS leaderboards every 10 minutes.. this puts a lot of strain on the server (depending on the size of the database) and should not be done frequently if (System.currentTimeMillis() < lastUpdate + UPDATE_WAIT_TIME) {
return;
} }
lastUpdate = System.currentTimeMillis(); //Log when the last update was run lastUpdate = System.currentTimeMillis(); // Log when the last update was run
powerLevels.clear(); // Clear old values from the power levels
//Initialize lists // Initialize lists
List<PlayerStat> mining, woodcutting, herbalism, excavation, acrobatics, repair, swords, axes, archery, unarmed, taming, fishing; List<PlayerStat> mining = new ArrayList<PlayerStat>();
List<PlayerStat> woodcutting = new ArrayList<PlayerStat>();
List<PlayerStat> herbalism = new ArrayList<PlayerStat>();
List<PlayerStat> excavation = new ArrayList<PlayerStat>();
List<PlayerStat> acrobatics = new ArrayList<PlayerStat>();
List<PlayerStat> repair = new ArrayList<PlayerStat>();
List<PlayerStat> swords = new ArrayList<PlayerStat>();
List<PlayerStat> axes = new ArrayList<PlayerStat>();
List<PlayerStat> archery = new ArrayList<PlayerStat>();
List<PlayerStat> unarmed = new ArrayList<PlayerStat>();
List<PlayerStat> taming = new ArrayList<PlayerStat>();
List<PlayerStat> fishing = new ArrayList<PlayerStat>();
mining = new ArrayList<PlayerStat>(); // Read from the FlatFile database and fill our arrays with information
woodcutting = new ArrayList<PlayerStat>();
herbalism = new ArrayList<PlayerStat>();
excavation = new ArrayList<PlayerStat>();
acrobatics = new ArrayList<PlayerStat>();
repair = new ArrayList<PlayerStat>();
swords = new ArrayList<PlayerStat>();
axes = new ArrayList<PlayerStat>();
archery = new ArrayList<PlayerStat>();
unarmed = new ArrayList<PlayerStat>();
taming = new ArrayList<PlayerStat>();
fishing = new ArrayList<PlayerStat>();
powerLevels = new ArrayList<PlayerStat>();
//Read from the FlatFile database and fill our arrays with information
try { try {
FileReader file = new FileReader(mcMMO.getUsersFilePath()); FileReader file = new FileReader(mcMMO.getUsersFilePath());
BufferedReader in = new BufferedReader(file); BufferedReader in = new BufferedReader(file);
@ -64,7 +65,7 @@ public final class Leaderboard {
String p = character[0]; String p = character[0];
int powerLevel = 0; int powerLevel = 0;
//Prevent the same player from being added multiple times (I'd like to note that this shouldn't happen...) // Prevent the same player from being added multiple times (I'd like to note that this shouldn't happen...)
if (players.contains(p)) { if (players.contains(p)) {
continue; continue;
} }
@ -136,10 +137,11 @@ public final class Leaderboard {
in.close(); in.close();
} }
catch (Exception e) { catch (Exception e) {
mcMMO.p.getLogger().severe(("Exception while reading " + mcMMO.getUsersFilePath() + " (Are you sure you formatted it correctly?)" + e.toString())); mcMMO.p.getLogger().severe("Exception while reading " + mcMMO.getUsersFilePath() + " (Are you sure you formatted it correctly?)" + e.toString());
} }
SkillComparator c = new SkillComparator(); SkillComparator c = new SkillComparator();
Collections.sort(mining, c); Collections.sort(mining, c);
Collections.sort(woodcutting, c); Collections.sort(woodcutting, c);
Collections.sort(repair, c); Collections.sort(repair, c);
@ -227,6 +229,7 @@ public final class Leaderboard {
currentPos++; currentPos++;
continue; continue;
} }
return new int[] {0, 0}; return new int[] {0, 0};
} }
@ -246,19 +249,13 @@ public final class Leaderboard {
currentPos++; currentPos++;
continue; continue;
} }
return new int[] {0, 0}; return new int[] {0, 0};
} }
return new int[] {0, 0}; return new int[] {0, 0};
} }
private static class SkillComparator implements Comparator<PlayerStat> {
@Override
public int compare(PlayerStat o1, PlayerStat o2) {
return (o2.statVal - o1.statVal);
}
}
public static boolean removeFlatFileUser(String playerName) { public static boolean removeFlatFileUser(String playerName) {
boolean worked = false; boolean worked = false;
@ -274,18 +271,18 @@ public final class Leaderboard {
while ((line = in.readLine()) != null) { while ((line = in.readLine()) != null) {
/* Write out the same file but when we get to the player we want to remove, we skip his line. */ // Write out the same file but when we get to the player we want to remove, we skip his line.
if (!line.split(":")[0].equalsIgnoreCase(playerName)) { if (!line.split(":")[0].equalsIgnoreCase(playerName)) {
writer.append(line).append("\r\n"); writer.append(line).append("\r\n");
} }
else { else {
mcMMO.p.getLogger().info("User found, removing..."); mcMMO.p.getLogger().info("User found, removing...");
worked = true; worked = true;
continue; //Skip the player continue; // Skip the player
} }
} }
out = new FileWriter(usersFilePath); //Write out the new file out = new FileWriter(usersFilePath); // Write out the new file
out.write(writer.toString()); out.write(writer.toString());
} }
catch (Exception e) { catch (Exception e) {
@ -314,13 +311,12 @@ public final class Leaderboard {
return worked; return worked;
} }
public static void purgePowerlessFlatfile() { public static void purgePowerlessFlatfile() {
mcMMO.p.getLogger().info("Purging powerless users..."); mcMMO.p.getLogger().info("Purging powerless users...");
int purgedUsers = 0; int purgedUsers = 0;
for (PlayerStat stat : powerLevels) { for (PlayerStat stat : powerLevels) {
if (stat.statVal == 0 && removeFlatFileUser(stat.name) && !Bukkit.getOfflinePlayer(stat.name).isOnline()) { if (stat.statVal == 0 && removeFlatFileUser(stat.name) && !mcMMO.p.getServer().getOfflinePlayer(stat.name).isOnline()) {
purgedUsers++; purgedUsers++;
} }
} }
@ -337,7 +333,7 @@ public final class Leaderboard {
private static int removeOldFlatfileUsers() { private static int removeOldFlatfileUsers() {
int removedPlayers = 0; int removedPlayers = 0;
long currentTime = System.currentTimeMillis(); long currentTime = System.currentTimeMillis();
long purgeTime = 2630000000L * Config.getInstance().getOldUsersCutoff(); long purgeTime = ONE_MONTH * Config.getInstance().getOldUsersCutoff();
BufferedReader in = null; BufferedReader in = null;
FileWriter out = null; FileWriter out = null;
@ -351,7 +347,7 @@ public final class Leaderboard {
while ((line = in.readLine()) != null) { while ((line = in.readLine()) != null) {
/* Write out the same file but when we get to the player we want to remove, we skip his line. */ // Write out the same file but when we get to the player we want to remove, we skip his line.
String[] splitLine = line.split(":"); String[] splitLine = line.split(":");
if (splitLine.length > 37) { if (splitLine.length > 37) {
@ -361,7 +357,7 @@ public final class Leaderboard {
else { else {
mcMMO.p.getLogger().info("User found, removing..."); mcMMO.p.getLogger().info("User found, removing...");
removedPlayers++; removedPlayers++;
continue; //Skip the player continue; // Skip the player
} }
} }
else { else {
@ -369,7 +365,7 @@ public final class Leaderboard {
} }
} }
out = new FileWriter(usersFilePath); //Write out the new file out = new FileWriter(usersFilePath); // Write out the new file
out.write(writer.toString()); out.write(writer.toString());
} }
catch (Exception e) { catch (Exception e) {
@ -398,4 +394,10 @@ public final class Leaderboard {
return removedPlayers; return removedPlayers;
} }
private static class SkillComparator implements Comparator<PlayerStat> {
@Override
public int compare(PlayerStat o1, PlayerStat o2) {
return (o2.statVal - o1.statVal);
}
}
} }

View File

@ -1,39 +0,0 @@
package com.gmail.nossr50.database.commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.database.Database;
import com.gmail.nossr50.database.Leaderboard;
import com.gmail.nossr50.locale.LocaleLoader;
public class McpurgeCommand implements CommandExecutor{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) {
case 0:
if (Config.getInstance().getUseMySQL()) {
Database.purgePowerlessSQL();
if (Config.getInstance().getOldUsersCutoff() != -1) {
Database.purgeOldSQL();
}
}
else {
Leaderboard.purgePowerlessFlatfile();
if (Config.getInstance().getOldUsersCutoff() != -1) {
Leaderboard.purgeOldFlatfile();
}
}
sender.sendMessage(LocaleLoader.getString("Commands.mcpurge.Success"));
return true;
default:
return false;
}
}
}

View File

@ -1,45 +0,0 @@
package com.gmail.nossr50.database.commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.database.Database;
import com.gmail.nossr50.database.Leaderboard;
import com.gmail.nossr50.locale.LocaleLoader;
public class McremoveCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) {
case 1:
/* MySQL */
if (Config.getInstance().getUseMySQL()) {
String tablePrefix = Config.getInstance().getMySQLTablePrefix();
if (Database.update("DELETE FROM " + tablePrefix + "users WHERE " + tablePrefix + "users.user = '" + args[0] + "'") != 0) {
Database.profileCleanup(args[0]);
sender.sendMessage(LocaleLoader.getString("Commands.mcremove.Success", args[0]));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
}
}
else {
if (Leaderboard.removeFlatFileUser(args[0])) {
Database.profileCleanup(args[0]);
sender.sendMessage(LocaleLoader.getString("Commands.mcremove.Success", args[0]));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
}
}
return true;
default:
return false;
}
}
}

View File

@ -1,45 +0,0 @@
package com.gmail.nossr50.database.commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.database.runnables.SQLConversionTask;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Users;
public class MmoupdateCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) {
case 0:
sender.sendMessage(LocaleLoader.getString("Commands.mmoupdate.Start"));
Users.clearAll();
convertToMySQL();
for (Player player : mcMMO.p.getServer().getOnlinePlayers()) {
Users.addUser(player);
}
sender.sendMessage(LocaleLoader.getString("Commands.mmoupdate.Finish"));
return true;
default:
return false;
}
}
/**
* Convert FlatFile data to MySQL data.
*/
private void convertToMySQL() {
if (!Config.getInstance().getUseMySQL()) {
return;
}
mcMMO.p.getServer().getScheduler().runTaskLaterAsynchronously(mcMMO.p, new SQLConversionTask(), 1);
}
}

View File

@ -1,21 +0,0 @@
package com.gmail.nossr50.database.runnables;
import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.database.Database;
import com.gmail.nossr50.util.Users;
public class SQLReconnect implements Runnable {
@Override
public void run() {
if (Database.checkConnected()) {
Users.saveAll(); //Save all profiles
Users.clearAll(); //Clear the profiles
for (Player player : mcMMO.p.getServer().getOnlinePlayers()) {
Users.addUser(player); //Add in new profiles, forcing them to 'load' again from MySQL
}
}
}
}

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