mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2026-02-18 17:53:00 +01:00
Compare commits
2 Commits
dev-asyncL
...
dev-worlds
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
66de4f7cab | ||
|
|
fc935ce9dd |
@@ -28,11 +28,6 @@ Version 1.4.06-dev
|
||||
+ Added multiplier to Archery XP based on bow force
|
||||
+ Added information about /party itemshare and /party expshare to the party help page
|
||||
+ Added option to use scoreboards for power level display instead of Spout.
|
||||
+ Added permission node to prevent inspecting hidden players
|
||||
+ Added SQL to Flatfile database conversion
|
||||
+ Added ability to use custom database managers and convert to/from them
|
||||
= Fixed bug which could cause the server to hang for a minute when checking for updates. (Thanks to Riking)
|
||||
= Fixed bug where spawned arrows could throw ArrayIndexOutOfBoundsException
|
||||
= Fixed bug where custom Spout titles were overwritten by mcMMO.
|
||||
= Fixed bug where Nether Quartz wasn't included in Smelting or item sharing
|
||||
= Fixed bug where players were able to join the same party multiple times
|
||||
@@ -53,10 +48,6 @@ Version 1.4.06-dev
|
||||
= Fixed bug where Blast Mining would drop wrong items
|
||||
= Fixed bug with Blast Mining where the Ability refreshed message was being send too early
|
||||
= Fixed bug where the chance of a successful Gracefull Roll was twice as high as displayed
|
||||
= Fixed bug where lucky perks where not working
|
||||
= Fixed bug with Ice Fishing on a single block of ice
|
||||
= Fixed bug with Ice Fishing which allowed players to break ice in protected areas
|
||||
= Fixed a small bug with mob healthbars and bosses, such as EnderDragons and Withers
|
||||
! Changed Spout notification tiers to be stored in SpoutConfig instead of AdvancedConfig
|
||||
! Changed Berserk to add items to inventory rather than denying pickup
|
||||
! Changed Call of the Wild, newly summoned pet's will have a custom name. (added permission node to disable this)
|
||||
|
||||
6
pom.xml
6
pom.xml
@@ -2,7 +2,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.gmail.nossr50.mcMMO</groupId>
|
||||
<artifactId>mcMMO</artifactId>
|
||||
<version>1.4.06-dev6</version>
|
||||
<version>1.4.06-dev5</version>
|
||||
<name>mcMMO</name>
|
||||
<url>https://github.com/mcMMO-Dev/mcMMO</url>
|
||||
<issueManagement>
|
||||
@@ -145,7 +145,7 @@
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.5.2-R1.0</version>
|
||||
<version>LATEST</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
@@ -165,7 +165,7 @@
|
||||
<dependency>
|
||||
<groupId>com.turt2live.metrics</groupId>
|
||||
<artifactId>MetricsExtension</artifactId>
|
||||
<version>0.0.5-SNAPSHOT</version>
|
||||
<version>0.0.4-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<distributionManagement>
|
||||
|
||||
@@ -4,9 +4,6 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.gmail.nossr50.chat.ChatManager;
|
||||
import com.gmail.nossr50.chat.ChatManagerFactory;
|
||||
import com.gmail.nossr50.chat.ChatMode;
|
||||
import com.gmail.nossr50.chat.PartyChatManager;
|
||||
import com.gmail.nossr50.party.PartyManager;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
|
||||
@@ -25,7 +22,7 @@ public final class ChatAPI {
|
||||
* @param message The message to send
|
||||
*/
|
||||
public static void sendPartyChat(Plugin plugin, String sender, String displayName, String party, String message) {
|
||||
getPartyChatManager(plugin, party).handleChat(sender, displayName, message);
|
||||
ChatManager.handlePartyChat(plugin, PartyManager.getParty(party), sender, displayName, message);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,7 +36,7 @@ public final class ChatAPI {
|
||||
* @param message The message to send
|
||||
*/
|
||||
public static void sendPartyChat(Plugin plugin, String sender, String party, String message) {
|
||||
getPartyChatManager(plugin, party).handleChat(sender, message);
|
||||
ChatManager.handlePartyChat(plugin, PartyManager.getParty(party), sender, sender, message);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,7 +50,7 @@ public final class ChatAPI {
|
||||
* @param message The message to send
|
||||
*/
|
||||
public static void sendAdminChat(Plugin plugin, String sender, String displayName, String message) {
|
||||
ChatManagerFactory.getChatManager(plugin, ChatMode.ADMIN).handleChat(sender, displayName, message);
|
||||
ChatManager.handleAdminChat(plugin, sender, displayName, message);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,7 +63,7 @@ public final class ChatAPI {
|
||||
* @param message The message to send
|
||||
*/
|
||||
public static void sendAdminChat(Plugin plugin, String sender, String message) {
|
||||
ChatManagerFactory.getChatManager(plugin, ChatMode.ADMIN).handleChat(sender, message);
|
||||
ChatManager.handleAdminChat(plugin, sender, sender, message);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,7 +73,7 @@ public final class ChatAPI {
|
||||
* @return true if the player is using party chat, false otherwise
|
||||
*/
|
||||
public static boolean isUsingPartyChat(Player player) {
|
||||
return UserManager.getPlayer(player).getPartyChatMode();
|
||||
return isUsingPartyChat(player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,7 +93,7 @@ public final class ChatAPI {
|
||||
* @return true if the player is using admin chat, false otherwise
|
||||
*/
|
||||
public static boolean isUsingAdminChat(Player player) {
|
||||
return UserManager.getPlayer(player).getAdminChatMode();
|
||||
return isUsingAdminChat(player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,7 +112,7 @@ public final class ChatAPI {
|
||||
* @param player The player to toggle party chat on.
|
||||
*/
|
||||
public static void togglePartyChat(Player player) {
|
||||
UserManager.getPlayer(player).togglePartyChat();
|
||||
togglePartyChat(player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -124,7 +121,7 @@ public final class ChatAPI {
|
||||
* @param playerName The name of the player to toggle party chat on.
|
||||
*/
|
||||
public static void togglePartyChat(String playerName) {
|
||||
UserManager.getPlayer(playerName).togglePartyChat();
|
||||
UserManager.getPlayer(playerName).setPartyChat(!isUsingPartyChat(playerName));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -133,7 +130,7 @@ public final class ChatAPI {
|
||||
* @param player The player to toggle admin chat on.
|
||||
*/
|
||||
public static void toggleAdminChat(Player player) {
|
||||
UserManager.getPlayer(player).toggleAdminChat();
|
||||
toggleAdminChat(player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,13 +139,6 @@ public final class ChatAPI {
|
||||
* @param playerName The name of the player to toggle party chat on.
|
||||
*/
|
||||
public static void toggleAdminChat(String playerName) {
|
||||
UserManager.getPlayer(playerName).toggleAdminChat();
|
||||
}
|
||||
|
||||
private static ChatManager getPartyChatManager(Plugin plugin, String party) {
|
||||
ChatManager chatManager = ChatManagerFactory.getChatManager(plugin, ChatMode.PARTY);
|
||||
((PartyChatManager) chatManager).setParty(PartyManager.getParty(party));
|
||||
|
||||
return chatManager;
|
||||
UserManager.getPlayer(playerName).setAdminChat(!isUsingAdminChat(playerName));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import java.util.Set;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.api.exceptions.InvalidPlayerException;
|
||||
import com.gmail.nossr50.api.exceptions.InvalidSkillException;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
@@ -16,37 +15,6 @@ import com.gmail.nossr50.util.player.UserManager;
|
||||
public final class ExperienceAPI {
|
||||
private ExperienceAPI() {}
|
||||
|
||||
/**
|
||||
* Returns whether given string is a valid type of skill suitable for the
|
||||
* other API calls in this class.
|
||||
* </br>
|
||||
* This function is designed for API usage.
|
||||
*
|
||||
* @param skillType A string that may or may not be a skill
|
||||
* @return true if this is a valid mcMMO skill
|
||||
*/
|
||||
public static boolean isValidSkillType(String skillType) {
|
||||
return SkillType.getSkill(skillType) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the given skill type string is both valid and not a
|
||||
* child skill. (Child skills have no XP of their own, and their level is
|
||||
* derived from the parent(s).)
|
||||
* </br>
|
||||
* This function is designed for API usage.
|
||||
*
|
||||
* @param skillType the skill to check
|
||||
* @return true if this is a valid, non-child mcMMO skill
|
||||
*/
|
||||
public static boolean isNonChildSkill(String skillType) {
|
||||
SkillType skill = SkillType.getSkill(skillType);
|
||||
|
||||
if (skill == null) return false;
|
||||
|
||||
return !skill.isChildSkill();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds raw XP to the player.
|
||||
* </br>
|
||||
@@ -59,7 +27,13 @@ public final class ExperienceAPI {
|
||||
* @throws InvalidSkillException if the given skill is not valid
|
||||
*/
|
||||
public static void addRawXP(Player player, String skillType, int XP) {
|
||||
UserManager.getPlayer(player).applyXpGain(getSkillType(skillType), XP);
|
||||
SkillType skill = SkillType.getSkill(skillType);
|
||||
|
||||
if (skill == null) {
|
||||
throw new InvalidSkillException();
|
||||
}
|
||||
|
||||
UserManager.getPlayer(player).applyXpGain(skill, XP);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,7 +49,13 @@ public final class ExperienceAPI {
|
||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||
*/
|
||||
public static void addRawXPOffline(String playerName, String skillType, int XP) {
|
||||
addOfflineXP(playerName, getSkillType(skillType), XP);
|
||||
SkillType skill = SkillType.getSkill(skillType);
|
||||
|
||||
if (skill == null) {
|
||||
throw new InvalidSkillException();
|
||||
}
|
||||
|
||||
addOfflineXP(playerName, skill, XP);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,7 +70,13 @@ public final class ExperienceAPI {
|
||||
* @throws InvalidSkillException if the given skill is not valid
|
||||
*/
|
||||
public static void addMultipliedXP(Player player, String skillType, int XP) {
|
||||
UserManager.getPlayer(player).applyXpGain(getSkillType(skillType), (int) (XP * Config.getInstance().getExperienceGainsGlobalMultiplier()));
|
||||
SkillType skill = SkillType.getSkill(skillType);
|
||||
|
||||
if (skill == null) {
|
||||
throw new InvalidSkillException();
|
||||
}
|
||||
|
||||
UserManager.getPlayer(player).applyXpGain(skill, (int) (XP * Config.getInstance().getExperienceGainsGlobalMultiplier()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,7 +92,13 @@ public final class ExperienceAPI {
|
||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||
*/
|
||||
public static void addMultipliedXPOffline(String playerName, String skillType, int XP) {
|
||||
addOfflineXP(playerName, getSkillType(skillType), (int) (XP * Config.getInstance().getExperienceGainsGlobalMultiplier()));
|
||||
SkillType skill = SkillType.getSkill(skillType);
|
||||
|
||||
if (skill == null) {
|
||||
throw new InvalidSkillException();
|
||||
}
|
||||
|
||||
addOfflineXP(playerName, skill, (int) (XP * Config.getInstance().getExperienceGainsGlobalMultiplier()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,7 +113,11 @@ public final class ExperienceAPI {
|
||||
* @throws InvalidSkillException if the given skill is not valid
|
||||
*/
|
||||
public static void addModifiedXP(Player player, String skillType, int XP) {
|
||||
SkillType skill = getSkillType(skillType);
|
||||
SkillType skill = SkillType.getSkill(skillType);
|
||||
|
||||
if (skill == null) {
|
||||
throw new InvalidSkillException();
|
||||
}
|
||||
|
||||
UserManager.getPlayer(player).applyXpGain(skill, (int) (XP / skill.getXpModifier() * Config.getInstance().getExperienceGainsGlobalMultiplier()));
|
||||
}
|
||||
@@ -139,14 +135,17 @@ public final class ExperienceAPI {
|
||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||
*/
|
||||
public static void addModifiedXPOffline(String playerName, String skillType, int XP) {
|
||||
SkillType skill = getSkillType(skillType);
|
||||
SkillType skill = SkillType.getSkill(skillType);
|
||||
|
||||
if (skill == null) {
|
||||
throw new InvalidSkillException();
|
||||
}
|
||||
|
||||
addOfflineXP(playerName, skill, (int) (XP / skill.getXpModifier() * Config.getInstance().getExperienceGainsGlobalMultiplier()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds XP to the player, calculates for XP Rate, skill modifiers, perks, child skills,
|
||||
* and party sharing.
|
||||
* 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.
|
||||
*
|
||||
@@ -157,7 +156,13 @@ public final class ExperienceAPI {
|
||||
* @throws InvalidSkillException if the given skill is not valid
|
||||
*/
|
||||
public static void addXP(Player player, String skillType, int XP) {
|
||||
UserManager.getPlayer(player).beginXpGain(getSkillType(skillType), XP);
|
||||
SkillType skill = SkillType.getSkill(skillType);
|
||||
|
||||
if (skill == null) {
|
||||
throw new InvalidSkillException();
|
||||
}
|
||||
|
||||
UserManager.getPlayer(player).beginXpGain(skill, XP);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -173,7 +178,17 @@ public final class ExperienceAPI {
|
||||
* @throws UnsupportedOperationException if the given skill is a child skill
|
||||
*/
|
||||
public static int getXP(Player player, String skillType) {
|
||||
return UserManager.getPlayer(player).getProfile().getSkillXpLevel(getNonChildSkillType(skillType));
|
||||
SkillType skill = SkillType.getSkill(skillType);
|
||||
|
||||
if (skill == null) {
|
||||
throw new InvalidSkillException();
|
||||
}
|
||||
|
||||
if (skill.isChildSkill()) {
|
||||
throw new UnsupportedOperationException("Child skills do not have XP");
|
||||
}
|
||||
|
||||
return UserManager.getPlayer(player).getProfile().getSkillXpLevel(skill);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -190,7 +205,17 @@ public final class ExperienceAPI {
|
||||
* @throws UnsupportedOperationException if the given skill is a child skill
|
||||
*/
|
||||
public static int getOfflineXP(String playerName, String skillType) {
|
||||
return getOfflineProfile(playerName).getSkillXpLevel(getNonChildSkillType(skillType));
|
||||
SkillType skill = SkillType.getSkill(skillType);
|
||||
|
||||
if (skill == null) {
|
||||
throw new InvalidSkillException();
|
||||
}
|
||||
|
||||
if (skill.isChildSkill()) {
|
||||
throw new UnsupportedOperationException("Child skills do not have XP");
|
||||
}
|
||||
|
||||
return getOfflineProfile(playerName).getSkillXpLevel(skill);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -206,7 +231,17 @@ public final class ExperienceAPI {
|
||||
* @throws UnsupportedOperationException if the given skill is a child skill
|
||||
*/
|
||||
public static float getXPRaw(Player player, String skillType) {
|
||||
return UserManager.getPlayer(player).getProfile().getSkillXpLevelRaw(getNonChildSkillType(skillType));
|
||||
SkillType skill = SkillType.getSkill(skillType);
|
||||
|
||||
if (skill == null) {
|
||||
throw new InvalidSkillException();
|
||||
}
|
||||
|
||||
if (skill.isChildSkill()) {
|
||||
throw new UnsupportedOperationException("Child skills do not have XP");
|
||||
}
|
||||
|
||||
return UserManager.getPlayer(player).getProfile().getSkillXpLevelRaw(skill);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -223,7 +258,17 @@ public final class ExperienceAPI {
|
||||
* @throws UnsupportedOperationException if the given skill is a child skill
|
||||
*/
|
||||
public static float getOfflineXPRaw(String playerName, String skillType) {
|
||||
return getOfflineProfile(playerName).getSkillXpLevelRaw(getNonChildSkillType(skillType));
|
||||
SkillType skill = SkillType.getSkill(skillType);
|
||||
|
||||
if (skill == null) {
|
||||
throw new InvalidSkillException();
|
||||
}
|
||||
|
||||
if (skill.isChildSkill()) {
|
||||
throw new UnsupportedOperationException("Child skills do not have XP");
|
||||
}
|
||||
|
||||
return getOfflineProfile(playerName).getSkillXpLevelRaw(skill);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -239,7 +284,17 @@ public final class ExperienceAPI {
|
||||
* @throws UnsupportedOperationException if the given skill is a child skill
|
||||
*/
|
||||
public static int getXPToNextLevel(Player player, String skillType) {
|
||||
return UserManager.getPlayer(player).getProfile().getXpToLevel(getNonChildSkillType(skillType));
|
||||
SkillType skill = SkillType.getSkill(skillType);
|
||||
|
||||
if (skill == null) {
|
||||
throw new InvalidSkillException();
|
||||
}
|
||||
|
||||
if (skill.isChildSkill()) {
|
||||
throw new UnsupportedOperationException("Child skills do not have XP");
|
||||
}
|
||||
|
||||
return UserManager.getPlayer(player).getProfile().getXpToLevel(skill);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -256,7 +311,17 @@ public final class ExperienceAPI {
|
||||
* @throws UnsupportedOperationException if the given skill is a child skill
|
||||
*/
|
||||
public static int getOfflineXPToNextLevel(String playerName, String skillType) {
|
||||
return getOfflineProfile(playerName).getXpToLevel(getNonChildSkillType(skillType));
|
||||
SkillType skill = SkillType.getSkill(skillType);
|
||||
|
||||
if (skill == null) {
|
||||
throw new InvalidSkillException();
|
||||
}
|
||||
|
||||
if (skill.isChildSkill()) {
|
||||
throw new UnsupportedOperationException("Child skills do not have XP");
|
||||
}
|
||||
|
||||
return getOfflineProfile(playerName).getXpToLevel(skill);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -272,7 +337,15 @@ public final class ExperienceAPI {
|
||||
* @throws UnsupportedOperationException if the given skill is a child skill
|
||||
*/
|
||||
public static int getXPRemaining(Player player, String skillType) {
|
||||
SkillType skill = getNonChildSkillType(skillType);
|
||||
SkillType skill = SkillType.getSkill(skillType);
|
||||
|
||||
if (skill == null) {
|
||||
throw new InvalidSkillException();
|
||||
}
|
||||
|
||||
if (skill.isChildSkill()) {
|
||||
throw new UnsupportedOperationException("Child skills do not have XP");
|
||||
}
|
||||
|
||||
PlayerProfile profile = UserManager.getPlayer(player).getProfile();
|
||||
|
||||
@@ -293,7 +366,15 @@ public final class ExperienceAPI {
|
||||
* @throws UnsupportedOperationException if the given skill is a child skill
|
||||
*/
|
||||
public static int getOfflineXPRemaining(String playerName, String skillType) {
|
||||
SkillType skill = getNonChildSkillType(skillType);
|
||||
SkillType skill = SkillType.getSkill(skillType);
|
||||
|
||||
if (skill == null) {
|
||||
throw new InvalidSkillException();
|
||||
}
|
||||
|
||||
if (skill.isChildSkill()) {
|
||||
throw new UnsupportedOperationException("Child skills do not have XP");
|
||||
}
|
||||
|
||||
PlayerProfile profile = getOfflineProfile(playerName);
|
||||
|
||||
@@ -312,7 +393,13 @@ public final class ExperienceAPI {
|
||||
* @throws InvalidSkillException if the given skill is not valid
|
||||
*/
|
||||
public static void addLevel(Player player, String skillType, int levels) {
|
||||
UserManager.getPlayer(player).getProfile().addLevels(getSkillType(skillType), levels);
|
||||
SkillType skill = SkillType.getSkill(skillType);
|
||||
|
||||
if (skill == null) {
|
||||
throw new InvalidSkillException();
|
||||
}
|
||||
|
||||
UserManager.getPlayer(player).getProfile().addLevels(skill, levels);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -329,7 +416,11 @@ public final class ExperienceAPI {
|
||||
*/
|
||||
public static void addLevelOffline(String playerName, String skillType, int levels) {
|
||||
PlayerProfile profile = getOfflineProfile(playerName);
|
||||
SkillType skill = getSkillType(skillType);
|
||||
SkillType skill = SkillType.getSkill(skillType);
|
||||
|
||||
if (skill == null) {
|
||||
throw new InvalidSkillException();
|
||||
}
|
||||
|
||||
if (skill.isChildSkill()) {
|
||||
Set<SkillType> parentSkills = FamilyTree.getParents(skill);
|
||||
@@ -358,7 +449,13 @@ public final class ExperienceAPI {
|
||||
* @throws InvalidSkillException if the given skill is not valid
|
||||
*/
|
||||
public static int getLevel(Player player, String skillType) {
|
||||
return UserManager.getPlayer(player).getProfile().getSkillLevel(getSkillType(skillType));
|
||||
SkillType skill = SkillType.getSkill(skillType);
|
||||
|
||||
if (skill == null) {
|
||||
throw new InvalidSkillException();
|
||||
}
|
||||
|
||||
return UserManager.getPlayer(player).getProfile().getSkillLevel(skill);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -374,7 +471,13 @@ public final class ExperienceAPI {
|
||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||
*/
|
||||
public static int getLevelOffline(String playerName, String skillType) {
|
||||
return getOfflineProfile(playerName).getSkillLevel(getSkillType(skillType));
|
||||
SkillType skill = SkillType.getSkill(skillType);
|
||||
|
||||
if (skill == null) {
|
||||
throw new InvalidSkillException();
|
||||
}
|
||||
|
||||
return getOfflineProfile(playerName).getSkillLevel(skill);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -403,7 +506,11 @@ public final class ExperienceAPI {
|
||||
int powerLevel = 0;
|
||||
PlayerProfile profile = getOfflineProfile(playerName);
|
||||
|
||||
for (SkillType type : SkillType.nonChildSkills()) {
|
||||
for (SkillType type : SkillType.values()) {
|
||||
if (type.isChildSkill()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
powerLevel += profile.getSkillLevel(type);
|
||||
}
|
||||
|
||||
@@ -421,7 +528,13 @@ public final class ExperienceAPI {
|
||||
* @throws InvalidSkillException if the given skill is not valid
|
||||
*/
|
||||
public static int getLevelCap(String skillType) {
|
||||
return Config.getInstance().getLevelCap(getSkillType(skillType));
|
||||
SkillType skill = SkillType.getSkill(skillType);
|
||||
|
||||
if (skill == null) {
|
||||
throw new InvalidSkillException();
|
||||
}
|
||||
|
||||
return Config.getInstance().getLevelCap(skill);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -447,7 +560,13 @@ public final class ExperienceAPI {
|
||||
* @throws InvalidSkillException if the given skill is not valid
|
||||
*/
|
||||
public static void setLevel(Player player, String skillType, int skillLevel) {
|
||||
UserManager.getPlayer(player).getProfile().modifySkill(getSkillType(skillType), skillLevel);
|
||||
SkillType skill = SkillType.getSkill(skillType);
|
||||
|
||||
if (skill == null) {
|
||||
throw new InvalidSkillException();
|
||||
}
|
||||
|
||||
UserManager.getPlayer(player).getProfile().modifySkill(skill, skillLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -463,7 +582,13 @@ public final class ExperienceAPI {
|
||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||
*/
|
||||
public static void setLevelOffline(String playerName, String skillType, int skillLevel) {
|
||||
getOfflineProfile(playerName).modifySkill(getSkillType(skillType), skillLevel);
|
||||
SkillType skill = SkillType.getSkill(skillType);
|
||||
|
||||
if (skill == null) {
|
||||
throw new InvalidSkillException();
|
||||
}
|
||||
|
||||
getOfflineProfile(playerName).modifySkill(skill, skillLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -479,7 +604,17 @@ public final class ExperienceAPI {
|
||||
* @throws UnsupportedOperationException if the given skill is a child skill
|
||||
*/
|
||||
public static void setXP(Player player, String skillType, int newValue) {
|
||||
UserManager.getPlayer(player).getProfile().setSkillXpLevel(getNonChildSkillType(skillType), newValue);
|
||||
SkillType skill = SkillType.getSkill(skillType);
|
||||
|
||||
if (skill == null) {
|
||||
throw new InvalidSkillException();
|
||||
}
|
||||
|
||||
if (skill.isChildSkill()) {
|
||||
throw new UnsupportedOperationException("Child skills do not have XP");
|
||||
}
|
||||
|
||||
UserManager.getPlayer(player).getProfile().setSkillXpLevel(skill, newValue);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -496,7 +631,17 @@ public final class ExperienceAPI {
|
||||
* @throws UnsupportedOperationException if the given skill is a child skill
|
||||
*/
|
||||
public static void setXPOffline(String playerName, String skillType, int newValue) {
|
||||
getOfflineProfile(playerName).setSkillXpLevel(getNonChildSkillType(skillType), newValue);
|
||||
SkillType skill = SkillType.getSkill(skillType);
|
||||
|
||||
if (skill == null) {
|
||||
throw new InvalidSkillException();
|
||||
}
|
||||
|
||||
if (skill.isChildSkill()) {
|
||||
throw new UnsupportedOperationException("Child skills do not have XP");
|
||||
}
|
||||
|
||||
getOfflineProfile(playerName).setSkillXpLevel(skill, newValue);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -512,7 +657,17 @@ public final class ExperienceAPI {
|
||||
* @throws UnsupportedOperationException if the given skill is a child skill
|
||||
*/
|
||||
public static void removeXP(Player player, String skillType, int xp) {
|
||||
UserManager.getPlayer(player).getProfile().removeXp(getNonChildSkillType(skillType), xp);
|
||||
SkillType skill = SkillType.getSkill(skillType);
|
||||
|
||||
if (skill == null) {
|
||||
throw new InvalidSkillException();
|
||||
}
|
||||
|
||||
if (skill.isChildSkill()) {
|
||||
throw new UnsupportedOperationException("Child skills do not have XP");
|
||||
}
|
||||
|
||||
UserManager.getPlayer(player).getProfile().removeXp(skill, xp);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -529,11 +684,26 @@ public final class ExperienceAPI {
|
||||
* @throws UnsupportedOperationException if the given skill is a child skill
|
||||
*/
|
||||
public static void removeXPOffline(String playerName, String skillType, int xp) {
|
||||
getOfflineProfile(playerName).removeXp(getNonChildSkillType(skillType), xp);
|
||||
SkillType skill = SkillType.getSkill(skillType);
|
||||
|
||||
if (skill == null) {
|
||||
throw new InvalidSkillException();
|
||||
}
|
||||
|
||||
if (skill.isChildSkill()) {
|
||||
throw new UnsupportedOperationException("Child skills do not have XP");
|
||||
}
|
||||
|
||||
getOfflineProfile(playerName).removeXp(skill, xp);
|
||||
}
|
||||
|
||||
// Utility methods follow.
|
||||
|
||||
/**
|
||||
* Add XP to an offline player.
|
||||
*
|
||||
* @param playerName The player to check
|
||||
* @param skillType The skill to check
|
||||
* @param XP The amount of XP to award.
|
||||
*/
|
||||
private static void addOfflineXP(String playerName, SkillType skill, int XP) {
|
||||
PlayerProfile profile = getOfflineProfile(playerName);
|
||||
|
||||
@@ -553,7 +723,7 @@ public final class ExperienceAPI {
|
||||
}
|
||||
|
||||
private static PlayerProfile getOfflineProfile(String playerName) {
|
||||
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(playerName, false);
|
||||
PlayerProfile profile = new PlayerProfile(playerName, false);
|
||||
|
||||
if (!profile.isLoaded()) {
|
||||
throw new InvalidPlayerException();
|
||||
@@ -561,24 +731,4 @@ public final class ExperienceAPI {
|
||||
|
||||
return profile;
|
||||
}
|
||||
|
||||
private static SkillType getSkillType(String skillType) throws InvalidSkillException {
|
||||
SkillType skill = SkillType.getSkill(skillType);
|
||||
|
||||
if (skill == null) {
|
||||
throw new InvalidSkillException();
|
||||
}
|
||||
|
||||
return skill;
|
||||
}
|
||||
|
||||
private static SkillType getNonChildSkillType(String skillType) throws InvalidSkillException, UnsupportedOperationException {
|
||||
SkillType skill = getSkillType(skillType);
|
||||
|
||||
if (skill.isChildSkill()) {
|
||||
throw new UnsupportedOperationException("Child skills do not have XP");
|
||||
}
|
||||
|
||||
return skill;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,13 +77,14 @@ public final class PartyAPI {
|
||||
*/
|
||||
public static void addToParty(Player player, String partyName) {
|
||||
Party party = PartyManager.getParty(partyName);
|
||||
String playerName = player.getName();
|
||||
|
||||
if (party == null) {
|
||||
party = new Party(playerName, partyName);
|
||||
party = new Party();
|
||||
party.setName(partyName);
|
||||
party.setLeader(player.getName());
|
||||
}
|
||||
|
||||
PartyManager.addToParty(playerName, UserManager.getPlayer(player), party);
|
||||
PartyManager.addToParty(player, UserManager.getPlayer(player), party);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
package com.gmail.nossr50.chat;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.events.chat.McMMOAdminChatEvent;
|
||||
|
||||
public class AdminChatManager extends ChatManager {
|
||||
protected AdminChatManager(Plugin plugin) {
|
||||
super(plugin, Config.getInstance().getAdminDisplayNames(), "Commands.AdminChat.Prefix");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleChat(String senderName, String displayName, String message, boolean isAsync) {
|
||||
handleChat(new McMMOAdminChatEvent(plugin, senderName, displayName, message, isAsync));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void sendMessage() {
|
||||
plugin.getServer().broadcast(message, "mcmmo.chat.adminchat");
|
||||
}
|
||||
}
|
||||
@@ -1,51 +1,78 @@
|
||||
package com.gmail.nossr50.chat;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.gmail.nossr50.events.chat.McMMOChatEvent;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.party.Party;
|
||||
import com.gmail.nossr50.events.chat.McMMOAdminChatEvent;
|
||||
import com.gmail.nossr50.events.chat.McMMOPartyChatEvent;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
|
||||
public abstract class ChatManager {
|
||||
protected Plugin plugin;
|
||||
protected boolean useDisplayNames;
|
||||
protected String chatPrefix;
|
||||
public final class ChatManager {
|
||||
public ChatManager() {}
|
||||
|
||||
protected String displayName;
|
||||
protected String message;
|
||||
public static void handleAdminChat(Plugin plugin, String playerName, String displayName, String message, boolean isAsync) {
|
||||
McMMOAdminChatEvent chatEvent = new McMMOAdminChatEvent(plugin, playerName, displayName, message, isAsync);
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(chatEvent);
|
||||
|
||||
protected ChatManager(Plugin plugin, boolean useDisplayNames, String chatPrefix) {
|
||||
this.plugin = plugin;
|
||||
this.useDisplayNames = useDisplayNames;
|
||||
this.chatPrefix = chatPrefix;
|
||||
}
|
||||
|
||||
protected void handleChat(McMMOChatEvent event) {
|
||||
plugin.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
if (chatEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
displayName = useDisplayNames ? event.getDisplayName() : event.getSender();
|
||||
message = LocaleLoader.getString(chatPrefix, displayName) + event.getMessage();
|
||||
if (Config.getInstance().getAdminDisplayNames()) {
|
||||
displayName = chatEvent.getDisplayName();
|
||||
}
|
||||
else {
|
||||
displayName = chatEvent.getSender();
|
||||
}
|
||||
|
||||
sendMessage();
|
||||
String adminMessage = chatEvent.getMessage();
|
||||
|
||||
mcMMO.p.getServer().broadcast(LocaleLoader.getString("Commands.AdminChat.Prefix", displayName) + adminMessage, "mcmmo.chat.adminchat");
|
||||
}
|
||||
|
||||
public void handleChat(String senderName, String message) {
|
||||
handleChat(senderName, senderName, message, false);
|
||||
public static void handleAdminChat(Plugin plugin, String senderName, String message) {
|
||||
handleAdminChat(plugin, senderName, senderName, message);
|
||||
}
|
||||
|
||||
public void handleChat(Player player, String message, boolean isAsync) {
|
||||
handleChat(player.getName(), player.getDisplayName(), message, isAsync);
|
||||
public static void handleAdminChat(Plugin plugin, String playerName, String displayName, String message) {
|
||||
handleAdminChat(plugin, playerName, displayName, message, false);
|
||||
}
|
||||
|
||||
public void handleChat(String senderName, String displayName, String message) {
|
||||
handleChat(senderName, displayName, message, false);
|
||||
public static void handlePartyChat(Plugin plugin, Party party, String playerName, String displayName, String message, boolean isAsync) {
|
||||
String partyName = party.getName();
|
||||
|
||||
McMMOPartyChatEvent chatEvent = new McMMOPartyChatEvent(plugin, playerName, displayName, partyName, message, isAsync);
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(chatEvent);
|
||||
|
||||
if (chatEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Config.getInstance().getPartyDisplayNames()) {
|
||||
displayName = chatEvent.getDisplayName();
|
||||
}
|
||||
else {
|
||||
displayName = chatEvent.getSender();
|
||||
}
|
||||
|
||||
String partyMessage = chatEvent.getMessage();
|
||||
|
||||
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 abstract void handleChat(String senderName, String displayName, String message, boolean isAsync);
|
||||
public static void handlePartyChat(Plugin plugin, Party party, String senderName, String message) {
|
||||
handlePartyChat(plugin, party, senderName, senderName, message);
|
||||
}
|
||||
|
||||
protected abstract void sendMessage();
|
||||
public static void handlePartyChat(Plugin plugin, Party party, String playerName, String displayName, String message) {
|
||||
handlePartyChat(plugin, party, playerName, displayName, message, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.gmail.nossr50.chat;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class ChatManagerFactory {
|
||||
private static final HashMap<Plugin, AdminChatManager> adminChatManagers = new HashMap<Plugin, AdminChatManager>();
|
||||
private static final HashMap<Plugin, PartyChatManager> partyChatManagers = new HashMap<Plugin, PartyChatManager>();
|
||||
|
||||
public static ChatManager getChatManager(Plugin plugin, ChatMode mode) {
|
||||
switch (mode) {
|
||||
case ADMIN:
|
||||
if (!adminChatManagers.containsKey(plugin)) {
|
||||
adminChatManagers.put(plugin, new AdminChatManager(plugin));
|
||||
}
|
||||
|
||||
return adminChatManagers.get(plugin);
|
||||
case PARTY:
|
||||
if (!partyChatManagers.containsKey(plugin)) {
|
||||
partyChatManagers.put(plugin, new PartyChatManager(plugin));
|
||||
}
|
||||
|
||||
return partyChatManagers.get(plugin);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package com.gmail.nossr50.chat;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.party.Party;
|
||||
import com.gmail.nossr50.events.chat.McMMOPartyChatEvent;
|
||||
|
||||
public class PartyChatManager extends ChatManager {
|
||||
private Party party;
|
||||
|
||||
protected PartyChatManager(Plugin plugin) {
|
||||
super(plugin, Config.getInstance().getPartyDisplayNames(), "Commands.Party.Chat.Prefix");
|
||||
}
|
||||
|
||||
public void setParty(Party party) {
|
||||
this.party = party;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleChat(String senderName, String displayName, String message, boolean isAsync) {
|
||||
handleChat(new McMMOPartyChatEvent(plugin, senderName, displayName, party.getName(), message, isAsync));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void sendMessage() {
|
||||
for (Player member : party.getOnlineMembers()) {
|
||||
member.sendMessage(message);
|
||||
}
|
||||
|
||||
plugin.getLogger().info("[P]<" + party.getName() + ">" + message);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import java.util.Set;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.StringUtil;
|
||||
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
@@ -30,7 +29,7 @@ public class KrakenCommand implements TabExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
UserManager.getPlayer((Player) sender).getFishingManager().unleashTheKraken();
|
||||
UserManager.getPlayer(sender.getName()).getFishingManager().unleashTheKraken();
|
||||
return true;
|
||||
|
||||
case 1:
|
||||
|
||||
@@ -62,52 +62,52 @@ public class McmmoCommand implements CommandExecutor {
|
||||
private void displayPartyCommands(CommandSender sender) {
|
||||
if (Permissions.party(sender)) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.Party.Commands"));
|
||||
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 quit " + LocaleLoader.getString("Commands.Party.Quit"));
|
||||
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 quit " + LocaleLoader.getString("Commands.Party.Quit"));
|
||||
|
||||
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 accept " + LocaleLoader.getString("Commands.Party.Accept"));
|
||||
sender.sendMessage("/party invite <" + LocaleLoader.getString("Commands.Usage.Player") + "> " + LocaleLoader.getString("Commands.Party.Invite"));
|
||||
sender.sendMessage("/party accept " + LocaleLoader.getString("Commands.Party.Accept"));
|
||||
|
||||
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) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.Other"));
|
||||
sender.sendMessage(" /mcstats " + LocaleLoader.getString("Commands.Stats"));
|
||||
sender.sendMessage(" /mctop " + LocaleLoader.getString("Commands.Leaderboards"));
|
||||
sender.sendMessage("/mcstats " + LocaleLoader.getString("Commands.Stats"));
|
||||
sender.sendMessage("/mctop " + LocaleLoader.getString("Commands.Leaderboards"));
|
||||
|
||||
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)) {
|
||||
sender.sendMessage(" /mcability " + LocaleLoader.getString("Commands.ToggleAbility"));
|
||||
sender.sendMessage("/mcability " + LocaleLoader.getString("Commands.ToggleAbility"));
|
||||
}
|
||||
|
||||
if (Permissions.adminChat(sender)) {
|
||||
sender.sendMessage(" /adminchat " + LocaleLoader.getString("Commands.AdminToggle"));
|
||||
sender.sendMessage("/adminchat " + LocaleLoader.getString("Commands.AdminToggle"));
|
||||
}
|
||||
|
||||
if (Permissions.inspect(sender)) {
|
||||
sender.sendMessage(" /inspect " + LocaleLoader.getString("Commands.Inspect"));
|
||||
sender.sendMessage("/inspect " + LocaleLoader.getString("Commands.Inspect"));
|
||||
}
|
||||
|
||||
if (Permissions.mmoedit(sender)) {
|
||||
sender.sendMessage(" /mmoedit " + LocaleLoader.getString("Commands.mmoedit"));
|
||||
sender.sendMessage("/mmoedit " + LocaleLoader.getString("Commands.mmoedit"));
|
||||
}
|
||||
|
||||
if (Permissions.mcgod(sender)) {
|
||||
sender.sendMessage(" /mcgod " + LocaleLoader.getString("Commands.mcgod"));
|
||||
sender.sendMessage("/mcgod " + LocaleLoader.getString("Commands.mcgod"));
|
||||
}
|
||||
|
||||
sender.sendMessage(" /<skill>" + LocaleLoader.getString("Commands.SkillInfo"));
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.SkillInfo"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import java.util.List;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
@@ -18,7 +17,7 @@ public class McnotifyCommand implements TabExecutor {
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
switch (args.length) {
|
||||
case 0:
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer((Player) sender);
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
||||
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.Notifications." + (mcMMOPlayer.useChatNotifications() ? "Off" : "On")));
|
||||
mcMMOPlayer.toggleChatNotifications();
|
||||
|
||||
@@ -7,7 +7,6 @@ import java.util.List;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.StringUtil;
|
||||
|
||||
import com.gmail.nossr50.datatypes.MobHealthbarType;
|
||||
@@ -39,7 +38,7 @@ public class MobhealthCommand implements TabExecutor {
|
||||
|
||||
switch (args.length) {
|
||||
case 1:
|
||||
PlayerProfile playerProfile = UserManager.getPlayer((Player) sender).getProfile();
|
||||
PlayerProfile playerProfile = UserManager.getPlayer(sender.getName()).getProfile();
|
||||
|
||||
try {
|
||||
MobHealthbarType type = MobHealthbarType.valueOf(args[0].toUpperCase().trim());
|
||||
|
||||
@@ -33,8 +33,8 @@ public abstract class ToggleCommand implements TabExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
player = (Player) sender;
|
||||
mcMMOPlayer = UserManager.getPlayer(player);
|
||||
mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
||||
player = mcMMOPlayer.getPlayer();
|
||||
|
||||
applyCommandAction();
|
||||
return true;
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
package com.gmail.nossr50.commands.chat;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.chat.ChatManager;
|
||||
import com.gmail.nossr50.chat.ChatMode;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
|
||||
public class AdminChatCommand extends ChatCommand {
|
||||
public AdminChatCommand() {
|
||||
@@ -11,6 +15,12 @@ public class AdminChatCommand extends ChatCommand {
|
||||
|
||||
@Override
|
||||
protected void handleChatSending(CommandSender sender, String[] args) {
|
||||
chatManager.handleChat(sender.getName(), getDisplayName(sender), buildChatMessage(args, 0));
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
ChatManager.handleAdminChat(mcMMO.p, player.getName(), player.getDisplayName(), buildChatMessage(args, 0));
|
||||
}
|
||||
else {
|
||||
ChatManager.handleAdminChat(mcMMO.p, LocaleLoader.getString("Commands.Chat.Console"), buildChatMessage(args, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,12 +6,8 @@ import java.util.List;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.StringUtil;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.chat.ChatManager;
|
||||
import com.gmail.nossr50.chat.ChatManagerFactory;
|
||||
import com.gmail.nossr50.chat.ChatMode;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
@@ -22,12 +18,10 @@ import com.google.common.collect.ImmutableList;
|
||||
|
||||
public abstract class ChatCommand implements TabExecutor {
|
||||
protected ChatMode chatMode;
|
||||
protected ChatManager chatManager;
|
||||
private McMMOPlayer mcMMOPlayer;
|
||||
|
||||
public ChatCommand(ChatMode chatMode) {
|
||||
this.chatMode = chatMode;
|
||||
this.chatManager = ChatManagerFactory.getChatManager(mcMMO.p, chatMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -38,7 +32,7 @@ public abstract class ChatCommand implements TabExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
mcMMOPlayer = UserManager.getPlayer((Player) sender);
|
||||
mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
||||
|
||||
if (chatMode.isEnabled(mcMMOPlayer)) {
|
||||
disableChatMode(sender);
|
||||
@@ -55,7 +49,7 @@ public abstract class ChatCommand implements TabExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
mcMMOPlayer = UserManager.getPlayer((Player) sender);
|
||||
mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
||||
|
||||
enableChatMode(sender);
|
||||
return true;
|
||||
@@ -66,7 +60,7 @@ public abstract class ChatCommand implements TabExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
mcMMOPlayer = UserManager.getPlayer((Player) sender);
|
||||
mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
||||
|
||||
disableChatMode(sender);
|
||||
return true;
|
||||
@@ -102,10 +96,6 @@ public abstract class ChatCommand implements TabExecutor {
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
protected String getDisplayName(CommandSender sender) {
|
||||
return (sender instanceof Player) ? ((Player) sender).getDisplayName() : LocaleLoader.getString("Commands.Chat.Console");
|
||||
}
|
||||
|
||||
protected abstract void handleChatSending(CommandSender sender, String[] args);
|
||||
|
||||
private void enableChatMode(CommandSender sender) {
|
||||
|
||||
@@ -3,8 +3,9 @@ package com.gmail.nossr50.commands.chat;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.chat.ChatManager;
|
||||
import com.gmail.nossr50.chat.ChatMode;
|
||||
import com.gmail.nossr50.chat.PartyChatManager;
|
||||
import com.gmail.nossr50.datatypes.party.Party;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.party.PartyManager;
|
||||
@@ -17,18 +18,16 @@ public class PartyChatCommand extends ChatCommand {
|
||||
|
||||
@Override
|
||||
protected void handleChatSending(CommandSender sender, String[] args) {
|
||||
Party party;
|
||||
String message;
|
||||
|
||||
if (sender instanceof Player) {
|
||||
party = UserManager.getPlayer((Player) sender).getParty();
|
||||
Player player = (Player) sender;
|
||||
Party party = UserManager.getPlayer(player).getParty();
|
||||
|
||||
if (party == null) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.Party.None"));
|
||||
return;
|
||||
}
|
||||
|
||||
message = buildChatMessage(args, 0);
|
||||
ChatManager.handlePartyChat(mcMMO.p, party, player.getName(), player.getDisplayName(), buildChatMessage(args, 0));
|
||||
}
|
||||
else {
|
||||
if (args.length < 2) {
|
||||
@@ -36,17 +35,14 @@ public class PartyChatCommand extends ChatCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
party = PartyManager.getParty(args[0]);
|
||||
Party party = PartyManager.getParty(args[0]);
|
||||
|
||||
if (party == null) {
|
||||
sender.sendMessage(LocaleLoader.getString("Party.InvalidName"));
|
||||
return;
|
||||
}
|
||||
|
||||
message = buildChatMessage(args, 1);
|
||||
ChatManager.handlePartyChat(mcMMO.p, party, LocaleLoader.getString("Commands.Chat.Console"), buildChatMessage(args, 1));
|
||||
}
|
||||
|
||||
((PartyChatManager) chatManager).setParty(party);
|
||||
chatManager.handleChat(sender.getName(), getDisplayName(sender), message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.util.StringUtil;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.util.commands.CommandUtils;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
@@ -21,7 +22,7 @@ public class McremoveCommand implements TabExecutor {
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
switch (args.length) {
|
||||
case 1:
|
||||
if (UserManager.getPlayer(args[0]) == null && CommandUtils.unloadedProfile(sender, mcMMO.getDatabaseManager().loadPlayerProfile(args[0], false))) {
|
||||
if (UserManager.getPlayer(args[0]) == null && CommandUtils.unloadedProfile(sender, new PlayerProfile(args[0], false))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
package com.gmail.nossr50.commands.database;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.database.DatabaseManagerFactory;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
public class MmoshowdbCommand implements TabExecutor {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (args.length != 0) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
Class<?> clazz = DatabaseManagerFactory.getCustomDatabaseManagerClass();
|
||||
if (clazz != null) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.mmoshowdb", clazz.getName()));
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
if (Config.getInstance().getUseMySQL()) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.mmoshowdb", "sql"));
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.mmoshowdb", "flatfile"));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
return ImmutableList.of();
|
||||
}
|
||||
}
|
||||
@@ -9,130 +9,41 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.database.DatabaseManager;
|
||||
import com.gmail.nossr50.database.DatabaseManagerFactory;
|
||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.runnables.database.ConversionTask;
|
||||
import com.gmail.nossr50.runnables.database.SQLConversionTask;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
public class MmoupdateCommand implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!Config.getInstance().getUseMySQL()) {
|
||||
sender.sendMessage("SQL Mode is not enabled."); // TODO: Localize
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (args.length) {
|
||||
case 1:
|
||||
String argType = args[0];
|
||||
String oldType = validateName(sender, args[0]);
|
||||
if (oldType == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String newType = getCurrentDb();
|
||||
|
||||
if (newType.equals(oldType)) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.mmoupdate.Same", argType));
|
||||
return true;
|
||||
}
|
||||
|
||||
DatabaseManager oldDb;
|
||||
if (oldType == "sql") {
|
||||
oldDb = DatabaseManagerFactory.createSQLDatabaseManager();
|
||||
}
|
||||
else if (oldType == "flatfile") {
|
||||
oldDb = DatabaseManagerFactory.createFlatfileDatabaseManager();
|
||||
}
|
||||
else try {
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<? extends DatabaseManager> clazz = (Class<? extends DatabaseManager>) Class.forName(oldType);
|
||||
oldDb = DatabaseManagerFactory.createCustomDatabaseManager((Class<? extends DatabaseManager>) clazz);
|
||||
|
||||
oldType = clazz.getSimpleName(); // For pretty-printing; we have the database now
|
||||
}
|
||||
catch (Throwable e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.mmoupdate.Start", oldType, newType));
|
||||
|
||||
// Convert the online players right away, without waiting
|
||||
// first, flush out the current data
|
||||
case 0:
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.mmoupdate.Start"));
|
||||
UserManager.saveAll();
|
||||
UserManager.clearAll();
|
||||
new SQLConversionTask().runTaskLaterAsynchronously(mcMMO.p, 1);
|
||||
|
||||
for (Player player : mcMMO.p.getServer().getOnlinePlayers()) {
|
||||
// Get the profile from the old database and save it in the new
|
||||
PlayerProfile profile = oldDb.loadPlayerProfile(player.getName(), false);
|
||||
if (profile.isLoaded()) {
|
||||
mcMMO.getDatabaseManager().saveUser(profile);
|
||||
}
|
||||
|
||||
// Reload from the current database via UserManager
|
||||
UserManager.addUser(player);
|
||||
}
|
||||
|
||||
// Schedule the task for all users
|
||||
new ConversionTask(oldDb, sender, oldType, newType).runTaskAsynchronously(mcMMO.p);
|
||||
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.mmoupdate.Finish"));
|
||||
return true;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null - if type not recognized / class not found
|
||||
* empty string - if type is same as current
|
||||
* normalized string - if type is recognized
|
||||
*/
|
||||
private String validateName(CommandSender sender, String type) {
|
||||
if (type.equalsIgnoreCase("sql") || type.equalsIgnoreCase("mysql")) {
|
||||
return "sql";
|
||||
}
|
||||
|
||||
if (type.equalsIgnoreCase("flatfile") || type.equalsIgnoreCase("file")) {
|
||||
return "flatfile";
|
||||
}
|
||||
|
||||
try {
|
||||
Class<?> clazz = Class.forName(type);
|
||||
|
||||
if (!DatabaseManager.class.isAssignableFrom(clazz)) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.mmoupdate.InvalidType", type));
|
||||
return null;
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
catch (Exception e) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.mmoupdate.InvalidType", type));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private String getCurrentDb() {
|
||||
if (DatabaseManagerFactory.getCustomDatabaseManagerClass() != null) {
|
||||
return DatabaseManagerFactory.getCustomDatabaseManagerClass().getSimpleName();
|
||||
}
|
||||
|
||||
if (Config.getInstance().getUseMySQL()) {
|
||||
return "sql";
|
||||
}
|
||||
else {
|
||||
return "flatfile";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
Class<?> clazz = DatabaseManagerFactory.getCustomDatabaseManagerClass();
|
||||
if (clazz != null) {
|
||||
return ImmutableList.of("flatfile", "sql", clazz.getName());
|
||||
}
|
||||
return ImmutableList.of("flatfile", "sql");
|
||||
return ImmutableList.of();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,7 @@ package com.gmail.nossr50.commands.experience;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.skills.SkillUtils;
|
||||
@@ -23,10 +21,6 @@ public class AddlevelsCommand extends ExperienceCommand {
|
||||
@Override
|
||||
protected void handleCommand(SkillType skill) {
|
||||
profile.addLevels(skill, value);
|
||||
|
||||
if (player != null) {
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerLevelUpEvent(player, skill, value));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,7 +10,6 @@ import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.StringUtil;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
@@ -47,8 +46,8 @@ public abstract class ExperienceCommand implements TabExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
player = (Player) sender;
|
||||
mcMMOPlayer = UserManager.getPlayer(player);
|
||||
mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
||||
player = mcMMOPlayer.getPlayer();
|
||||
profile = mcMMOPlayer.getProfile();
|
||||
|
||||
editValues();
|
||||
@@ -69,7 +68,7 @@ public abstract class ExperienceCommand implements TabExecutor {
|
||||
|
||||
// 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 = mcMMO.getDatabaseManager().loadPlayerProfile(args[0], false);
|
||||
profile = new PlayerProfile(args[0], false);
|
||||
|
||||
if (CommandUtils.unloadedProfile(sender, profile)) {
|
||||
return true;
|
||||
|
||||
@@ -2,9 +2,7 @@ package com.gmail.nossr50.commands.experience;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.skills.SkillUtils;
|
||||
@@ -23,10 +21,6 @@ public class MmoeditCommand extends ExperienceCommand {
|
||||
@Override
|
||||
protected void handleCommand(SkillType skill) {
|
||||
profile.modifySkill(skill, value);
|
||||
|
||||
if (player != null) {
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerLevelUpEvent(player, skill, value - profile.getSkillLevel(skill)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,11 +2,9 @@ package com.gmail.nossr50.commands.experience;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.commands.CommandUtils;
|
||||
@@ -39,8 +37,8 @@ public class SkillresetCommand extends ExperienceCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
player = (Player) sender;
|
||||
mcMMOPlayer = UserManager.getPlayer(player);
|
||||
mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
||||
player = mcMMOPlayer.getPlayer();
|
||||
profile = mcMMOPlayer.getProfile();
|
||||
|
||||
editValues();
|
||||
@@ -60,7 +58,7 @@ public class SkillresetCommand extends ExperienceCommand {
|
||||
|
||||
// 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 = mcMMO.getDatabaseManager().loadPlayerProfile(args[0], false);
|
||||
profile = new PlayerProfile(args[0], false);
|
||||
|
||||
if (CommandUtils.unloadedProfile(sender, profile)) {
|
||||
return true;
|
||||
@@ -86,11 +84,13 @@ public class SkillresetCommand extends ExperienceCommand {
|
||||
|
||||
@Override
|
||||
protected boolean permissionsCheckSelf(CommandSender sender) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean permissionsCheckOthers(CommandSender sender) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -102,10 +102,6 @@ public class SkillresetCommand extends ExperienceCommand {
|
||||
}
|
||||
|
||||
profile.modifySkill(skill, 0);
|
||||
|
||||
if (player != null) {
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerLevelUpEvent(player, skill, 0 - profile.getSkillLevel(skill)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,8 +15,8 @@ public class PartyAcceptCommand implements CommandExecutor {
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
switch (args.length) {
|
||||
case 1:
|
||||
Player player = (Player) sender;
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
|
||||
if (!mcMMOPlayer.hasPartyInvite()) {
|
||||
sender.sendMessage(LocaleLoader.getString("mcMMO.NoInvites"));
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.gmail.nossr50.commands.party;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.datatypes.party.Party;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
@@ -15,7 +14,7 @@ public class PartyChangeOwnerCommand implements CommandExecutor {
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
switch (args.length) {
|
||||
case 2:
|
||||
Party playerParty = UserManager.getPlayer((Player) sender).getParty();
|
||||
Party playerParty = UserManager.getPlayer(sender.getName()).getParty();
|
||||
|
||||
if (!playerParty.getMembers().contains(args[1])) {
|
||||
sender.sendMessage(LocaleLoader.getString("Party.NotInYourParty", args[1]));
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.gmail.nossr50.commands.party;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.datatypes.party.Party;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
@@ -14,7 +13,7 @@ public class PartyChangePasswordCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
playerParty = UserManager.getPlayer((Player) sender).getParty();
|
||||
playerParty = UserManager.getPlayer(sender.getName()).getParty();
|
||||
|
||||
switch (args.length) {
|
||||
case 1:
|
||||
|
||||
@@ -70,8 +70,8 @@ public class PartyCommand implements TabExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
player = (Player) sender;
|
||||
mcMMOPlayer = UserManager.getPlayer(player);
|
||||
mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
||||
player = mcMMOPlayer.getPlayer();
|
||||
|
||||
if (args.length < 1) {
|
||||
if (!mcMMOPlayer.inParty()) {
|
||||
|
||||
@@ -19,8 +19,8 @@ public class PartyCreateCommand implements CommandExecutor {
|
||||
case 3:
|
||||
Party newParty = PartyManager.getParty(args[1]);
|
||||
|
||||
Player player = (Player) sender;
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
|
||||
// Check to see if the party exists, and if it does cancel creating a new party
|
||||
if (PartyManager.checkPartyExistence(player, newParty, args[1])) {
|
||||
|
||||
@@ -16,7 +16,7 @@ public class PartyDisbandCommand implements CommandExecutor {
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
switch (args.length) {
|
||||
case 1:
|
||||
Party playerParty = UserManager.getPlayer((Player) sender).getParty();
|
||||
Party playerParty = UserManager.getPlayer(sender.getName()).getParty();
|
||||
String partyName = playerParty.getName();
|
||||
|
||||
for (Player member : playerParty.getOnlineMembers()) {
|
||||
|
||||
@@ -26,7 +26,7 @@ public class PartyExpShareCommand implements CommandExecutor {
|
||||
|
||||
switch (args.length) {
|
||||
case 2:
|
||||
playerParty = UserManager.getPlayer((Player) sender).getParty();
|
||||
playerParty = UserManager.getPlayer(sender.getName()).getParty();
|
||||
|
||||
if (args[1].equalsIgnoreCase("none") || CommandUtils.shouldDisableToggle(args[1])) {
|
||||
handleChangingShareMode(ShareMode.NONE);
|
||||
|
||||
@@ -25,8 +25,8 @@ public class PartyInfoCommand implements CommandExecutor {
|
||||
switch (args.length) {
|
||||
case 0:
|
||||
case 1:
|
||||
player = (Player) sender;
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
||||
player = mcMMOPlayer.getPlayer();
|
||||
playerParty = mcMMOPlayer.getParty();
|
||||
|
||||
displayPartyHeader();
|
||||
|
||||
@@ -24,8 +24,8 @@ public class PartyInviteCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
Player target = mcMMOTarget.getPlayer();
|
||||
Player player = (Player) sender;
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
|
||||
if (player.equals(target)) {
|
||||
sender.sendMessage(LocaleLoader.getString("Party.Invite.Self"));
|
||||
|
||||
@@ -26,7 +26,7 @@ public class PartyItemShareCommand implements CommandExecutor {
|
||||
|
||||
switch (args.length) {
|
||||
case 2:
|
||||
playerParty = UserManager.getPlayer((Player) sender).getParty();
|
||||
playerParty = UserManager.getPlayer(sender.getName()).getParty();
|
||||
ShareMode mode = ShareMode.getShareMode(args[1].toUpperCase());
|
||||
|
||||
if (mode == null) {
|
||||
@@ -38,7 +38,7 @@ public class PartyItemShareCommand implements CommandExecutor {
|
||||
return true;
|
||||
|
||||
case 3:
|
||||
playerParty = UserManager.getPlayer((Player) sender).getParty();
|
||||
playerParty = UserManager.getPlayer(sender.getName()).getParty();
|
||||
boolean toggle = false;
|
||||
|
||||
if (CommandUtils.shouldEnableToggle(args[2])) {
|
||||
|
||||
@@ -77,8 +77,8 @@ public class PartyJoinCommand implements CommandExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
player = (Player) sender;
|
||||
mcMMOPlayer = UserManager.getPlayer(player);
|
||||
mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
||||
player = mcMMOPlayer.getPlayer();
|
||||
|
||||
playerParty = mcMMOPlayer.getParty();
|
||||
targetParty = mcMMOTarget.getParty();
|
||||
|
||||
@@ -18,7 +18,7 @@ public class PartyKickCommand implements CommandExecutor {
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
switch (args.length) {
|
||||
case 2:
|
||||
Party playerParty = UserManager.getPlayer((Player) sender).getParty();
|
||||
Party playerParty = UserManager.getPlayer(sender.getName()).getParty();
|
||||
OfflinePlayer target = mcMMO.p.getServer().getOfflinePlayer(args[1]);
|
||||
|
||||
if (!playerParty.getMembers().contains(target.getName())) {
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.gmail.nossr50.commands.party;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.datatypes.party.Party;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
@@ -16,7 +15,7 @@ public class PartyLockCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
playerParty = UserManager.getPlayer((Player) sender).getParty();
|
||||
playerParty = UserManager.getPlayer(sender.getName()).getParty();
|
||||
|
||||
switch (args.length) {
|
||||
case 1:
|
||||
|
||||
@@ -17,7 +17,7 @@ public class PartyRenameCommand implements CommandExecutor {
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
switch (args.length) {
|
||||
case 2:
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer((Player) sender);
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
||||
Party playerParty = mcMMOPlayer.getParty();
|
||||
|
||||
String oldPartyName = playerParty.getName();
|
||||
|
||||
@@ -18,8 +18,8 @@ public class PtpAcceptAnyCommand implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) sender;
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
|
||||
if (mcMMOPlayer.getPtpConfirmRequired()) {
|
||||
player.sendMessage(LocaleLoader.getString("Commands.ptp.AcceptAny.Disabled"));
|
||||
|
||||
@@ -21,8 +21,8 @@ public class PtpAcceptCommand implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) sender;
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
|
||||
if (!mcMMOPlayer.hasPtpRequest()) {
|
||||
player.sendMessage(LocaleLoader.getString("Commands.ptp.NoRequests"));
|
||||
|
||||
@@ -51,19 +51,15 @@ public class PtpCommand implements TabExecutor {
|
||||
return ptpAcceptAnyCommand.onCommand(sender, command, label, args);
|
||||
}
|
||||
|
||||
Player player = (Player) sender;
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
|
||||
long recentlyHurt = mcMMOPlayer.getRecentlyHurt();
|
||||
int hurtCooldown = Config.getInstance().getPTPCommandRecentlyHurtCooldown();
|
||||
int recentlyhurt_cooldown = Config.getInstance().getPTPCommandRecentlyHurtCooldown();
|
||||
|
||||
if (hurtCooldown > 0) {
|
||||
int timeRemaining = SkillUtils.calculateTimeLeft(recentlyHurt * Misc.TIME_CONVERSION_FACTOR, hurtCooldown, player);
|
||||
|
||||
if (timeRemaining > 0) {
|
||||
player.sendMessage(LocaleLoader.getString("Item.Injured.Wait", timeRemaining));
|
||||
return true;
|
||||
}
|
||||
if (!SkillUtils.cooldownOver(recentlyHurt * Misc.TIME_CONVERSION_FACTOR, recentlyhurt_cooldown, player)) {
|
||||
player.sendMessage(LocaleLoader.getString("Item.Injured.Wait", SkillUtils.calculateTimeLeft(recentlyHurt * Misc.TIME_CONVERSION_FACTOR, recentlyhurt_cooldown, player)));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("accept")) {
|
||||
@@ -78,13 +74,9 @@ public class PtpCommand implements TabExecutor {
|
||||
int ptpCooldown = Config.getInstance().getPTPCommandCooldown();
|
||||
long lastTeleport = mcMMOPlayer.getLastTeleport();
|
||||
|
||||
if (ptpCooldown > 0) {
|
||||
int timeRemaining = SkillUtils.calculateTimeLeft(lastTeleport * Misc.TIME_CONVERSION_FACTOR, ptpCooldown, player);
|
||||
|
||||
if (timeRemaining > 0) {
|
||||
player.sendMessage(LocaleLoader.getString("Item.Generic.Wait", timeRemaining));
|
||||
return true;
|
||||
}
|
||||
if (!SkillUtils.cooldownOver(lastTeleport * Misc.TIME_CONVERSION_FACTOR, ptpCooldown, player)) {
|
||||
player.sendMessage(LocaleLoader.getString("Item.Generic.Wait", SkillUtils.calculateTimeLeft(lastTeleport * Misc.TIME_CONVERSION_FACTOR, ptpCooldown, player)));
|
||||
return true;
|
||||
}
|
||||
|
||||
sendTeleportRequest(sender, player, args[0]);
|
||||
|
||||
@@ -18,8 +18,8 @@ public class PtpToggleCommand implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) sender;
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
|
||||
if (mcMMOPlayer.getPtpEnabled()) {
|
||||
player.sendMessage(LocaleLoader.getString("Commands.ptp.Disabled"));
|
||||
|
||||
@@ -10,7 +10,6 @@ import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.StringUtil;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
@@ -36,7 +35,7 @@ public class InspectCommand implements TabExecutor {
|
||||
|
||||
// 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) {
|
||||
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(args[0], false); // Temporary Profile
|
||||
PlayerProfile profile = new PlayerProfile(args[0], false); // Temporary Profile
|
||||
|
||||
if (CommandUtils.inspectOffline(sender, profile, Permissions.inspectOffline(sender))) {
|
||||
return true;
|
||||
@@ -70,13 +69,7 @@ public class InspectCommand implements TabExecutor {
|
||||
else {
|
||||
Player target = mcMMOPlayer.getPlayer();
|
||||
|
||||
if (CommandUtils.hidden(sender, target, Permissions.inspectHidden(sender))) {
|
||||
if (!Permissions.inspectOffline(sender)) {
|
||||
sender.sendMessage(LocaleLoader.getString("Inspect.Offline"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (CommandUtils.tooFar(sender, target, Permissions.inspectFar(sender))) {
|
||||
if (CommandUtils.tooFar(sender, target, Permissions.inspectFar(sender))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.bukkit.util.StringUtil;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
import com.gmail.nossr50.runnables.commands.McrankCommandAsyncTask;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.commands.CommandUtils;
|
||||
@@ -60,7 +61,7 @@ public class McrankCommand implements TabExecutor {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (CommandUtils.inspectOffline(sender, mcMMO.getDatabaseManager().loadPlayerProfile(playerName, false), Permissions.mcrankOffline(sender))) {
|
||||
else if (CommandUtils.inspectOffline(sender, new PlayerProfile(playerName, false), Permissions.mcrankOffline(sender))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,8 @@ public class McstatsCommand implements TabExecutor {
|
||||
|
||||
switch (args.length) {
|
||||
case 0:
|
||||
Player player = (Player) sender;
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
|
||||
if (Config.getInstance().getMcstatsScoreboardsEnabled()) {
|
||||
ScoreboardManager.setupPlayerScoreboard(player.getName());
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.gmail.nossr50.commands.player;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
@@ -11,7 +12,10 @@ import org.bukkit.util.StringUtil;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.database.FlatfileDatabaseManager;
|
||||
import com.gmail.nossr50.datatypes.database.PlayerStat;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.runnables.commands.MctopCommandAsyncTask;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.StringUtils;
|
||||
@@ -80,11 +84,39 @@ public class MctopCommand implements TabExecutor {
|
||||
ScoreboardManager.enableGlobalStatsScoreboard((Player) sender, skill, page);
|
||||
}
|
||||
else {
|
||||
display(page, skill, sender);
|
||||
if (Config.getInstance().getUseMySQL()) {
|
||||
sqlDisplay(page, skill, sender);
|
||||
}
|
||||
else {
|
||||
flatfileDisplay(page, skill, sender);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void display(int page, String query, CommandSender sender) {
|
||||
private void flatfileDisplay(int page, String skill, CommandSender sender) {
|
||||
FlatfileDatabaseManager.updateLeaderboards(); // Make sure we have the latest information
|
||||
|
||||
if (skill.equalsIgnoreCase("all")) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Leaderboard"));
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Leaderboard", StringUtils.getCapitalized(skill)));
|
||||
}
|
||||
|
||||
int position = (page * 10) - 9;
|
||||
|
||||
for (PlayerStat stat : FlatfileDatabaseManager.retrieveInfo(skill, page, 10)) {
|
||||
String digit = (position < 10) ? "0" : "" + String.valueOf(position);
|
||||
|
||||
// Format: 1. Playername - skill value
|
||||
sender.sendMessage(digit + ". " + ChatColor.GREEN + stat.name + " - " + ChatColor.WHITE + stat.statVal);
|
||||
position++;
|
||||
}
|
||||
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.mctop.Tip"));
|
||||
}
|
||||
|
||||
private void sqlDisplay(int page, String query, CommandSender sender) {
|
||||
new MctopCommandAsyncTask(page, query, sender).runTaskAsynchronously(mcMMO.p);
|
||||
}
|
||||
|
||||
|
||||
@@ -56,8 +56,8 @@ public abstract class SkillCommand implements TabExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
player = (Player) sender;
|
||||
mcMMOPlayer = UserManager.getPlayer(player);
|
||||
mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
||||
player = mcMMOPlayer.getPlayer();
|
||||
|
||||
switch (args.length) {
|
||||
case 0:
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.gmail.nossr50.commands.spout;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.spout.SpoutConfig;
|
||||
@@ -28,7 +27,7 @@ public abstract class SpoutCommand implements TabExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
playerProfile = UserManager.getPlayer((Player) sender).getProfile();
|
||||
playerProfile = UserManager.getPlayer(sender.getName()).getProfile();
|
||||
spoutHud = playerProfile.getSpoutHud();
|
||||
|
||||
if (spoutHud == null) {
|
||||
|
||||
@@ -46,6 +46,9 @@ public class Config extends AutoUpdateConfigLoader {
|
||||
public boolean getVerboseLoggingEnabled() { return config.getBoolean("General.Verbose_Logging", false); }
|
||||
public boolean getConfigOverwriteEnabled() { return config.getBoolean("General.Config_Update_Overwrite", true); }
|
||||
|
||||
public boolean getPotatoEnabled() { return config.getBoolean("General.Potato_Explosion_Enabled", false); }
|
||||
public int getPotatoChance() { return config.getInt("General.Potato_Explosion_Chance", 1); }
|
||||
|
||||
public boolean getPartyDisplayNames() { return config.getBoolean("Commands.p.Use_Display_Names", true); }
|
||||
public boolean getAdminDisplayNames() { return config.getBoolean("Commands.a.Use_Display_Names", true); }
|
||||
|
||||
@@ -290,9 +293,9 @@ public class Config extends AutoUpdateConfigLoader {
|
||||
public double getAnimalsXP() { return config.getDouble("Experience.Combat.Multiplier.Animals", 1.0); }
|
||||
public double getWitherSkeletonXP() { return config.getDouble("Experience.Combat.Multiplier.Wither_Skeleton", 4.0); }
|
||||
|
||||
public double getSpawnedMobXpMultiplier() { return config.getDouble("Experience.Gains.Mobspawners.Multiplier", 0.0); }
|
||||
public double getSpawnedMobXpMultiplier() { return config.getDouble("Experience.Gains.MobSpawners.Multiplier", 0.0); }
|
||||
|
||||
/* XP Formula Multiplier */
|
||||
public int getFormulaMultiplierCurve() { return config.getInt("Experience.Formula.Curve_Modifier", 20); }
|
||||
public double getFormulaSkillModifier(SkillType skill) { return config.getDouble("Experience.Formula.Modifier." + StringUtils.getCapitalized(skill.toString())); }
|
||||
public double getForumulaMultiplier(SkillType skill) { return config.getDouble("Experience.Formula.Modifier." + StringUtils.getCapitalized(skill.toString())); }
|
||||
}
|
||||
|
||||
49
src/main/java/com/gmail/nossr50/config/WorldConfig.java
Normal file
49
src/main/java/com/gmail/nossr50/config/WorldConfig.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package com.gmail.nossr50.config;
|
||||
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.util.StringUtils;
|
||||
|
||||
public class WorldConfig extends ConfigLoader {
|
||||
|
||||
private static WorldConfig instance;
|
||||
|
||||
public WorldConfig() {
|
||||
super("worlds.yml");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadKeys() { }
|
||||
|
||||
public static WorldConfig getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new WorldConfig();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
// World settings
|
||||
public boolean isSkillEnabled(SkillType skillType, String world) {
|
||||
String skill = StringUtils.getCapitalized(skillType.toString());
|
||||
return config.getBoolean("Worlds." + world + ".Skills." + skill + ".Enabled", isSkillEnabled(skill));
|
||||
}
|
||||
|
||||
public boolean isAbilityEnabled(SkillType skillType, String world) {
|
||||
String skill = StringUtils.getCapitalized(skillType.toString());
|
||||
return config.getBoolean("Worlds." + world + ".Skills." + skill + ".AbilityEnabled", isAbilityEnabled(skill));
|
||||
}
|
||||
|
||||
public boolean isBlockStoreEnabled(String world) { return config.getBoolean("Worlds." + world + ".BlockStore", isBlockStoreEnabled()); }
|
||||
|
||||
public boolean isMobHealthEnabled(String world) { return config.getBoolean("Worlds." + world + ".MobHealthBar", isMobHealthEnabled()); }
|
||||
|
||||
// Default settings
|
||||
private boolean isSkillEnabled(String skill) { return config.getBoolean("Default.Skills." + skill + ".Enabled", true); }
|
||||
|
||||
private boolean isAbilityEnabled(String skill) { return config.getBoolean("Default.Skills." + skill + ".AbilityEnabled", true); }
|
||||
|
||||
private boolean isBlockStoreEnabled() { return config.getBoolean("Default.BlockStore", true); }
|
||||
|
||||
private boolean isMobHealthEnabled() { return config.getBoolean("Default.MobHealthBar", true); }
|
||||
}
|
||||
@@ -442,10 +442,13 @@ public class TreasureConfig extends ConfigLoader {
|
||||
}
|
||||
|
||||
private boolean noErrorsInTreasure(List<String> issues) {
|
||||
if (issues.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (String issue : issues) {
|
||||
plugin.getLogger().warning(issue);
|
||||
}
|
||||
|
||||
return issues.isEmpty();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,89 +1,63 @@
|
||||
package com.gmail.nossr50.database;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.database.PlayerStat;
|
||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
|
||||
public interface DatabaseManager {
|
||||
// One month in milliseconds
|
||||
public final long PURGE_TIME = 2630000000L * Config.getInstance().getOldUsersCutoff();
|
||||
public class DatabaseManager {
|
||||
private final mcMMO plugin;
|
||||
private final boolean isUsingSQL;
|
||||
private File usersFile;
|
||||
|
||||
/**
|
||||
* Purge users with 0 power level from the database.
|
||||
*/
|
||||
public void purgePowerlessUsers();
|
||||
public DatabaseManager(final mcMMO plugin, final boolean isUsingSQL) {
|
||||
this.plugin = plugin;
|
||||
this.isUsingSQL = isUsingSQL;
|
||||
|
||||
/**
|
||||
* Purge users who haven't logged on in over a certain time frame from the database.
|
||||
*/
|
||||
public void purgeOldUsers();
|
||||
if (isUsingSQL) {
|
||||
SQLDatabaseManager.checkConnected();
|
||||
SQLDatabaseManager.createStructure();
|
||||
}
|
||||
else {
|
||||
usersFile = new File(mcMMO.getUsersFilePath());
|
||||
createFlatfileDatabase();
|
||||
FlatfileDatabaseManager.updateLeaderboards();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a user from the database.
|
||||
*
|
||||
* @param playerName The name of the user to remove
|
||||
* @return true if the user was successfully removed, false otherwise
|
||||
*/
|
||||
public boolean removeUser(String playerName);
|
||||
public void purgePowerlessUsers() {
|
||||
plugin.getLogger().info("Purging powerless users...");
|
||||
plugin.getLogger().info("Purged " + (isUsingSQL ? SQLDatabaseManager.purgePowerlessSQL() : FlatfileDatabaseManager.purgePowerlessFlatfile()) + " users from the database.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a user to the database.
|
||||
*
|
||||
* @param profile The profile of the player to save
|
||||
*/
|
||||
public void saveUser(PlayerProfile profile);
|
||||
public void purgeOldUsers() {
|
||||
plugin.getLogger().info("Purging old users...");
|
||||
plugin.getLogger().info("Purged " + (isUsingSQL ? SQLDatabaseManager.purgeOldSQL() : FlatfileDatabaseManager.removeOldFlatfileUsers()) + " users from the database.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve leaderboard info.
|
||||
*
|
||||
* @param skillName The skill to retrieve info on
|
||||
* @param pageNumber Which page in the leaderboards to retrieve
|
||||
* @param statsPerPage The number of stats per page
|
||||
* @return the requested leaderboard information
|
||||
*/
|
||||
public List<PlayerStat> readLeaderboard(String skillName, int pageNumber, int statsPerPage);
|
||||
public boolean removeUser(String playerName) {
|
||||
if (isUsingSQL ? SQLDatabaseManager.removeUserSQL(playerName) : FlatfileDatabaseManager.removeFlatFileUser(playerName)) {
|
||||
Misc.profileCleanup(playerName);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve rank info.
|
||||
*
|
||||
* @param playerName The name of the user to retrieve the rankings for
|
||||
* @return the requested rank information
|
||||
*/
|
||||
public Map<String, Integer> readRank(String playerName);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new user to the database.
|
||||
*
|
||||
* @param playerName The name of the player to be added to the database
|
||||
*/
|
||||
public void newUser(String playerName);
|
||||
private void createFlatfileDatabase() {
|
||||
if (usersFile.exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a player from the database.
|
||||
*
|
||||
* @param playerName The name of the player to load from the database
|
||||
* @param createNew Whether to create a new record if the player is not
|
||||
* found
|
||||
* @return The player's data, or an unloaded PlayerProfile if not found
|
||||
* and createNew is false
|
||||
*/
|
||||
public PlayerProfile loadPlayerProfile(String playerName, boolean createNew);
|
||||
usersFile.getParentFile().mkdir();
|
||||
|
||||
/**
|
||||
* Get all users currently stored in the database.
|
||||
*
|
||||
* @return list of playernames
|
||||
*/
|
||||
public List<String> getStoredUsers();
|
||||
|
||||
/**
|
||||
* Convert all users from this database to the provided database using
|
||||
* {@link #saveUser(PlayerProfile)}.
|
||||
*
|
||||
* @param the DatabaseManager to save to
|
||||
*/
|
||||
public void convertUsers(DatabaseManager destination);
|
||||
try {
|
||||
plugin.debug("Creating mcmmo.users file...");
|
||||
new File(mcMMO.getUsersFilePath()).createNewFile();
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
package com.gmail.nossr50.database;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
|
||||
public class DatabaseManagerFactory {
|
||||
private static Class<? extends DatabaseManager> customManager = null;
|
||||
|
||||
public static DatabaseManager getDatabaseManager() {
|
||||
if (customManager != null) {
|
||||
try {
|
||||
return createCustomDatabaseManager(customManager);
|
||||
} catch (Exception e) {
|
||||
mcMMO.p.debug("Could not create custom database manager");
|
||||
e.printStackTrace();
|
||||
} catch (Throwable e) {
|
||||
mcMMO.p.debug("Failed to create custom database manager");
|
||||
e.printStackTrace();
|
||||
}
|
||||
mcMMO.p.debug("Falling back on " + (Config.getInstance().getUseMySQL() ? "SQL" : "Flatfile") + " database");
|
||||
}
|
||||
return Config.getInstance().getUseMySQL() ? new SQLDatabaseManager() : new FlatfileDatabaseManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the custom DatabaseManager class for McMMO to use. This should be
|
||||
* called prior to mcMMO enabling.
|
||||
* <p>
|
||||
* The provided class must have an empty constructor, which is the one
|
||||
* that will be used.
|
||||
* <p>
|
||||
* This method is intended for API use, but it should not be considered
|
||||
* stable. This method is subject to change and/or removal in future
|
||||
* versions.
|
||||
*
|
||||
* @param man the DatabaseManager class to use
|
||||
* @throws IllegalArgumentException if the provided class does not have
|
||||
* an empty constructor
|
||||
*/
|
||||
public static void setCustomDatabaseManagerClass(Class<? extends DatabaseManager> clazz) {
|
||||
try {
|
||||
clazz.getConstructor((Class<?>) null);
|
||||
customManager = clazz;
|
||||
} catch (Throwable e) {
|
||||
throw new IllegalArgumentException("Provided database manager class must have an empty constructor", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Class<? extends DatabaseManager> getCustomDatabaseManagerClass() {
|
||||
return customManager;
|
||||
}
|
||||
|
||||
// For data conversion purposes
|
||||
|
||||
public static FlatfileDatabaseManager createFlatfileDatabaseManager() {
|
||||
return new FlatfileDatabaseManager();
|
||||
}
|
||||
|
||||
public static SQLDatabaseManager createSQLDatabaseManager() {
|
||||
return new SQLDatabaseManager();
|
||||
}
|
||||
|
||||
public static DatabaseManager createCustomDatabaseManager(Class<? extends DatabaseManager> clazz) throws Throwable {
|
||||
return customManager.getConstructor((Class<?>) null).newInstance((Object[]) null);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,6 @@
|
||||
package com.gmail.nossr50.database;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
@@ -14,448 +11,26 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.MobHealthbarType;
|
||||
import com.gmail.nossr50.datatypes.database.PlayerStat;
|
||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.skills.AbilityType;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.datatypes.spout.huds.HudType;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.StringUtils;
|
||||
|
||||
public final class FlatfileDatabaseManager implements DatabaseManager {
|
||||
private final HashMap<SkillType, List<PlayerStat>> playerStatHash = new HashMap<SkillType, List<PlayerStat>>();
|
||||
private final List<PlayerStat> powerLevels = new ArrayList<PlayerStat>();
|
||||
private long lastUpdate = 0;
|
||||
public final class FlatfileDatabaseManager {
|
||||
private static HashMap<SkillType, List<PlayerStat>> playerStatHash = new HashMap<SkillType, List<PlayerStat>>();
|
||||
private static List<PlayerStat> powerLevels = new ArrayList<PlayerStat>();
|
||||
private static long lastUpdate = 0;
|
||||
|
||||
private final long UPDATE_WAIT_TIME = 600000L; // 10 minutes
|
||||
private final File usersFile;
|
||||
private static final Object fileWritingLock = new Object();
|
||||
private static final long UPDATE_WAIT_TIME = 600000L; // 10 minutes
|
||||
private static final long ONE_MONTH = 2630000000L;
|
||||
|
||||
protected FlatfileDatabaseManager() {
|
||||
usersFile = new File(mcMMO.getUsersFilePath());
|
||||
checkStructure();
|
||||
updateLeaderboards();
|
||||
}
|
||||
|
||||
public void purgePowerlessUsers() {
|
||||
int purgedUsers = 0;
|
||||
|
||||
mcMMO.p.getLogger().info("Purging powerless users...");
|
||||
|
||||
BufferedReader in = null;
|
||||
FileWriter out = null;
|
||||
String usersFilePath = mcMMO.getUsersFilePath();
|
||||
|
||||
// This code is O(n) instead of O(n²)
|
||||
synchronized (fileWritingLock) {
|
||||
try {
|
||||
in = new BufferedReader(new FileReader(usersFilePath));
|
||||
StringBuilder writer = new StringBuilder();
|
||||
String line = "";
|
||||
|
||||
while ((line = in.readLine()) != null) {
|
||||
String[] character = line.split(":");
|
||||
Map<SkillType, Integer> skills = getSkillMapFromLine(character);
|
||||
|
||||
boolean powerless = true;
|
||||
for (int skill : skills.values()) {
|
||||
if (skill != 0) {
|
||||
powerless = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If they're still around, rewrite them to the file.
|
||||
if (!powerless) {
|
||||
writer.append(line).append("\r\n");
|
||||
}
|
||||
else {
|
||||
purgedUsers++;
|
||||
Misc.profileCleanup(character[0]);
|
||||
}
|
||||
}
|
||||
|
||||
// Write the new file
|
||||
out = new FileWriter(usersFilePath);
|
||||
out.write(writer.toString());
|
||||
}
|
||||
catch (IOException e) {
|
||||
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
|
||||
}
|
||||
finally {
|
||||
tryClose(in);
|
||||
tryClose(out);
|
||||
}
|
||||
}
|
||||
|
||||
mcMMO.p.getLogger().info("Purged " + purgedUsers + " users from the database.");
|
||||
}
|
||||
|
||||
public void purgeOldUsers() {
|
||||
int removedPlayers = 0;
|
||||
long currentTime = System.currentTimeMillis();
|
||||
|
||||
mcMMO.p.getLogger().info("Purging old users...");
|
||||
|
||||
|
||||
BufferedReader in = null;
|
||||
FileWriter out = null;
|
||||
String usersFilePath = mcMMO.getUsersFilePath();
|
||||
|
||||
// This code is O(n) instead of O(n²)
|
||||
synchronized (fileWritingLock) {
|
||||
try {
|
||||
in = new BufferedReader(new FileReader(usersFilePath));
|
||||
StringBuilder writer = new StringBuilder();
|
||||
String line = "";
|
||||
|
||||
while ((line = in.readLine()) != null) {
|
||||
String[] character = line.split(":");
|
||||
String name = character[0];
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(name);
|
||||
boolean old = true;
|
||||
if (player != null) {
|
||||
old = (currentTime - player.getLastPlayed()) > PURGE_TIME;
|
||||
}
|
||||
|
||||
if (!old) {
|
||||
writer.append(line).append("\r\n");
|
||||
}
|
||||
else {
|
||||
removedPlayers++;
|
||||
Misc.profileCleanup(name);
|
||||
}
|
||||
}
|
||||
|
||||
// Write the new file
|
||||
out = new FileWriter(usersFilePath);
|
||||
out.write(writer.toString());
|
||||
}
|
||||
catch (IOException e) {
|
||||
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
|
||||
}
|
||||
finally {
|
||||
tryClose(in);
|
||||
tryClose(out);
|
||||
}
|
||||
}
|
||||
|
||||
mcMMO.p.getLogger().info("Purged " + removedPlayers + " users from the database.");
|
||||
}
|
||||
|
||||
public boolean removeUser(String playerName) {
|
||||
boolean worked = false;
|
||||
|
||||
BufferedReader in = null;
|
||||
FileWriter out = null;
|
||||
String usersFilePath = mcMMO.getUsersFilePath();
|
||||
|
||||
synchronized (fileWritingLock) {
|
||||
try {
|
||||
in = new BufferedReader(new FileReader(usersFilePath));
|
||||
StringBuilder writer = new StringBuilder();
|
||||
String line = "";
|
||||
|
||||
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.
|
||||
if (!worked && line.split(":")[0].equalsIgnoreCase(playerName)) {
|
||||
mcMMO.p.getLogger().info("User found, removing...");
|
||||
worked = true;
|
||||
continue; // Skip the player
|
||||
}
|
||||
|
||||
writer.append(line).append("\r\n");
|
||||
}
|
||||
|
||||
out = new FileWriter(usersFilePath); // Write out the new file
|
||||
out.write(writer.toString());
|
||||
}
|
||||
catch (Exception e) {
|
||||
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
|
||||
}
|
||||
finally {
|
||||
tryClose(in);
|
||||
tryClose(out);
|
||||
}
|
||||
}
|
||||
|
||||
Misc.profileCleanup(playerName);
|
||||
|
||||
return worked;
|
||||
}
|
||||
|
||||
public void saveUser(PlayerProfile profile) {
|
||||
String playerName = profile.getPlayerName();
|
||||
|
||||
BufferedReader in = null;
|
||||
FileWriter out = null;
|
||||
String usersFilePath = mcMMO.getUsersFilePath();
|
||||
|
||||
synchronized (fileWritingLock) {
|
||||
try {
|
||||
// Open the file
|
||||
in = new BufferedReader(new FileReader(usersFilePath));
|
||||
StringBuilder writer = new StringBuilder();
|
||||
String line;
|
||||
|
||||
// While not at the end of the file
|
||||
while ((line = in.readLine()) != null) {
|
||||
// Read the line in and copy it to the output it's not the player we want to edit
|
||||
if (!line.split(":")[0].equalsIgnoreCase(playerName)) {
|
||||
writer.append(line).append("\r\n");
|
||||
}
|
||||
else {
|
||||
// Otherwise write the new player information
|
||||
writer.append(playerName).append(":");
|
||||
writer.append(profile.getSkillLevel(SkillType.MINING)).append(":");
|
||||
writer.append(":");
|
||||
writer.append(":");
|
||||
writer.append(profile.getSkillXpLevel(SkillType.MINING)).append(":");
|
||||
writer.append(profile.getSkillLevel(SkillType.WOODCUTTING)).append(":");
|
||||
writer.append(profile.getSkillXpLevel(SkillType.WOODCUTTING)).append(":");
|
||||
writer.append(profile.getSkillLevel(SkillType.REPAIR)).append(":");
|
||||
writer.append(profile.getSkillLevel(SkillType.UNARMED)).append(":");
|
||||
writer.append(profile.getSkillLevel(SkillType.HERBALISM)).append(":");
|
||||
writer.append(profile.getSkillLevel(SkillType.EXCAVATION)).append(":");
|
||||
writer.append(profile.getSkillLevel(SkillType.ARCHERY)).append(":");
|
||||
writer.append(profile.getSkillLevel(SkillType.SWORDS)).append(":");
|
||||
writer.append(profile.getSkillLevel(SkillType.AXES)).append(":");
|
||||
writer.append(profile.getSkillLevel(SkillType.ACROBATICS)).append(":");
|
||||
writer.append(profile.getSkillXpLevel(SkillType.REPAIR)).append(":");
|
||||
writer.append(profile.getSkillXpLevel(SkillType.UNARMED)).append(":");
|
||||
writer.append(profile.getSkillXpLevel(SkillType.HERBALISM)).append(":");
|
||||
writer.append(profile.getSkillXpLevel(SkillType.EXCAVATION)).append(":");
|
||||
writer.append(profile.getSkillXpLevel(SkillType.ARCHERY)).append(":");
|
||||
writer.append(profile.getSkillXpLevel(SkillType.SWORDS)).append(":");
|
||||
writer.append(profile.getSkillXpLevel(SkillType.AXES)).append(":");
|
||||
writer.append(profile.getSkillXpLevel(SkillType.ACROBATICS)).append(":");
|
||||
writer.append(":");
|
||||
writer.append(profile.getSkillLevel(SkillType.TAMING)).append(":");
|
||||
writer.append(profile.getSkillXpLevel(SkillType.TAMING)).append(":");
|
||||
writer.append((int) profile.getSkillDATS(AbilityType.BERSERK)).append(":");
|
||||
writer.append((int) profile.getSkillDATS(AbilityType.GIGA_DRILL_BREAKER)).append(":");
|
||||
writer.append((int) profile.getSkillDATS(AbilityType.TREE_FELLER)).append(":");
|
||||
writer.append((int) profile.getSkillDATS(AbilityType.GREEN_TERRA)).append(":");
|
||||
writer.append((int) profile.getSkillDATS(AbilityType.SERRATED_STRIKES)).append(":");
|
||||
writer.append((int) profile.getSkillDATS(AbilityType.SKULL_SPLITTER)).append(":");
|
||||
writer.append((int) profile.getSkillDATS(AbilityType.SUPER_BREAKER)).append(":");
|
||||
HudType hudType = profile.getHudType();
|
||||
writer.append(hudType == null ? "STANDARD" : hudType.toString()).append(":");
|
||||
writer.append(profile.getSkillLevel(SkillType.FISHING)).append(":");
|
||||
writer.append(profile.getSkillXpLevel(SkillType.FISHING)).append(":");
|
||||
writer.append((int) profile.getSkillDATS(AbilityType.BLAST_MINING)).append(":");
|
||||
writer.append(System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR).append(":");
|
||||
MobHealthbarType mobHealthbarType = profile.getMobHealthbarType();
|
||||
writer.append(mobHealthbarType == null ? Config.getInstance().getMobHealthbarDefault().toString() : mobHealthbarType.toString()).append(":");
|
||||
writer.append("\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
// Write the new file
|
||||
out = new FileWriter(usersFilePath);
|
||||
out.write(writer.toString());
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally {
|
||||
tryClose(in);
|
||||
tryClose(out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<PlayerStat> readLeaderboard(String skillName, int pageNumber, int statsPerPage) {
|
||||
updateLeaderboards();
|
||||
List<PlayerStat> statsList = skillName.equalsIgnoreCase("all") ? powerLevels : playerStatHash.get(SkillType.getSkill(skillName));
|
||||
int fromIndex = (Math.max(pageNumber, 1) - 1) * statsPerPage;
|
||||
|
||||
return statsList.subList(Math.min(fromIndex, statsList.size()), Math.min(fromIndex + statsPerPage, statsList.size()));
|
||||
}
|
||||
|
||||
public Map<String, Integer> readRank(String playerName) {
|
||||
updateLeaderboards();
|
||||
|
||||
Map<String, Integer> skills = new HashMap<String, Integer>();
|
||||
|
||||
for (SkillType skill : SkillType.nonChildSkills()) {
|
||||
skills.put(skill.name(), getPlayerRank(playerName, playerStatHash.get(skill)));
|
||||
}
|
||||
|
||||
skills.put("ALL", getPlayerRank(playerName, powerLevels));
|
||||
|
||||
return skills;
|
||||
}
|
||||
|
||||
public void newUser(String playerName) {
|
||||
BufferedWriter out = null;
|
||||
synchronized (fileWritingLock) {
|
||||
try {
|
||||
// Open the file to write the player
|
||||
out = new BufferedWriter(new FileWriter(mcMMO.getUsersFilePath(), true));
|
||||
|
||||
// Add the player to the end
|
||||
out.append(playerName).append(":");
|
||||
out.append("0:"); // Mining
|
||||
out.append(":");
|
||||
out.append(":");
|
||||
out.append("0:"); // Xp
|
||||
out.append("0:"); // Woodcutting
|
||||
out.append("0:"); // WoodCuttingXp
|
||||
out.append("0:"); // Repair
|
||||
out.append("0:"); // Unarmed
|
||||
out.append("0:"); // Herbalism
|
||||
out.append("0:"); // Excavation
|
||||
out.append("0:"); // Archery
|
||||
out.append("0:"); // Swords
|
||||
out.append("0:"); // Axes
|
||||
out.append("0:"); // Acrobatics
|
||||
out.append("0:"); // RepairXp
|
||||
out.append("0:"); // UnarmedXp
|
||||
out.append("0:"); // HerbalismXp
|
||||
out.append("0:"); // ExcavationXp
|
||||
out.append("0:"); // ArcheryXp
|
||||
out.append("0:"); // SwordsXp
|
||||
out.append("0:"); // AxesXp
|
||||
out.append("0:"); // AcrobaticsXp
|
||||
out.append(":");
|
||||
out.append("0:"); // Taming
|
||||
out.append("0:"); // TamingXp
|
||||
out.append("0:"); // DATS
|
||||
out.append("0:"); // DATS
|
||||
out.append("0:"); // DATS
|
||||
out.append("0:"); // DATS
|
||||
out.append("0:"); // DATS
|
||||
out.append("0:"); // DATS
|
||||
out.append("0:"); // DATS
|
||||
out.append("STANDARD").append(":"); // HUD
|
||||
out.append("0:"); // Fishing
|
||||
out.append("0:"); // FishingXp
|
||||
out.append("0:"); // Blast Mining
|
||||
out.append(String.valueOf(System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR)).append(":"); // LastLogin
|
||||
out.append(Config.getInstance().getMobHealthbarDefault().toString()).append(":"); // Mob Healthbar HUD
|
||||
|
||||
// Add more in the same format as the line above
|
||||
|
||||
out.newLine();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally {
|
||||
tryClose(out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public PlayerProfile loadPlayerProfile(String playerName, boolean create) {
|
||||
BufferedReader in = null;
|
||||
String usersFilePath = mcMMO.getUsersFilePath();
|
||||
|
||||
synchronized (fileWritingLock) {
|
||||
try {
|
||||
// Open the user file
|
||||
in = new BufferedReader(new FileReader(usersFilePath));
|
||||
String line;
|
||||
|
||||
while ((line = in.readLine()) != null) {
|
||||
// Find if the line contains the player we want.
|
||||
String[] character = line.split(":");
|
||||
|
||||
if (!character[0].equalsIgnoreCase(playerName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
PlayerProfile p = loadFromLine(character);
|
||||
in.close();
|
||||
return p;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally {
|
||||
tryClose(in);
|
||||
}
|
||||
}
|
||||
|
||||
if (create) {
|
||||
newUser(playerName);
|
||||
return new PlayerProfile(playerName, true);
|
||||
}
|
||||
return new PlayerProfile(playerName);
|
||||
}
|
||||
|
||||
public void convertUsers(DatabaseManager destination) {
|
||||
BufferedReader in = null;
|
||||
String usersFilePath = mcMMO.getUsersFilePath();
|
||||
|
||||
synchronized (fileWritingLock) {
|
||||
try {
|
||||
// Open the user file
|
||||
in = new BufferedReader(new FileReader(usersFilePath));
|
||||
String line;
|
||||
|
||||
while ((line = in.readLine()) != null) {
|
||||
String[] character = line.split(":");
|
||||
|
||||
try {
|
||||
destination.saveUser(loadFromLine(character));
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally {
|
||||
tryClose(in);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean checkConnected() {
|
||||
// Not implemented
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<String> getStoredUsers() {
|
||||
ArrayList<String> users = new ArrayList<String>();
|
||||
BufferedReader in = null;
|
||||
String usersFilePath = mcMMO.getUsersFilePath();
|
||||
|
||||
synchronized (fileWritingLock) {
|
||||
try {
|
||||
// Open the user file
|
||||
in = new BufferedReader(new FileReader(usersFilePath));
|
||||
String line;
|
||||
|
||||
while ((line = in.readLine()) != null) {
|
||||
String[] character = line.split(":");
|
||||
users.add(character[0]);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally {
|
||||
tryClose(in);
|
||||
}
|
||||
}
|
||||
return users;
|
||||
}
|
||||
private FlatfileDatabaseManager() {}
|
||||
|
||||
/**
|
||||
* Update the leader boards.
|
||||
*/
|
||||
private void updateLeaderboards() {
|
||||
public static void updateLeaderboards() {
|
||||
// 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;
|
||||
@@ -466,63 +41,57 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
||||
powerLevels.clear(); // Clear old values from the power levels
|
||||
|
||||
// Initialize lists
|
||||
List<PlayerStat> mining = new ArrayList<PlayerStat>();
|
||||
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>();
|
||||
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>();
|
||||
|
||||
BufferedReader in = null;
|
||||
// Read from the FlatFile database and fill our arrays with information
|
||||
synchronized (fileWritingLock) {
|
||||
try {
|
||||
in = new BufferedReader(new FileReader(usersFilePath));
|
||||
String line = "";
|
||||
ArrayList<String> players = new ArrayList<String>();
|
||||
try {
|
||||
BufferedReader in = new BufferedReader(new FileReader(usersFilePath));
|
||||
String line = "";
|
||||
ArrayList<String> players = new ArrayList<String>();
|
||||
|
||||
while ((line = in.readLine()) != null) {
|
||||
String[] data = line.split(":");
|
||||
String playerName = data[0];
|
||||
int powerLevel = 0;
|
||||
while ((line = in.readLine()) != null) {
|
||||
String[] data = line.split(":");
|
||||
|
||||
// Prevent the same player from being added multiple times (I'd like to note that this shouldn't happen...)
|
||||
if (players.contains(playerName)) {
|
||||
continue;
|
||||
}
|
||||
String playerName = data[0];
|
||||
int powerLevel = 0;
|
||||
|
||||
players.add(playerName);
|
||||
|
||||
Map<SkillType, Integer> skills = getSkillMapFromLine(data);
|
||||
|
||||
powerLevel += putStat(acrobatics, playerName, skills.get(SkillType.ACROBATICS));
|
||||
powerLevel += putStat(archery, playerName, skills.get(SkillType.ARCHERY));
|
||||
powerLevel += putStat(axes, playerName, skills.get(SkillType.AXES));
|
||||
powerLevel += putStat(excavation, playerName, skills.get(SkillType.EXCAVATION));
|
||||
powerLevel += putStat(fishing, playerName, skills.get(SkillType.FISHING));
|
||||
powerLevel += putStat(herbalism, playerName, skills.get(SkillType.HERBALISM));
|
||||
powerLevel += putStat(mining, playerName, skills.get(SkillType.MINING));
|
||||
powerLevel += putStat(repair, playerName, skills.get(SkillType.REPAIR));
|
||||
powerLevel += putStat(swords, playerName, skills.get(SkillType.SWORDS));
|
||||
powerLevel += putStat(taming, playerName, skills.get(SkillType.TAMING));
|
||||
powerLevel += putStat(unarmed, playerName, skills.get(SkillType.UNARMED));
|
||||
powerLevel += putStat(woodcutting, playerName, skills.get(SkillType.WOODCUTTING));
|
||||
|
||||
putStat(powerLevels, playerName, powerLevel);
|
||||
// Prevent the same player from being added multiple times (I'd like to note that this shouldn't happen...)
|
||||
if (players.contains(playerName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
players.add(playerName);
|
||||
|
||||
powerLevel += loadStat(mining, playerName, data, 1);
|
||||
powerLevel += loadStat(woodcutting, playerName, data, 5);
|
||||
powerLevel += loadStat(repair, playerName, data, 7);
|
||||
powerLevel += loadStat(unarmed, playerName, data, 8);
|
||||
powerLevel += loadStat(herbalism, playerName, data, 9);
|
||||
powerLevel += loadStat(excavation, playerName, data, 10);
|
||||
powerLevel += loadStat(archery, playerName, data, 11);
|
||||
powerLevel += loadStat(swords, playerName, data, 12);
|
||||
powerLevel += loadStat(axes, playerName, data, 13);
|
||||
powerLevel += loadStat(acrobatics, playerName, data, 14);
|
||||
powerLevel += loadStat(taming, playerName, data, 24);
|
||||
powerLevel += loadStat(fishing, playerName, data, 34);
|
||||
|
||||
powerLevels.add(new PlayerStat(playerName, powerLevel));
|
||||
}
|
||||
catch (Exception e) {
|
||||
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
|
||||
}
|
||||
finally {
|
||||
tryClose(in);
|
||||
}
|
||||
in.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
|
||||
}
|
||||
|
||||
SkillComparator c = new SkillComparator();
|
||||
@@ -556,73 +125,159 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that the file is present and valid
|
||||
* Retrieve leaderboard info.
|
||||
*
|
||||
* @param skillType Skill to retrieve info on.
|
||||
* @param pageNumber Which page in the leaderboards to retrieve
|
||||
* @return the requested leaderboard information
|
||||
*/
|
||||
private void checkStructure() {
|
||||
if (usersFile.exists()) {
|
||||
BufferedReader in = null;
|
||||
FileWriter out = null;
|
||||
String usersFilePath = mcMMO.getUsersFilePath();
|
||||
public static List<PlayerStat> retrieveInfo(String skillType, int pageNumber, int statsPerPage) {
|
||||
List<PlayerStat> statsList = skillType.equalsIgnoreCase("all") ? powerLevels : playerStatHash.get(SkillType.getSkill(skillType));
|
||||
int fromIndex = (Math.max(pageNumber, 1) - 1) * statsPerPage;
|
||||
|
||||
synchronized (fileWritingLock) {
|
||||
try {
|
||||
in = new BufferedReader(new FileReader(usersFilePath));
|
||||
StringBuilder writer = new StringBuilder();
|
||||
String line = "";
|
||||
return statsList.subList(Math.min(fromIndex, statsList.size()), Math.min(fromIndex + statsPerPage, statsList.size()));
|
||||
}
|
||||
|
||||
while ((line = in.readLine()) != null) {
|
||||
String[] character = line.split(":");
|
||||
public static boolean removeFlatFileUser(String playerName) {
|
||||
boolean worked = false;
|
||||
|
||||
// If they're valid, rewrite them to the file.
|
||||
if (character.length >= 37) {
|
||||
writer.append(line).append("\r\n");
|
||||
} else {
|
||||
// Placeholder, repair row if needed (I.E. when new skills are added and such)
|
||||
}
|
||||
}
|
||||
BufferedReader in = null;
|
||||
FileWriter out = null;
|
||||
String usersFilePath = mcMMO.getUsersFilePath();
|
||||
|
||||
// Write the new file
|
||||
out = new FileWriter(usersFilePath);
|
||||
out.write(writer.toString());
|
||||
try {
|
||||
FileReader file = new FileReader(usersFilePath);
|
||||
in = new BufferedReader(file);
|
||||
StringBuilder writer = new StringBuilder();
|
||||
String line = "";
|
||||
|
||||
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.
|
||||
if (!line.split(":")[0].equalsIgnoreCase(playerName)) {
|
||||
writer.append(line).append("\r\n");
|
||||
}
|
||||
catch (IOException e) {
|
||||
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
|
||||
}
|
||||
finally {
|
||||
tryClose(in);
|
||||
tryClose(out);
|
||||
else {
|
||||
mcMMO.p.getLogger().info("User found, removing...");
|
||||
worked = true;
|
||||
continue; // Skip the player
|
||||
}
|
||||
}
|
||||
|
||||
out = new FileWriter(usersFilePath); // Write out the new file
|
||||
out.write(writer.toString());
|
||||
}
|
||||
catch (Exception e) {
|
||||
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
|
||||
}
|
||||
finally {
|
||||
if (in != null) {
|
||||
try {
|
||||
in.close();
|
||||
}
|
||||
catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (out != null) {
|
||||
try {
|
||||
out.close();
|
||||
}
|
||||
catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
usersFile.getParentFile().mkdir();
|
||||
|
||||
try {
|
||||
mcMMO.p.debug("Creating mcmmo.users file...");
|
||||
new File(mcMMO.getUsersFilePath()).createNewFile();
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return worked;
|
||||
}
|
||||
|
||||
private void tryClose(Closeable c) {
|
||||
if (c == null) return;
|
||||
try {
|
||||
c.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
public static int purgePowerlessFlatfile() {
|
||||
mcMMO.p.getLogger().info("Purging powerless users...");
|
||||
|
||||
int purgedUsers = 0;
|
||||
|
||||
for (PlayerStat stat : powerLevels) {
|
||||
if (stat.statVal == 0 && !mcMMO.p.getServer().getOfflinePlayer(stat.name).isOnline() && removeFlatFileUser(stat.name)) {
|
||||
purgedUsers++;
|
||||
}
|
||||
}
|
||||
|
||||
return purgedUsers;
|
||||
}
|
||||
|
||||
private Integer getPlayerRank(String playerName, List<PlayerStat> statsList) {
|
||||
public static int removeOldFlatfileUsers() {
|
||||
int removedPlayers = 0;
|
||||
long currentTime = System.currentTimeMillis();
|
||||
long purgeTime = ONE_MONTH * Config.getInstance().getOldUsersCutoff();
|
||||
|
||||
BufferedReader in = null;
|
||||
FileWriter out = null;
|
||||
String usersFilePath = mcMMO.getUsersFilePath();
|
||||
|
||||
try {
|
||||
FileReader file = new FileReader(usersFilePath);
|
||||
in = new BufferedReader(file);
|
||||
StringBuilder writer = new StringBuilder();
|
||||
String line = "";
|
||||
|
||||
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.
|
||||
String[] splitLine = line.split(":");
|
||||
|
||||
if (splitLine.length > 37) {
|
||||
if (currentTime - (StringUtils.getLong(line.split(":")[37]) * 1000) <= purgeTime) {
|
||||
writer.append(line).append("\r\n");
|
||||
}
|
||||
else {
|
||||
mcMMO.p.getLogger().info("User found, removing...");
|
||||
removedPlayers++;
|
||||
continue; // Skip the player
|
||||
}
|
||||
}
|
||||
else {
|
||||
writer.append(line).append("\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
out = new FileWriter(usersFilePath); // Write out the new file
|
||||
out.write(writer.toString());
|
||||
}
|
||||
catch (Exception e) {
|
||||
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
|
||||
}
|
||||
finally {
|
||||
if (in != null) {
|
||||
try {
|
||||
in.close();
|
||||
}
|
||||
catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (out != null) {
|
||||
try {
|
||||
out.close();
|
||||
}
|
||||
catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return removedPlayers;
|
||||
}
|
||||
|
||||
private static Integer getPlayerRank(String playerName, List<PlayerStat> statsList) {
|
||||
int currentPos = 1;
|
||||
|
||||
if (statsList == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int currentPos = 1;
|
||||
|
||||
for (PlayerStat stat : statsList) {
|
||||
if (stat.name.equalsIgnoreCase(playerName)) {
|
||||
return currentPos;
|
||||
@@ -634,86 +289,43 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
private int putStat(List<PlayerStat> statList, String playerName, int statValue) {
|
||||
statList.add(new PlayerStat(playerName, statValue));
|
||||
return statValue;
|
||||
public static Map<String, Integer> getPlayerRanks(String playerName) {
|
||||
updateLeaderboards();
|
||||
|
||||
Map<String, Integer> skills = new HashMap<String, Integer>();
|
||||
|
||||
for (SkillType skill : SkillType.values()) {
|
||||
if (skill.isChildSkill()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
skills.put(skill.name(), getPlayerRank(playerName, playerStatHash.get(skill)));
|
||||
}
|
||||
|
||||
skills.put("ALL", getPlayerRank(playerName, powerLevels));
|
||||
|
||||
return skills;
|
||||
}
|
||||
|
||||
private class SkillComparator implements Comparator<PlayerStat> {
|
||||
public static List<PlayerStat> getPlayerStats(String skillName) {
|
||||
return (skillName.equalsIgnoreCase("all")) ? powerLevels : playerStatHash.get(SkillType.getSkill(skillName));
|
||||
}
|
||||
|
||||
private static int loadStat(List<PlayerStat> statList, String playerName, String[] data, int dataIndex) {
|
||||
if (data.length > dataIndex) {
|
||||
int statValue = Integer.parseInt(data[dataIndex]);
|
||||
|
||||
statList.add(new PlayerStat(playerName, statValue));
|
||||
return statValue;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static class SkillComparator implements Comparator<PlayerStat> {
|
||||
@Override
|
||||
public int compare(PlayerStat o1, PlayerStat o2) {
|
||||
return (o2.statVal - o1.statVal);
|
||||
}
|
||||
}
|
||||
|
||||
private PlayerProfile loadFromLine(String[] character) throws Exception {
|
||||
Map<SkillType, Integer> skills = getSkillMapFromLine(character); // Skill levels
|
||||
Map<SkillType, Float> skillsXp = new HashMap<SkillType, Float>(); // Skill & XP
|
||||
Map<AbilityType, Integer> skillsDATS = new HashMap<AbilityType, Integer>(); // Ability & Cooldown
|
||||
HudType hudType;
|
||||
MobHealthbarType mobHealthbarType;
|
||||
|
||||
// TODO on updates, put new values in a try{} ?
|
||||
|
||||
skillsXp.put(SkillType.TAMING, (float) Integer.valueOf(character[25]));
|
||||
skillsXp.put(SkillType.MINING, (float) Integer.valueOf(character[4]));
|
||||
skillsXp.put(SkillType.REPAIR, (float) Integer.valueOf(character[15]));
|
||||
skillsXp.put(SkillType.WOODCUTTING, (float) Integer.valueOf(character[6]));
|
||||
skillsXp.put(SkillType.UNARMED, (float) Integer.valueOf(character[16]));
|
||||
skillsXp.put(SkillType.HERBALISM, (float) Integer.valueOf(character[17]));
|
||||
skillsXp.put(SkillType.EXCAVATION, (float) Integer.valueOf(character[18]));
|
||||
skillsXp.put(SkillType.ARCHERY, (float) Integer.valueOf(character[19]));
|
||||
skillsXp.put(SkillType.SWORDS, (float) Integer.valueOf(character[20]));
|
||||
skillsXp.put(SkillType.AXES, (float) Integer.valueOf(character[21]));
|
||||
skillsXp.put(SkillType.ACROBATICS, (float) Integer.valueOf(character[22]));
|
||||
skillsXp.put(SkillType.FISHING, (float) Integer.valueOf(character[35]));
|
||||
|
||||
// Taming - Unused
|
||||
skillsDATS.put(AbilityType.SUPER_BREAKER, Integer.valueOf(character[32]));
|
||||
// Repair - Unused
|
||||
skillsDATS.put(AbilityType.TREE_FELLER, Integer.valueOf(character[28]));
|
||||
skillsDATS.put(AbilityType.BERSERK, Integer.valueOf(character[26]));
|
||||
skillsDATS.put(AbilityType.GREEN_TERRA, Integer.valueOf(character[29]));
|
||||
skillsDATS.put(AbilityType.GIGA_DRILL_BREAKER, Integer.valueOf(character[27]));
|
||||
// Archery - Unused
|
||||
skillsDATS.put(AbilityType.SERRATED_STRIKES, Integer.valueOf(character[30]));
|
||||
skillsDATS.put(AbilityType.SKULL_SPLITTER, Integer.valueOf(character[31]));
|
||||
// Acrobatics - Unused
|
||||
skillsDATS.put(AbilityType.BLAST_MINING, Integer.valueOf(character[36]));
|
||||
|
||||
try {
|
||||
hudType = HudType.valueOf(character[33]);
|
||||
}
|
||||
catch (Exception e) {
|
||||
hudType = HudType.STANDARD; // Shouldn't happen unless database is being tampered with
|
||||
}
|
||||
|
||||
try {
|
||||
mobHealthbarType = MobHealthbarType.valueOf(character[38]);
|
||||
}
|
||||
catch (Exception e) {
|
||||
mobHealthbarType = Config.getInstance().getMobHealthbarDefault();
|
||||
}
|
||||
|
||||
return new PlayerProfile(character[0], skills, skillsXp, skillsDATS, hudType, mobHealthbarType);
|
||||
}
|
||||
|
||||
private Map<SkillType, Integer> getSkillMapFromLine(String[] character) {
|
||||
Map<SkillType, Integer> skills = new HashMap<SkillType, Integer>(); // Skill & Level
|
||||
|
||||
skills.put(SkillType.TAMING, Integer.valueOf(character[24]));
|
||||
skills.put(SkillType.MINING, Integer.valueOf(character[1]));
|
||||
skills.put(SkillType.REPAIR, Integer.valueOf(character[7]));
|
||||
skills.put(SkillType.WOODCUTTING, Integer.valueOf(character[5]));
|
||||
skills.put(SkillType.UNARMED, Integer.valueOf(character[8]));
|
||||
skills.put(SkillType.HERBALISM, Integer.valueOf(character[9]));
|
||||
skills.put(SkillType.EXCAVATION, Integer.valueOf(character[10]));
|
||||
skills.put(SkillType.ARCHERY, Integer.valueOf(character[11]));
|
||||
skills.put(SkillType.SWORDS, Integer.valueOf(character[12]));
|
||||
skills.put(SkillType.AXES, Integer.valueOf(character[13]));
|
||||
skills.put(SkillType.ACROBATICS, Integer.valueOf(character[14]));
|
||||
skills.put(SkillType.FISHING, Integer.valueOf(character[34]));
|
||||
|
||||
return skills;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
@@ -11,8 +12,7 @@ import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.party.ShareHandler.ShareMode;
|
||||
|
||||
public class Party {
|
||||
private final LinkedHashSet<String> members = new LinkedHashSet<String>();
|
||||
|
||||
private LinkedHashSet<String> members = new LinkedHashSet<String>();
|
||||
private String leader;
|
||||
private String name;
|
||||
private String password;
|
||||
@@ -27,30 +27,6 @@ public class Party {
|
||||
private boolean shareWoodcuttingDrops = true;
|
||||
private boolean shareMiscDrops = true;
|
||||
|
||||
public Party(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Party(String leader, String name) {
|
||||
this.leader = leader;
|
||||
this.name = name;
|
||||
this.locked = true;
|
||||
}
|
||||
|
||||
public Party(String leader, String name, String password) {
|
||||
this.leader = leader;
|
||||
this.name = name;
|
||||
this.password = password;
|
||||
this.locked = true;
|
||||
}
|
||||
|
||||
public Party(String leader, String name, String password, boolean locked) {
|
||||
this.leader = leader;
|
||||
this.name = name;
|
||||
this.password = password;
|
||||
this.locked = locked;
|
||||
}
|
||||
|
||||
public LinkedHashSet<String> getMembers() {
|
||||
return members;
|
||||
}
|
||||
@@ -59,10 +35,9 @@ public class Party {
|
||||
List<Player> onlineMembers = new ArrayList<Player>();
|
||||
|
||||
for (String memberName : members) {
|
||||
Player member = mcMMO.p.getServer().getPlayerExact(memberName);
|
||||
|
||||
if (member != null) {
|
||||
onlineMembers.add(member);
|
||||
OfflinePlayer member = mcMMO.p.getServer().getOfflinePlayer(memberName);
|
||||
if (member.isOnline()) {
|
||||
onlineMembers.add(member.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,28 +166,4 @@ public class Party {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(obj instanceof Party)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Party other = (Party) obj;
|
||||
|
||||
if ((this.getName() == null) || (other.getName() == null)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.getName().equals(other.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return super.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.util.Set;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
@@ -53,7 +54,7 @@ public class McMMOPlayer {
|
||||
* we make sure that all class inheriting from SkillManager are instanced.
|
||||
* Which solution is better, I let you decide. - bm01
|
||||
*/
|
||||
private final Map<SkillType, SkillManager> skillManagers = new HashMap<SkillType, SkillManager>();
|
||||
private Map<SkillType, SkillManager> skillManagers = new HashMap<SkillType, SkillManager>();
|
||||
|
||||
private Party party;
|
||||
private Party invite;
|
||||
@@ -75,11 +76,11 @@ public class McMMOPlayer {
|
||||
private int lastSalvageClick;
|
||||
private boolean godMode;
|
||||
|
||||
private final Map<AbilityType, Boolean> abilityMode = new HashMap<AbilityType, Boolean>();
|
||||
private final Map<AbilityType, Boolean> abilityInformed = new HashMap<AbilityType, Boolean>();
|
||||
private Map<AbilityType, Boolean> abilityMode = new HashMap<AbilityType, Boolean>();
|
||||
private Map<AbilityType, Boolean> abilityInformed = new HashMap<AbilityType, Boolean>();
|
||||
|
||||
private final Map<ToolType, Boolean> toolMode = new HashMap<ToolType, Boolean>();
|
||||
private final Map<ToolType, Integer> toolATS = new HashMap<ToolType, Integer>();
|
||||
private Map<ToolType, Boolean> toolMode = new HashMap<ToolType, Boolean>();
|
||||
private Map<ToolType, Integer> toolATS = new HashMap<ToolType, Integer>();
|
||||
|
||||
private int recentlyHurt;
|
||||
private int respawnATS;
|
||||
@@ -89,17 +90,13 @@ public class McMMOPlayer {
|
||||
private boolean isUsingUnarmed;
|
||||
|
||||
public McMMOPlayer(Player player) {
|
||||
this(player, mcMMO.getDatabaseManager().loadPlayerProfile(player.getName(), true));
|
||||
}
|
||||
|
||||
public McMMOPlayer(Player player, PlayerProfile profile) {
|
||||
String playerName = player.getName();
|
||||
|
||||
this.player = player;
|
||||
this.profile = profile;
|
||||
profile = new PlayerProfile(playerName, true);
|
||||
party = PartyManager.getPlayerParty(playerName);
|
||||
|
||||
/*
|
||||
/*
|
||||
* I'm using this method because it makes code shorter and safer (we don't have to add all SkillTypes manually),
|
||||
* but I actually have no idea about the performance impact, if there is any.
|
||||
* If in the future someone wants to remove this, don't forget to also remove what is in the SkillType enum. - bm01
|
||||
@@ -205,10 +202,10 @@ public class McMMOPlayer {
|
||||
* Set the mode of an ability.
|
||||
*
|
||||
* @param ability The ability to check
|
||||
* @param isActive True if the ability is active, false otherwise
|
||||
* @param bool True if the ability is active, false otherwise
|
||||
*/
|
||||
public void setAbilityMode(AbilityType ability, boolean isActive) {
|
||||
abilityMode.put(ability, isActive);
|
||||
public void setAbilityMode(AbilityType ability, boolean bool) {
|
||||
abilityMode.put(ability, bool);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -225,10 +222,10 @@ public class McMMOPlayer {
|
||||
* Set the informed state of an ability.
|
||||
*
|
||||
* @param ability The ability to check
|
||||
* @param isInformed True if the ability is informed, false otherwise
|
||||
* @param bool True if the ability is informed, false otherwise
|
||||
*/
|
||||
public void setAbilityInformed(AbilityType ability, boolean isInformed) {
|
||||
abilityInformed.put(ability, isInformed);
|
||||
public void setAbilityInformed(AbilityType ability, boolean bool) {
|
||||
abilityInformed.put(ability, bool);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -266,10 +263,10 @@ public class McMMOPlayer {
|
||||
* Set the current prep mode of a tool.
|
||||
*
|
||||
* @param tool Tool to set the mode for
|
||||
* @param isPrepared true if the tool should be prepped, false otherwise
|
||||
* @param bool true if the tool should be prepped, false otherwise
|
||||
*/
|
||||
public void setToolPreparationMode(ToolType tool, boolean isPrepared) {
|
||||
toolMode.put(tool, isPrepared);
|
||||
public void setToolPreparationMode(ToolType tool, boolean bool) {
|
||||
toolMode.put(tool, bool);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -335,7 +332,7 @@ public class McMMOPlayer {
|
||||
}
|
||||
|
||||
public void actualizeTeleportCommenceLocation(Player player) {
|
||||
teleportCommence = player.getLocation();
|
||||
setTeleportCommenceLocation(player.getLocation());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -444,7 +441,11 @@ public class McMMOPlayer {
|
||||
public int getPowerLevel() {
|
||||
int powerLevel = 0;
|
||||
|
||||
for (SkillType type : SkillType.nonChildSkills()) {
|
||||
for (SkillType type : SkillType.values()) {
|
||||
if (type.isChildSkill()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Permissions.skillEnabled(player, type)) {
|
||||
powerLevel += profile.getSkillLevel(type);
|
||||
}
|
||||
@@ -503,10 +504,6 @@ public class McMMOPlayer {
|
||||
* @param xp Experience amount to add
|
||||
*/
|
||||
public void applyXpGain(SkillType skillType, float xp) {
|
||||
if (!Permissions.skillEnabled(player, skillType)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (skillType.isChildSkill()) {
|
||||
Set<SkillType> parentSkills = FamilyTree.getParents(skillType);
|
||||
|
||||
@@ -517,6 +514,10 @@ public class McMMOPlayer {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Permissions.skillEnabled(player, skillType)) {
|
||||
return;
|
||||
}
|
||||
|
||||
McMMOPlayerXpGainEvent event = new McMMOPlayerXpGainEvent(player, skillType, xp);
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
@@ -532,7 +533,7 @@ public class McMMOPlayer {
|
||||
spoutHud.setLastGained(skillType);
|
||||
}
|
||||
|
||||
isUsingUnarmed = (skillType == SkillType.UNARMED);
|
||||
isUsingUnarmed = skillType == SkillType.UNARMED;
|
||||
SkillUtils.xpCheckSkill(skillType, player, profile);
|
||||
}
|
||||
|
||||
@@ -565,7 +566,11 @@ public class McMMOPlayer {
|
||||
}
|
||||
|
||||
public boolean hasPartyInvite() {
|
||||
return (invite != null);
|
||||
if (invite != null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setParty(Party party) {
|
||||
@@ -577,7 +582,11 @@ public class McMMOPlayer {
|
||||
}
|
||||
|
||||
public boolean inParty() {
|
||||
return (party != null);
|
||||
if (party != null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void removeParty() {
|
||||
@@ -605,7 +614,11 @@ public class McMMOPlayer {
|
||||
}
|
||||
|
||||
public boolean hasPtpRequest() {
|
||||
return (ptpRequest != null);
|
||||
if (ptpRequest != null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void removePtpRequest() {
|
||||
@@ -637,7 +650,11 @@ public class McMMOPlayer {
|
||||
}
|
||||
|
||||
public void setItemShareModifier(int modifier) {
|
||||
itemShareModifier = Math.max(10, modifier);
|
||||
if (modifier < 10) {
|
||||
modifier = 10;
|
||||
}
|
||||
|
||||
itemShareModifier = modifier;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -680,14 +697,15 @@ public class McMMOPlayer {
|
||||
* @return Modified experience
|
||||
*/
|
||||
private float modifyXpGain(SkillType skillType, float xp) {
|
||||
if (player.getGameMode() == GameMode.CREATIVE || (skillType.getMaxLevel() <= profile.getSkillLevel(skillType)) || (Config.getInstance().getPowerLevelCap() <= getPowerLevel())) {
|
||||
if (player.getGameMode() == GameMode.CREATIVE || (skillType.getMaxLevel() < profile.getSkillLevel(skillType) + 1) || (Config.getInstance().getPowerLevelCap() < getPowerLevel() + 1)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
xp = (float) (xp / skillType.getXpModifier() * Config.getInstance().getExperienceGainsGlobalMultiplier());
|
||||
|
||||
if (Config.getInstance().getToolModsEnabled()) {
|
||||
CustomTool tool = ModUtils.getToolFromItemStack(player.getItemInHand());
|
||||
ItemStack item = player.getItemInHand();
|
||||
CustomTool tool = ModUtils.getToolFromItemStack(item);
|
||||
|
||||
if (tool != null) {
|
||||
xp *= tool.getXpMultiplier();
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package com.gmail.nossr50.datatypes.player;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -9,15 +14,18 @@ import org.bukkit.scoreboard.Scoreboard;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.config.spout.SpoutConfig;
|
||||
import com.gmail.nossr50.database.SQLDatabaseManager;
|
||||
import com.gmail.nossr50.datatypes.MobHealthbarType;
|
||||
import com.gmail.nossr50.datatypes.skills.AbilityType;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.datatypes.spout.huds.HudType;
|
||||
import com.gmail.nossr50.datatypes.spout.huds.McMMOHud;
|
||||
import com.gmail.nossr50.skills.child.FamilyTree;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
|
||||
public class PlayerProfile {
|
||||
private final String playerName;
|
||||
private int userId;
|
||||
private boolean loaded;
|
||||
|
||||
/* HUDs */
|
||||
@@ -28,10 +36,10 @@ public class PlayerProfile {
|
||||
|
||||
/* Skill Data */
|
||||
private final Map<SkillType, Integer> skills = new HashMap<SkillType, Integer>(); // Skill & Level
|
||||
private final Map<SkillType, Float> skillsXp = new HashMap<SkillType, Float>(); // Skill & XP
|
||||
private final Map<SkillType, Float> skillsXp = new HashMap<SkillType, Float>(); // Skill & XP
|
||||
private final Map<AbilityType, Integer> skillsDATS = new HashMap<AbilityType, Integer>(); // Ability & Cooldown
|
||||
|
||||
public PlayerProfile(String playerName) {
|
||||
public PlayerProfile(String playerName, boolean addNew) {
|
||||
this.playerName = playerName;
|
||||
|
||||
hudType = mcMMO.isSpoutEnabled() ? SpoutConfig.getInstance().getDefaultHudType() : HudType.DISABLED;
|
||||
@@ -41,35 +49,28 @@ public class PlayerProfile {
|
||||
skillsDATS.put(abilityType, 0);
|
||||
}
|
||||
|
||||
for (SkillType skillType : SkillType.nonChildSkills()) {
|
||||
for (SkillType skillType : SkillType.values()) {
|
||||
if (skillType.isChildSkill()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
skills.put(skillType, 0);
|
||||
skillsXp.put(skillType, 0F);
|
||||
}
|
||||
}
|
||||
|
||||
public PlayerProfile(String playerName, boolean isLoaded) {
|
||||
this(playerName);
|
||||
this.loaded = isLoaded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calling this constructor is considered loading the profile.
|
||||
*/
|
||||
public PlayerProfile(String playerName, Map<SkillType, Integer> argSkills, Map<SkillType, Float> argSkillsXp, Map<AbilityType, Integer> argSkillsDats, HudType hudType, MobHealthbarType mobHealthbarType) {
|
||||
this(playerName, true);
|
||||
|
||||
this.hudType = hudType;
|
||||
this.mobHealthbarType = mobHealthbarType;
|
||||
|
||||
this.skills.putAll(argSkills);
|
||||
this.skillsXp.putAll(argSkillsXp);
|
||||
this.skillsDATS.putAll(argSkillsDats);
|
||||
|
||||
loaded = true;
|
||||
if (!loadPlayer() && addNew) {
|
||||
addPlayer();
|
||||
loaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void save() {
|
||||
mcMMO.getDatabaseManager().saveUser(this);
|
||||
if (Config.getInstance().getUseMySQL()) {
|
||||
saveMySQL();
|
||||
}
|
||||
else {
|
||||
saveFlatfile();
|
||||
}
|
||||
}
|
||||
|
||||
public String getPlayerName() {
|
||||
@@ -141,7 +142,7 @@ public class PlayerProfile {
|
||||
/**
|
||||
* Set the current DATS of a skill.
|
||||
*
|
||||
* @param abilityType Ability to set the DATS for
|
||||
* @param abilityType Ability to set the DATS for
|
||||
* @param DATS the DATS of the ability
|
||||
*/
|
||||
public void setSkillDATS(AbilityType abilityType, long DATS) {
|
||||
@@ -269,4 +270,404 @@ public class PlayerProfile {
|
||||
|
||||
return sum / parents.size();
|
||||
}
|
||||
|
||||
private boolean loadPlayer() {
|
||||
return Config.getInstance().getUseMySQL() ? loadMySQL() : loadFlatfile();
|
||||
}
|
||||
|
||||
private void addPlayer() {
|
||||
if (Config.getInstance().getUseMySQL()) {
|
||||
addMySQLPlayer();
|
||||
}
|
||||
else {
|
||||
addFlatfilePlayer();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean loadMySQL() {
|
||||
String tablePrefix = Config.getInstance().getMySQLTablePrefix();
|
||||
|
||||
ArrayList<String> playerData = SQLDatabaseManager.read(
|
||||
"SELECT " +
|
||||
"u.id, " +
|
||||
"s.taming, s.mining, s.repair, s.woodcutting, s.unarmed, s.herbalism, s.excavation, s.archery, s.swords, s.axes, s.acrobatics, s.fishing, " +
|
||||
"e.taming, e.mining, e.repair, e.woodcutting, e.unarmed, e.herbalism, e.excavation, e.archery, e.swords, e.axes, e.acrobatics, e.fishing, " +
|
||||
"c.taming, c.mining, c.repair, c.woodcutting, c.unarmed, c.herbalism, c.excavation, c.archery, c.swords, c.axes, c.acrobatics, c.blast_mining, " +
|
||||
"h.hudtype, h.mobhealthbar " +
|
||||
"FROM " + tablePrefix + "users u " +
|
||||
"JOIN " + tablePrefix + "skills s ON (u.id = s.user_id) " +
|
||||
"JOIN " + tablePrefix + "experience e ON (u.id = e.user_id) " +
|
||||
"JOIN " + tablePrefix + "cooldowns c ON (u.id = c.user_id) " +
|
||||
"JOIN " + tablePrefix + "huds h ON (u.id = h.user_id) " +
|
||||
"WHERE u.user = '" + playerName + "'"
|
||||
).get(1);
|
||||
|
||||
if (playerData == null || playerData.size() == 0) {
|
||||
userId = SQLDatabaseManager.getInt("SELECT id FROM " + tablePrefix + "users WHERE user = '" + playerName + "'");
|
||||
|
||||
// Check if user doesn't exist
|
||||
if (userId == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Write missing table rows
|
||||
SQLDatabaseManager.write("INSERT IGNORE INTO " + tablePrefix + "skills (user_id) VALUES (" + userId + ")");
|
||||
SQLDatabaseManager.write("INSERT IGNORE INTO " + tablePrefix + "experience (user_id) VALUES (" + userId + ")");
|
||||
SQLDatabaseManager.write("INSERT IGNORE INTO " + tablePrefix + "cooldowns (user_id) VALUES (" + userId + ")");
|
||||
SQLDatabaseManager.write("INSERT IGNORE INTO " + tablePrefix + "huds (user_id, mobhealthbar) VALUES (" + userId + ",'" + mobHealthbarType.name() + "')");
|
||||
|
||||
// Re-read data
|
||||
playerData = SQLDatabaseManager.read(
|
||||
"SELECT " +
|
||||
"u.id, " +
|
||||
"s.taming, s.mining, s.repair, s.woodcutting, s.unarmed, s.herbalism, s.excavation, s.archery, s.swords, s.axes, s.acrobatics, s.fishing, " +
|
||||
"e.taming, e.mining, e.repair, e.woodcutting, e.unarmed, e.herbalism, e.excavation, e.archery, e.swords, e.axes, e.acrobatics, e.fishing, " +
|
||||
"c.taming, c.mining, c.repair, c.woodcutting, c.unarmed, c.herbalism, c.excavation, c.archery, c.swords, c.axes, c.acrobatics, c.blast_mining, " +
|
||||
"h.hudtype, h.mobhealthbar " +
|
||||
"FROM " + tablePrefix + "users u " +
|
||||
"JOIN " + tablePrefix + "skills s ON (u.id = s.user_id) " +
|
||||
"JOIN " + tablePrefix + "experience e ON (u.id = e.user_id) " +
|
||||
"JOIN " + tablePrefix + "cooldowns c ON (u.id = c.user_id) " +
|
||||
"JOIN " + tablePrefix + "huds h ON (u.id = h.user_id) " +
|
||||
"WHERE u.user = '" + playerName + "'"
|
||||
).get(1);
|
||||
|
||||
// Should never happen but just in case
|
||||
if (playerData == null || playerData.size() == 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
userId = Integer.valueOf(playerData.get(0));
|
||||
|
||||
skills.put(SkillType.TAMING, Integer.valueOf(playerData.get(1)));
|
||||
skills.put(SkillType.MINING, Integer.valueOf(playerData.get(2)));
|
||||
skills.put(SkillType.REPAIR, Integer.valueOf(playerData.get(3)));
|
||||
skills.put(SkillType.WOODCUTTING, Integer.valueOf(playerData.get(4)));
|
||||
skills.put(SkillType.UNARMED, Integer.valueOf(playerData.get(5)));
|
||||
skills.put(SkillType.HERBALISM, Integer.valueOf(playerData.get(6)));
|
||||
skills.put(SkillType.EXCAVATION, Integer.valueOf(playerData.get(7)));
|
||||
skills.put(SkillType.ARCHERY, Integer.valueOf(playerData.get(8)));
|
||||
skills.put(SkillType.SWORDS, Integer.valueOf(playerData.get(9)));
|
||||
skills.put(SkillType.AXES, Integer.valueOf(playerData.get(10)));
|
||||
skills.put(SkillType.ACROBATICS, Integer.valueOf(playerData.get(11)));
|
||||
skills.put(SkillType.FISHING, Integer.valueOf(playerData.get(12)));
|
||||
|
||||
skillsXp.put(SkillType.TAMING, (float) Integer.valueOf(playerData.get(13)));
|
||||
skillsXp.put(SkillType.MINING, (float) Integer.valueOf(playerData.get(14)));
|
||||
skillsXp.put(SkillType.REPAIR, (float) Integer.valueOf(playerData.get(15)));
|
||||
skillsXp.put(SkillType.WOODCUTTING, (float) Integer.valueOf(playerData.get(16)));
|
||||
skillsXp.put(SkillType.UNARMED, (float) Integer.valueOf(playerData.get(17)));
|
||||
skillsXp.put(SkillType.HERBALISM, (float) Integer.valueOf(playerData.get(18)));
|
||||
skillsXp.put(SkillType.EXCAVATION, (float) Integer.valueOf(playerData.get(19)));
|
||||
skillsXp.put(SkillType.ARCHERY, (float) Integer.valueOf(playerData.get(20)));
|
||||
skillsXp.put(SkillType.SWORDS, (float) Integer.valueOf(playerData.get(21)));
|
||||
skillsXp.put(SkillType.AXES, (float) Integer.valueOf(playerData.get(22)));
|
||||
skillsXp.put(SkillType.ACROBATICS, (float) Integer.valueOf(playerData.get(23)));
|
||||
skillsXp.put(SkillType.FISHING, (float) Integer.valueOf(playerData.get(24)));
|
||||
|
||||
// Taming 25 - Unused
|
||||
skillsDATS.put(AbilityType.SUPER_BREAKER, Integer.valueOf(playerData.get(26)));
|
||||
// Repair 27 - Unused
|
||||
skillsDATS.put(AbilityType.TREE_FELLER, Integer.valueOf(playerData.get(28)));
|
||||
skillsDATS.put(AbilityType.BERSERK, Integer.valueOf(playerData.get(29)));
|
||||
skillsDATS.put(AbilityType.GREEN_TERRA, Integer.valueOf(playerData.get(30)));
|
||||
skillsDATS.put(AbilityType.GIGA_DRILL_BREAKER, Integer.valueOf(playerData.get(31)));
|
||||
// Archery 32 - Unused
|
||||
skillsDATS.put(AbilityType.SERRATED_STRIKES, Integer.valueOf(playerData.get(33)));
|
||||
skillsDATS.put(AbilityType.SKULL_SPLITTER, Integer.valueOf(playerData.get(34)));
|
||||
// Acrobatics 35 - Unused
|
||||
skillsDATS.put(AbilityType.BLAST_MINING, Integer.valueOf(playerData.get(36)));
|
||||
|
||||
try {
|
||||
hudType = HudType.valueOf(playerData.get(37));
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Shouldn't happen unless database is being tampered with
|
||||
hudType = HudType.STANDARD;
|
||||
}
|
||||
|
||||
try {
|
||||
mobHealthbarType = MobHealthbarType.valueOf(playerData.get(38));
|
||||
}
|
||||
catch (Exception e) {
|
||||
mobHealthbarType = Config.getInstance().getMobHealthbarDefault();
|
||||
}
|
||||
|
||||
loaded = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
private void addMySQLPlayer() {
|
||||
String tablePrefix = Config.getInstance().getMySQLTablePrefix();
|
||||
|
||||
SQLDatabaseManager.write("INSERT INTO " + tablePrefix + "users (user, lastlogin) VALUES ('" + playerName + "'," + System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR + ")");
|
||||
userId = SQLDatabaseManager.getInt("SELECT id FROM " + tablePrefix + "users WHERE user = '" + playerName + "'");
|
||||
|
||||
SQLDatabaseManager.write("INSERT INTO " + tablePrefix + "huds (user_id, mobhealthbar) VALUES (" + userId + ", '" + mobHealthbarType.name() + "')");
|
||||
SQLDatabaseManager.write("INSERT INTO " + tablePrefix + "cooldowns (user_id) VALUES (" + userId + ")");
|
||||
SQLDatabaseManager.write("INSERT INTO " + tablePrefix + "skills (user_id) VALUES (" + userId + ")");
|
||||
SQLDatabaseManager.write("INSERT INTO " + tablePrefix + "experience (user_id) VALUES (" + userId + ")");
|
||||
}
|
||||
|
||||
|
||||
private void addFlatfilePlayer() {
|
||||
try {
|
||||
// Open the file to write the player
|
||||
BufferedWriter out = new BufferedWriter(new FileWriter(mcMMO.getUsersFilePath(), true));
|
||||
|
||||
// Add the player to the end
|
||||
out.append(playerName).append(":");
|
||||
out.append("0:"); // Mining
|
||||
out.append(":");
|
||||
out.append(":");
|
||||
out.append("0:"); // Xp
|
||||
out.append("0:"); // Woodcutting
|
||||
out.append("0:"); // WoodCuttingXp
|
||||
out.append("0:"); // Repair
|
||||
out.append("0:"); // Unarmed
|
||||
out.append("0:"); // Herbalism
|
||||
out.append("0:"); // Excavation
|
||||
out.append("0:"); // Archery
|
||||
out.append("0:"); // Swords
|
||||
out.append("0:"); // Axes
|
||||
out.append("0:"); // Acrobatics
|
||||
out.append("0:"); // RepairXp
|
||||
out.append("0:"); // UnarmedXp
|
||||
out.append("0:"); // HerbalismXp
|
||||
out.append("0:"); // ExcavationXp
|
||||
out.append("0:"); // ArcheryXp
|
||||
out.append("0:"); // SwordsXp
|
||||
out.append("0:"); // AxesXp
|
||||
out.append("0:"); // AcrobaticsXp
|
||||
out.append(":");
|
||||
out.append("0:"); // Taming
|
||||
out.append("0:"); // TamingXp
|
||||
out.append("0:"); // DATS
|
||||
out.append("0:"); // DATS
|
||||
out.append("0:"); // DATS
|
||||
out.append("0:"); // DATS
|
||||
out.append("0:"); // DATS
|
||||
out.append("0:"); // DATS
|
||||
out.append("0:"); // DATS
|
||||
out.append(hudType == null ? "STANDARD" : hudType.toString()).append(":"); // HUD
|
||||
out.append("0:"); // Fishing
|
||||
out.append("0:"); // FishingXp
|
||||
out.append("0:"); // Blast Mining
|
||||
out.append(String.valueOf(System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR)).append(":"); // LastLogin
|
||||
out.append(mobHealthbarType == null ? Config.getInstance().getMobHealthbarDefault().toString() : mobHealthbarType.toString()).append(":"); // Mob Healthbar HUD
|
||||
|
||||
// Add more in the same format as the line above
|
||||
|
||||
out.newLine();
|
||||
out.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean loadFlatfile() {
|
||||
try {
|
||||
// Open the user file
|
||||
FileReader file = new FileReader(mcMMO.getUsersFilePath());
|
||||
BufferedReader in = new BufferedReader(file);
|
||||
String line;
|
||||
|
||||
while ((line = in.readLine()) != null) {
|
||||
// Find if the line contains the player we want.
|
||||
String[] character = line.split(":");
|
||||
|
||||
if (!character[0].equalsIgnoreCase(playerName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
loadSkillData(SkillType.MINING, character, 1);
|
||||
loadSkillData(SkillType.WOODCUTTING, character, 5);
|
||||
loadSkillData(SkillType.REPAIR, character, 7);
|
||||
loadSkillData(SkillType.UNARMED, character, 8);
|
||||
loadSkillData(SkillType.HERBALISM, character, 9);
|
||||
loadSkillData(SkillType.EXCAVATION, character, 10);
|
||||
loadSkillData(SkillType.ARCHERY, character, 11);
|
||||
loadSkillData(SkillType.SWORDS, character, 12);
|
||||
loadSkillData(SkillType.AXES, character, 13);
|
||||
loadSkillData(SkillType.ACROBATICS, character, 14);
|
||||
loadSkillData(SkillType.TAMING, character, 24);
|
||||
loadSkillData(SkillType.FISHING, character, 34);
|
||||
|
||||
loadSkillXpData(SkillType.MINING, character, 4);
|
||||
loadSkillXpData(SkillType.WOODCUTTING, character, 6);
|
||||
loadSkillXpData(SkillType.REPAIR, character, 15);
|
||||
loadSkillXpData(SkillType.UNARMED, character, 16);
|
||||
loadSkillXpData(SkillType.HERBALISM, character, 17);
|
||||
loadSkillXpData(SkillType.EXCAVATION, character, 18);
|
||||
loadSkillXpData(SkillType.ARCHERY, character, 19);
|
||||
loadSkillXpData(SkillType.SWORDS, character, 20);
|
||||
loadSkillXpData(SkillType.AXES, character, 21);
|
||||
loadSkillXpData(SkillType.ACROBATICS, character, 22);
|
||||
loadSkillXpData(SkillType.TAMING, character, 25);
|
||||
loadSkillXpData(SkillType.FISHING, character, 35);
|
||||
|
||||
loadDATSData(AbilityType.BERSERK, character, 26);
|
||||
loadDATSData(AbilityType.GIGA_DRILL_BREAKER, character, 27);
|
||||
loadDATSData(AbilityType.TREE_FELLER, character, 28);
|
||||
loadDATSData(AbilityType.GREEN_TERRA, character, 29);
|
||||
loadDATSData(AbilityType.SERRATED_STRIKES, character, 30);
|
||||
loadDATSData(AbilityType.SKULL_SPLITTER, character, 31);
|
||||
loadDATSData(AbilityType.SUPER_BREAKER, character, 32);
|
||||
loadDATSData(AbilityType.BLAST_MINING, character, 36);
|
||||
|
||||
hudType = character.length > 33 ? HudType.valueOf(character[33]) : null;
|
||||
mobHealthbarType = character.length > 38 ? MobHealthbarType.valueOf(character[38]) : null;
|
||||
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
in.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return loaded;
|
||||
}
|
||||
|
||||
private void saveMySQL() {
|
||||
if (Config.getInstance().getUseMySQL()) {
|
||||
String tablePrefix = Config.getInstance().getMySQLTablePrefix();
|
||||
|
||||
SQLDatabaseManager.write("UPDATE " + tablePrefix + "users SET lastlogin = " + ((int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR)) + " WHERE id = " + userId);
|
||||
SQLDatabaseManager.write("UPDATE " + tablePrefix + "huds SET "
|
||||
+ " hudtype = '" + (hudType == null ? "STANDARD" : hudType.toString() + "'")
|
||||
+ ", mobhealthbar = '" + (mobHealthbarType == null ? Config.getInstance().getMobHealthbarDefault().toString() : mobHealthbarType.toString() + "'")
|
||||
+ " WHERE user_id = " + userId);
|
||||
SQLDatabaseManager.write("UPDATE " + tablePrefix + "cooldowns SET "
|
||||
+ " mining = " + skillsDATS.get(AbilityType.SUPER_BREAKER)
|
||||
+ ", woodcutting = " + skillsDATS.get(AbilityType.TREE_FELLER)
|
||||
+ ", unarmed = " + skillsDATS.get(AbilityType.BERSERK)
|
||||
+ ", herbalism = " + skillsDATS.get(AbilityType.GREEN_TERRA)
|
||||
+ ", excavation = " + skillsDATS.get(AbilityType.GIGA_DRILL_BREAKER)
|
||||
+ ", swords = " + skillsDATS.get(AbilityType.SERRATED_STRIKES)
|
||||
+ ", axes = " + skillsDATS.get(AbilityType.SKULL_SPLITTER)
|
||||
+ ", blast_mining = " + skillsDATS.get(AbilityType.BLAST_MINING)
|
||||
+ " WHERE user_id = " + userId);
|
||||
SQLDatabaseManager.write("UPDATE " + tablePrefix + "skills SET "
|
||||
+ " taming = " + skills.get(SkillType.TAMING)
|
||||
+ ", mining = " + skills.get(SkillType.MINING)
|
||||
+ ", repair = " + skills.get(SkillType.REPAIR)
|
||||
+ ", woodcutting = " + skills.get(SkillType.WOODCUTTING)
|
||||
+ ", unarmed = " + skills.get(SkillType.UNARMED)
|
||||
+ ", herbalism = " + skills.get(SkillType.HERBALISM)
|
||||
+ ", excavation = " + skills.get(SkillType.EXCAVATION)
|
||||
+ ", archery = " + skills.get(SkillType.ARCHERY)
|
||||
+ ", swords = " + skills.get(SkillType.SWORDS)
|
||||
+ ", axes = " + skills.get(SkillType.AXES)
|
||||
+ ", acrobatics = " + skills.get(SkillType.ACROBATICS)
|
||||
+ ", fishing = " + skills.get(SkillType.FISHING)
|
||||
+ " WHERE user_id = " + userId);
|
||||
SQLDatabaseManager.write("UPDATE " + tablePrefix + "experience SET "
|
||||
+ " taming = " + getSkillXpLevel(SkillType.TAMING)
|
||||
+ ", mining = " + getSkillXpLevel(SkillType.MINING)
|
||||
+ ", repair = " + getSkillXpLevel(SkillType.REPAIR)
|
||||
+ ", woodcutting = " + getSkillXpLevel(SkillType.WOODCUTTING)
|
||||
+ ", unarmed = " + getSkillXpLevel(SkillType.UNARMED)
|
||||
+ ", herbalism = " + getSkillXpLevel(SkillType.HERBALISM)
|
||||
+ ", excavation = " + getSkillXpLevel(SkillType.EXCAVATION)
|
||||
+ ", archery = " + getSkillXpLevel(SkillType.ARCHERY)
|
||||
+ ", swords = " + getSkillXpLevel(SkillType.SWORDS)
|
||||
+ ", axes = " + getSkillXpLevel(SkillType.AXES)
|
||||
+ ", acrobatics = " + getSkillXpLevel(SkillType.ACROBATICS)
|
||||
+ ", fishing = " + getSkillXpLevel(SkillType.FISHING)
|
||||
+ " WHERE user_id = " + userId);
|
||||
}
|
||||
}
|
||||
|
||||
private void saveFlatfile() {
|
||||
try {
|
||||
// Open the file
|
||||
BufferedReader in = new BufferedReader(new FileReader(mcMMO.getUsersFilePath()));
|
||||
StringBuilder writer = new StringBuilder();
|
||||
String line;
|
||||
|
||||
// While not at the end of the file
|
||||
while ((line = in.readLine()) != null) {
|
||||
// Read the line in and copy it to the output it's not the player we want to edit
|
||||
if (!line.split(":")[0].equalsIgnoreCase(playerName)) {
|
||||
writer.append(line).append("\r\n");
|
||||
}
|
||||
else {
|
||||
// Otherwise write the new player information
|
||||
writer.append(playerName).append(":");
|
||||
writer.append(skills.get(SkillType.MINING)).append(":");
|
||||
writer.append(":");
|
||||
writer.append(":");
|
||||
writer.append(getSkillXpLevel(SkillType.MINING)).append(":");
|
||||
writer.append(skills.get(SkillType.WOODCUTTING)).append(":");
|
||||
writer.append(getSkillXpLevel(SkillType.WOODCUTTING)).append(":");
|
||||
writer.append(skills.get(SkillType.REPAIR)).append(":");
|
||||
writer.append(skills.get(SkillType.UNARMED)).append(":");
|
||||
writer.append(skills.get(SkillType.HERBALISM)).append(":");
|
||||
writer.append(skills.get(SkillType.EXCAVATION)).append(":");
|
||||
writer.append(skills.get(SkillType.ARCHERY)).append(":");
|
||||
writer.append(skills.get(SkillType.SWORDS)).append(":");
|
||||
writer.append(skills.get(SkillType.AXES)).append(":");
|
||||
writer.append(skills.get(SkillType.ACROBATICS)).append(":");
|
||||
writer.append(getSkillXpLevel(SkillType.REPAIR)).append(":");
|
||||
writer.append(getSkillXpLevel(SkillType.UNARMED)).append(":");
|
||||
writer.append(getSkillXpLevel(SkillType.HERBALISM)).append(":");
|
||||
writer.append(getSkillXpLevel(SkillType.EXCAVATION)).append(":");
|
||||
writer.append(getSkillXpLevel(SkillType.ARCHERY)).append(":");
|
||||
writer.append(getSkillXpLevel(SkillType.SWORDS)).append(":");
|
||||
writer.append(getSkillXpLevel(SkillType.AXES)).append(":");
|
||||
writer.append(getSkillXpLevel(SkillType.ACROBATICS)).append(":");
|
||||
writer.append(":");
|
||||
writer.append(skills.get(SkillType.TAMING)).append(":");
|
||||
writer.append(getSkillXpLevel(SkillType.TAMING)).append(":");
|
||||
writer.append(skillsDATS.get(AbilityType.BERSERK)).append(":");
|
||||
writer.append(skillsDATS.get(AbilityType.GIGA_DRILL_BREAKER)).append(":");
|
||||
writer.append(skillsDATS.get(AbilityType.TREE_FELLER)).append(":");
|
||||
writer.append(skillsDATS.get(AbilityType.GREEN_TERRA)).append(":");
|
||||
writer.append(skillsDATS.get(AbilityType.SERRATED_STRIKES)).append(":");
|
||||
writer.append(skillsDATS.get(AbilityType.SKULL_SPLITTER)).append(":");
|
||||
writer.append(skillsDATS.get(AbilityType.SUPER_BREAKER)).append(":");
|
||||
writer.append(hudType == null ? "STANDARD" : hudType.toString()).append(":");
|
||||
writer.append(skills.get(SkillType.FISHING)).append(":");
|
||||
writer.append(getSkillXpLevel(SkillType.FISHING)).append(":");
|
||||
writer.append(skillsDATS.get(AbilityType.BLAST_MINING)).append(":");
|
||||
writer.append(System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR).append(":");
|
||||
writer.append(mobHealthbarType == null ? Config.getInstance().getMobHealthbarDefault().toString() : mobHealthbarType.toString()).append(":");
|
||||
writer.append("\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
in.close();
|
||||
|
||||
// Write the new file
|
||||
FileWriter out = new FileWriter(mcMMO.getUsersFilePath());
|
||||
out.write(writer.toString());
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void loadSkillXpData(SkillType skill, String[] data, int dataIndex) {
|
||||
if (data.length > dataIndex) {
|
||||
skillsXp.put(skill, (float) Integer.valueOf(data[dataIndex]));
|
||||
}
|
||||
}
|
||||
|
||||
private void loadSkillData(SkillType skill, String[] data, int dataIndex) {
|
||||
if (data.length > dataIndex) {
|
||||
skills.put(skill, Integer.valueOf(data[dataIndex]));
|
||||
}
|
||||
}
|
||||
|
||||
private void loadDATSData(AbilityType ability, String[] data, int dataIndex) {
|
||||
if (data.length > dataIndex) {
|
||||
skillsDATS.put(ability, Integer.valueOf(data[dataIndex]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,13 +68,6 @@ public enum AbilityType {
|
||||
null),
|
||||
|
||||
LEAF_BLOWER(
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null),
|
||||
|
||||
BLOCK_CRACKER(
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
@@ -151,6 +144,7 @@ public enum AbilityType {
|
||||
* @return true if the player has permissions, false otherwise
|
||||
*/
|
||||
public boolean getPermissions(Player player) {
|
||||
|
||||
switch (this) {
|
||||
case BERSERK:
|
||||
return Permissions.berserk(player);
|
||||
@@ -158,9 +152,6 @@ public enum AbilityType {
|
||||
case BLAST_MINING:
|
||||
return Permissions.remoteDetonation(player);
|
||||
|
||||
case BLOCK_CRACKER:
|
||||
return Permissions.blockCracker(player);
|
||||
|
||||
case GIGA_DRILL_BREAKER:
|
||||
return Permissions.gigaDrillBreaker(player);
|
||||
|
||||
@@ -198,9 +189,6 @@ public enum AbilityType {
|
||||
case BERSERK:
|
||||
return (BlockUtils.affectedByGigaDrillBreaker(blockState) || blockState.getType() == Material.SNOW);
|
||||
|
||||
case BLOCK_CRACKER:
|
||||
return BlockUtils.affectedByBlockCracker(blockState);
|
||||
|
||||
case GIGA_DRILL_BREAKER:
|
||||
return BlockUtils.affectedByGigaDrillBreaker(blockState);
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ public enum SkillType {
|
||||
}
|
||||
|
||||
public double getXpModifier() {
|
||||
return Config.getInstance().getFormulaSkillModifier(this);
|
||||
return Config.getInstance().getForumulaMultiplier(this);
|
||||
}
|
||||
|
||||
public static SkillType getSkill(String skillName) {
|
||||
|
||||
@@ -56,7 +56,11 @@ public class McMMOHud {
|
||||
}
|
||||
|
||||
public boolean isMenuOpened() {
|
||||
return (menu != null);
|
||||
if (menu != null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void openMenu() {
|
||||
|
||||
@@ -17,7 +17,7 @@ public class McMMOPlayerLevelUpEvent extends McMMOPlayerExperienceEvent {
|
||||
|
||||
public McMMOPlayerLevelUpEvent(Player player, SkillType skill, int levelsGained) {
|
||||
super(player, skill);
|
||||
this.levelsGained = levelsGained;
|
||||
this.setLevelsGained(levelsGained);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
package com.gmail.nossr50.events.skills.fishing;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.events.skills.McMMOPlayerSkillEvent;
|
||||
|
||||
public class McMMOPlayerFishingTreasureEvent extends McMMOPlayerSkillEvent implements Cancellable {
|
||||
|
||||
private boolean cancelled = false;
|
||||
private ItemStack treasure;
|
||||
private int xp;
|
||||
|
||||
public McMMOPlayerFishingTreasureEvent(Player player, ItemStack treasure, int xp) {
|
||||
super(player, SkillType.FISHING);
|
||||
this.treasure = treasure;
|
||||
this.xp = xp;
|
||||
}
|
||||
|
||||
public ItemStack getTreasure() {
|
||||
return treasure;
|
||||
}
|
||||
|
||||
public void setTreasure(ItemStack item) {
|
||||
this.treasure = item;
|
||||
}
|
||||
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
public void setCancelled(boolean newValue) {
|
||||
this.cancelled = newValue;
|
||||
}
|
||||
|
||||
public int getXp() {
|
||||
return xp;
|
||||
}
|
||||
|
||||
public void setXp(int xp) {
|
||||
this.xp = xp;
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package com.gmail.nossr50.events.skills.fishing;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class McMMOPlayerMagicHunterEvent extends McMMOPlayerFishingTreasureEvent {
|
||||
|
||||
private Map<Enchantment, Integer> enchants;
|
||||
|
||||
public McMMOPlayerMagicHunterEvent(Player player, ItemStack treasure, int xp, Map<Enchantment, Integer> enchants) {
|
||||
super(player, treasure, xp);
|
||||
this.enchants = enchants;
|
||||
}
|
||||
|
||||
public Map<Enchantment, Integer> getEnchantments() {
|
||||
return enchants;
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package com.gmail.nossr50.events.skills.fishing;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.events.skills.McMMOPlayerSkillEvent;
|
||||
|
||||
public class McMMOPlayerShakeEvent extends McMMOPlayerSkillEvent implements Cancellable {
|
||||
|
||||
private boolean cancelled = false;
|
||||
private ItemStack drop;
|
||||
|
||||
public McMMOPlayerShakeEvent(Player player, ItemStack drop) {
|
||||
super(player, SkillType.FISHING);
|
||||
this.drop = drop;
|
||||
}
|
||||
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
public void setCancelled(boolean newValue) {
|
||||
this.cancelled = newValue;
|
||||
}
|
||||
|
||||
public ItemStack getDrop() {
|
||||
return drop;
|
||||
}
|
||||
|
||||
public void setDrop(ItemStack drop) {
|
||||
this.drop = drop;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,18 +22,21 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.HiddenConfig;
|
||||
import com.gmail.nossr50.config.WorldConfig;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.skills.AbilityType;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.ToolType;
|
||||
import com.gmail.nossr50.events.fake.FakeBlockBreakEvent;
|
||||
import com.gmail.nossr50.events.fake.FakeBlockDamageEvent;
|
||||
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
|
||||
import com.gmail.nossr50.runnables.StickyPistonTrackerTask;
|
||||
import com.gmail.nossr50.skills.excavation.ExcavationManager;
|
||||
import com.gmail.nossr50.skills.herbalism.HerbalismManager;
|
||||
import com.gmail.nossr50.skills.mining.MiningManager;
|
||||
import com.gmail.nossr50.skills.repair.Repair;
|
||||
import com.gmail.nossr50.skills.smelting.SmeltingManager;
|
||||
import com.gmail.nossr50.skills.unarmed.UnarmedManager;
|
||||
import com.gmail.nossr50.skills.woodcutting.WoodcuttingManager;
|
||||
import com.gmail.nossr50.util.BlockUtils;
|
||||
import com.gmail.nossr50.util.ItemUtils;
|
||||
@@ -56,6 +59,10 @@ public class BlockListener implements Listener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
|
||||
if (!WorldConfig.getInstance().isBlockStoreEnabled(event.getBlock().getWorld().getName()) || !HiddenConfig.getInstance().getChunkletsEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<Block> blocks = event.getBlocks();
|
||||
BlockFace direction = event.getDirection();
|
||||
Block futureEmptyBlock = event.getBlock().getRelative(direction); // Block that would be air after piston is finished
|
||||
@@ -70,11 +77,9 @@ public class BlockListener implements Listener {
|
||||
}
|
||||
|
||||
for (Block b : blocks) {
|
||||
Block nextBlock = b.getRelative(direction);
|
||||
|
||||
if (nextBlock.hasMetadata(mcMMO.blockMetadataKey)) {
|
||||
mcMMO.getPlaceStore().setTrue(nextBlock);
|
||||
nextBlock.removeMetadata(mcMMO.blockMetadataKey, plugin);
|
||||
if (b.getRelative(direction).hasMetadata(mcMMO.blockMetadataKey)) {
|
||||
mcMMO.getPlaceStore().setTrue(b.getRelative(direction));
|
||||
b.getRelative(direction).removeMetadata(mcMMO.blockMetadataKey, plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -88,6 +93,10 @@ public class BlockListener implements Listener {
|
||||
public void onBlockPistonRetract(BlockPistonRetractEvent event) {
|
||||
if (event.isSticky()) {
|
||||
// Needed only because under some circumstances Minecraft doesn't move the block
|
||||
if (!WorldConfig.getInstance().isBlockStoreEnabled(event.getBlock().getWorld().getName()) || !HiddenConfig.getInstance().getChunkletsEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
new StickyPistonTrackerTask(event.getDirection(), event.getBlock()).runTaskLater(plugin, 2);
|
||||
}
|
||||
}
|
||||
@@ -106,14 +115,15 @@ public class BlockListener implements Listener {
|
||||
}
|
||||
|
||||
BlockState blockState = event.getBlock().getState();
|
||||
int blockId = blockState.getTypeId();
|
||||
|
||||
/* Check if the blocks placed should be monitored so they do not give out XP in the future */
|
||||
if (BlockUtils.shouldBeWatched(blockState)) {
|
||||
mcMMO.getPlaceStore().setTrue(blockState);
|
||||
}
|
||||
|
||||
if (Repair.anvilMessagesEnabled && BlockUtils.isMcMMOAnvil(blockState)) {
|
||||
UserManager.getPlayer(player).getRepairManager().placedAnvilCheck(blockState.getTypeId());
|
||||
if (Repair.anvilMessagesEnabled && (blockId == Repair.repairAnvilId || blockId == Repair.salvageAnvilId)) {
|
||||
UserManager.getPlayer(player).getRepairManager().placedAnvilCheck(blockId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,47 +155,61 @@ public class BlockListener implements Listener {
|
||||
|
||||
/* HERBALISM */
|
||||
if (BlockUtils.affectedByGreenTerra(blockState)) {
|
||||
HerbalismManager herbalismManager = mcMMOPlayer.getHerbalismManager();
|
||||
if (WorldConfig.getInstance().isSkillEnabled(SkillType.HERBALISM, blockState.getWorld().getName())) {
|
||||
HerbalismManager herbalismManager = mcMMOPlayer.getHerbalismManager();
|
||||
|
||||
/* Green Terra */
|
||||
if (herbalismManager.canActivateAbility()) {
|
||||
SkillUtils.abilityCheck(mcMMOPlayer, SkillType.HERBALISM);
|
||||
}
|
||||
/* Green Terra */
|
||||
if (herbalismManager.canActivateAbility()) {
|
||||
SkillUtils.abilityCheck(mcMMOPlayer, SkillType.HERBALISM);
|
||||
}
|
||||
|
||||
/*
|
||||
* We don't check the block store here because herbalism has too many unusual edge cases.
|
||||
* Instead, we check it inside the drops handler.
|
||||
*/
|
||||
if (Permissions.skillEnabled(player, SkillType.HERBALISM)) {
|
||||
herbalismManager.herbalismBlockCheck(blockState);
|
||||
/*
|
||||
* We don't check the block store here because Herbalism has too many unusual edge cases.
|
||||
* Instead, we check it inside the drops handler.
|
||||
*/
|
||||
if (Permissions.skillEnabled(player, SkillType.HERBALISM)) {
|
||||
herbalismManager.herbalismBlockCheck(blockState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* MINING */
|
||||
else if (BlockUtils.affectedBySuperBreaker(blockState) && ItemUtils.isPickaxe(heldItem) && Permissions.skillEnabled(player, SkillType.MINING) && !mcMMO.getPlaceStore().isTrue(blockState)) {
|
||||
MiningManager miningManager = mcMMOPlayer.getMiningManager();
|
||||
miningManager.miningBlockCheck(blockState);
|
||||
else if (BlockUtils.affectedBySuperBreaker(blockState)) {
|
||||
if (WorldConfig.getInstance().isSkillEnabled(SkillType.MINING, blockState.getWorld().getName())) {
|
||||
if (ItemUtils.isPickaxe(heldItem) && Permissions.skillEnabled(player, SkillType.MINING) && !mcMMO.getPlaceStore().isTrue(blockState)) {
|
||||
MiningManager miningManager = mcMMOPlayer.getMiningManager();
|
||||
miningManager.miningBlockCheck(blockState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* WOOD CUTTING */
|
||||
else if (BlockUtils.isLog(blockState) && Permissions.skillEnabled(player, SkillType.WOODCUTTING) && !mcMMO.getPlaceStore().isTrue(blockState)) {
|
||||
WoodcuttingManager woodcuttingManager = mcMMOPlayer.getWoodcuttingManager();
|
||||
else if (BlockUtils.isLog(blockState)) {
|
||||
if (WorldConfig.getInstance().isSkillEnabled(SkillType.WOODCUTTING, blockState.getWorld().getName())) {
|
||||
if (Permissions.skillEnabled(player, SkillType.WOODCUTTING) && !mcMMO.getPlaceStore().isTrue(blockState)) {
|
||||
WoodcuttingManager woodcuttingManager = mcMMOPlayer.getWoodcuttingManager();
|
||||
|
||||
if (woodcuttingManager.canUseTreeFeller(heldItem)) {
|
||||
woodcuttingManager.processTreeFeller(blockState);
|
||||
}
|
||||
else {
|
||||
woodcuttingManager.woodcuttingBlockCheck(blockState);
|
||||
if (woodcuttingManager.canUseTreeFeller(heldItem)) {
|
||||
woodcuttingManager.processTreeFeller(blockState);
|
||||
}
|
||||
else {
|
||||
woodcuttingManager.woodcuttingBlockCheck(blockState);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* EXCAVATION */
|
||||
else if (BlockUtils.affectedByGigaDrillBreaker(blockState) && ItemUtils.isShovel(heldItem) && Permissions.skillEnabled(player, SkillType.EXCAVATION) && !mcMMO.getPlaceStore().isTrue(blockState)) {
|
||||
ExcavationManager excavationManager = mcMMOPlayer.getExcavationManager();
|
||||
excavationManager.excavationBlockCheck(blockState);
|
||||
else if (BlockUtils.affectedByGigaDrillBreaker(blockState)) {
|
||||
if (WorldConfig.getInstance().isSkillEnabled(SkillType.EXCAVATION, blockState.getWorld().getName())) {
|
||||
if (ItemUtils.isShovel(heldItem) && Permissions.skillEnabled(player, SkillType.EXCAVATION) && !mcMMO.getPlaceStore().isTrue(blockState)) {
|
||||
ExcavationManager excavationManager = mcMMOPlayer.getExcavationManager();
|
||||
excavationManager.excavationBlockCheck(blockState);
|
||||
|
||||
if (mcMMOPlayer.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER)) {
|
||||
excavationManager.gigaDrillBreaker(blockState);
|
||||
if (mcMMOPlayer.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER)) {
|
||||
excavationManager.gigaDrillBreaker(blockState);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,6 +238,10 @@ public class BlockListener implements Listener {
|
||||
ItemStack heldItem = player.getItemInHand();
|
||||
|
||||
if (ItemUtils.isSword(heldItem)) {
|
||||
if (!WorldConfig.getInstance().isSkillEnabled(SkillType.HERBALISM, blockState.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
HerbalismManager herbalismManager = UserManager.getPlayer(player).getHerbalismManager();
|
||||
|
||||
if (herbalismManager.canUseHylianLuck()) {
|
||||
@@ -224,6 +252,10 @@ public class BlockListener implements Listener {
|
||||
}
|
||||
}
|
||||
else if (ItemUtils.isPickaxe(heldItem) && !heldItem.containsEnchantment(Enchantment.SILK_TOUCH)) {
|
||||
if (!WorldConfig.getInstance().isSkillEnabled(SkillType.MINING, blockState.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
SmeltingManager smeltingManager = UserManager.getPlayer(player).getSmeltingManager();
|
||||
|
||||
if (smeltingManager.canUseFluxMining(blockState)) {
|
||||
@@ -322,31 +354,41 @@ public class BlockListener implements Listener {
|
||||
ItemStack heldItem = player.getItemInHand();
|
||||
Block block = event.getBlock();
|
||||
BlockState blockState = block.getState();
|
||||
HerbalismManager herbalismManager = mcMMOPlayer.getHerbalismManager();
|
||||
|
||||
/*
|
||||
* ABILITY TRIGGER CHECKS
|
||||
*
|
||||
* We don't need to check permissions here because they've already been checked for the ability to even activate.
|
||||
*/
|
||||
if (mcMMOPlayer.getAbilityMode(AbilityType.GREEN_TERRA) && BlockUtils.canMakeMossy(blockState)) {
|
||||
if (mcMMOPlayer.getHerbalismManager().processGreenTerra(blockState)) {
|
||||
if (herbalismManager.canGreenTerraBlock(blockState)) {
|
||||
if (herbalismManager.processGreenTerra(blockState)) {
|
||||
blockState.update(true);
|
||||
}
|
||||
}
|
||||
else if (mcMMOPlayer.getAbilityMode(AbilityType.BERSERK) && heldItem.getType() == Material.AIR) {
|
||||
else if (mcMMOPlayer.getAbilityMode(AbilityType.BERSERK)) {
|
||||
if (SkillUtils.triggerCheck(player, block, AbilityType.BERSERK)) {
|
||||
event.setInstaBreak(true);
|
||||
player.playSound(block.getLocation(), Sound.ITEM_PICKUP, Misc.POP_VOLUME, Misc.getPopPitch());
|
||||
if (heldItem.getType() == Material.AIR) {
|
||||
plugin.getServer().getPluginManager().callEvent(new FakePlayerAnimationEvent(player));
|
||||
|
||||
event.setInstaBreak(true);
|
||||
player.playSound(block.getLocation(), Sound.ITEM_PICKUP, Misc.POP_VOLUME, Misc.getPopPitch());
|
||||
}
|
||||
}
|
||||
else if (mcMMOPlayer.getUnarmedManager().canUseBlockCracker() && SkillUtils.triggerCheck(player, block, AbilityType.BLOCK_CRACKER)) {
|
||||
if (mcMMOPlayer.getUnarmedManager().blockCrackerCheck(blockState)) {
|
||||
// Another perm check for the cracked blocks activation
|
||||
else if (BlockUtils.affectedByBlockCracker(blockState)) {
|
||||
UnarmedManager unarmedManager = mcMMOPlayer.getUnarmedManager();
|
||||
|
||||
if (unarmedManager.canUseBlockCracker() && SkillUtils.blockBreakSimulate(block, player, false) && unarmedManager.blockCrackerCheck(blockState)) {
|
||||
blockState.update();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (mcMMOPlayer.getWoodcuttingManager().canUseLeafBlower(heldItem) && SkillUtils.triggerCheck(player, block, AbilityType.LEAF_BLOWER)) {
|
||||
event.setInstaBreak(true);
|
||||
player.playSound(blockState.getLocation(), Sound.ITEM_PICKUP, Misc.POP_VOLUME, Misc.getPopPitch());
|
||||
else if (BlockUtils.isLeaves(blockState)) {
|
||||
if (mcMMOPlayer.getWoodcuttingManager().canUseLeafBlower(heldItem) && SkillUtils.blockBreakSimulate(block, player, true)) {
|
||||
event.setInstaBreak(true);
|
||||
player.playSound(blockState.getLocation(), Sound.ITEM_PICKUP, Misc.POP_VOLUME, Misc.getPopPitch());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,13 +28,14 @@ import org.bukkit.event.entity.EntityTameEvent;
|
||||
import org.bukkit.event.entity.EntityTargetEvent;
|
||||
import org.bukkit.event.entity.ExplosionPrimeEvent;
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
import org.bukkit.event.entity.ProjectileLaunchEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.config.WorldConfig;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent;
|
||||
import com.gmail.nossr50.events.fake.FakeEntityDamageEvent;
|
||||
import com.gmail.nossr50.party.PartyManager;
|
||||
@@ -60,32 +61,23 @@ public class EntityListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onEntityShootBow(EntityShootBowEvent event) {
|
||||
Entity projectile = event.getProjectile();
|
||||
|
||||
if (!(projectile instanceof Arrow)) {
|
||||
if (!WorldConfig.getInstance().isSkillEnabled(SkillType.ARCHERY, event.getEntity().getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack bow = event.getBow();
|
||||
|
||||
if (bow != null && bow.containsEnchantment(Enchantment.ARROW_INFINITE)) {
|
||||
projectile.setMetadata(mcMMO.infiniteArrowKey, mcMMO.metadataValue);
|
||||
if (bow != null) {
|
||||
Entity projectile = event.getProjectile();
|
||||
|
||||
if (projectile instanceof Arrow) {
|
||||
if (bow.containsEnchantment(Enchantment.ARROW_INFINITE)) {
|
||||
projectile.setMetadata(mcMMO.infiniteArrowKey, mcMMO.metadataValue);
|
||||
}
|
||||
|
||||
projectile.setMetadata(mcMMO.bowForceKey, new FixedMetadataValue(plugin, Math.min(event.getForce() * AdvancedConfig.getInstance().getForceMultiplier(), 1.0)));
|
||||
projectile.setMetadata(mcMMO.arrowDistanceKey, new FixedMetadataValue(plugin, Archery.locationToString(projectile.getLocation())));
|
||||
}
|
||||
}
|
||||
|
||||
projectile.setMetadata(mcMMO.bowForceKey, new FixedMetadataValue(plugin, Math.min(event.getForce() * AdvancedConfig.getInstance().getForceMultiplier(), 1.0)));
|
||||
projectile.setMetadata(mcMMO.arrowDistanceKey, new FixedMetadataValue(plugin, Archery.locationToString(projectile.getLocation())));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onProjectileLaunch(ProjectileLaunchEvent event) {
|
||||
Projectile projectile = event.getEntity();
|
||||
|
||||
if (!(projectile instanceof Arrow) || projectile.hasMetadata(mcMMO.bowForceKey)) {
|
||||
return;
|
||||
}
|
||||
|
||||
projectile.setMetadata(mcMMO.bowForceKey, new FixedMetadataValue(plugin, 1.0));
|
||||
projectile.setMetadata(mcMMO.arrowDistanceKey, new FixedMetadataValue(plugin, Archery.locationToString(projectile.getLocation())));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,7 +86,7 @@ public class EntityListener implements Listener {
|
||||
* @param event The event to watch
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onEntityChangeBlock(EntityChangeBlockEvent event) {
|
||||
public void onEntityChangeBlockEvent(EntityChangeBlockEvent event) {
|
||||
Entity entity = event.getEntity();
|
||||
|
||||
if (!(entity instanceof FallingBlock)) {
|
||||
@@ -120,13 +112,7 @@ public class EntityListener implements Listener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||
if (event instanceof FakeEntityDamageByEntityEvent) {
|
||||
return;
|
||||
}
|
||||
|
||||
int damage = event.getDamage();
|
||||
|
||||
if (damage <= 0) {
|
||||
if (event instanceof FakeEntityDamageByEntityEvent || event.getDamage() <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -136,14 +122,13 @@ public class EntityListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
Entity attacker = event.getDamager();
|
||||
LivingEntity target = (LivingEntity) defender;
|
||||
|
||||
if (CombatUtils.isInvincible(target, damage)) {
|
||||
if (CombatUtils.isInvincible(target, event.getDamage())) {
|
||||
return;
|
||||
}
|
||||
|
||||
Entity attacker = event.getDamager();
|
||||
|
||||
if (attacker instanceof Projectile) {
|
||||
attacker = ((Projectile) attacker).getShooter();
|
||||
}
|
||||
@@ -170,7 +155,7 @@ public class EntityListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
CombatUtils.processCombatAttack(event, attacker, target);
|
||||
CombatUtils.combatChecks(event, attacker, target);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -180,13 +165,7 @@ public class EntityListener implements Listener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onEntityDamage(EntityDamageEvent event) {
|
||||
if (event instanceof FakeEntityDamageEvent) {
|
||||
return;
|
||||
}
|
||||
|
||||
int damage = event.getDamage();
|
||||
|
||||
if (damage <= 0) {
|
||||
if (event instanceof FakeEntityDamageEvent || event.getDamage() <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -196,14 +175,13 @@ public class EntityListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
DamageCause cause = event.getCause();
|
||||
LivingEntity livingEntity = (LivingEntity) entity;
|
||||
|
||||
if (CombatUtils.isInvincible(livingEntity, damage)) {
|
||||
if (CombatUtils.isInvincible(livingEntity, event.getDamage())) {
|
||||
return;
|
||||
}
|
||||
|
||||
DamageCause cause = event.getCause();
|
||||
|
||||
if (livingEntity instanceof Player) {
|
||||
Player player = (Player) entity;
|
||||
|
||||
@@ -221,6 +199,10 @@ public class EntityListener implements Listener {
|
||||
|
||||
switch (cause) {
|
||||
case FALL:
|
||||
if (!WorldConfig.getInstance().isSkillEnabled(SkillType.ACROBATICS, player.getWorld().getName())) {
|
||||
break;
|
||||
}
|
||||
|
||||
AcrobaticsManager acrobaticsManager = mcMMOPlayer.getAcrobaticsManager();
|
||||
|
||||
if (acrobaticsManager.canRoll()) {
|
||||
@@ -234,6 +216,10 @@ public class EntityListener implements Listener {
|
||||
break;
|
||||
|
||||
case BLOCK_EXPLOSION:
|
||||
if (!WorldConfig.getInstance().isSkillEnabled(SkillType.MINING, player.getWorld().getName())) {
|
||||
break;
|
||||
}
|
||||
|
||||
MiningManager miningManager = mcMMOPlayer.getMiningManager();
|
||||
|
||||
if (miningManager.canUseDemolitionsExpertise()) {
|
||||
@@ -258,6 +244,10 @@ public class EntityListener implements Listener {
|
||||
Tameable pet = (Tameable) livingEntity;
|
||||
AnimalTamer owner = pet.getOwner();
|
||||
|
||||
if (!WorldConfig.getInstance().isSkillEnabled(SkillType.TAMING, livingEntity.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Taming.canPreventDamage(pet, owner)) {
|
||||
Player player = (Player) owner;
|
||||
Wolf wolf = (Wolf) pet;
|
||||
@@ -323,30 +313,6 @@ public class EntityListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Monitor EntityDeath events.
|
||||
*
|
||||
* @param event The event to watch
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onEntityDeathLowest(EntityDeathEvent event) {
|
||||
LivingEntity entity = event.getEntity();
|
||||
|
||||
if (Misc.isNPCEntity(entity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (entity.hasMetadata(mcMMO.customNameKey)) {
|
||||
entity.setCustomName(entity.getMetadata(mcMMO.customNameKey).get(0).asString());
|
||||
entity.removeMetadata(mcMMO.customNameKey, mcMMO.p);
|
||||
}
|
||||
|
||||
if (entity.hasMetadata(mcMMO.customVisibleKey)) {
|
||||
entity.setCustomNameVisible(entity.getMetadata(mcMMO.customVisibleKey).get(0).asBoolean());
|
||||
entity.removeMetadata(mcMMO.customVisibleKey, mcMMO.p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Monitor EntityDeath events.
|
||||
*
|
||||
@@ -360,6 +326,7 @@ public class EntityListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
entity.setFireTicks(0);
|
||||
BleedTimerTask.remove(entity);
|
||||
Archery.arrowRetrievalCheck(entity);
|
||||
}
|
||||
@@ -398,21 +365,23 @@ public class EntityListener implements Listener {
|
||||
public void onExplosionPrime(ExplosionPrimeEvent event) {
|
||||
Entity entity = event.getEntity();
|
||||
|
||||
if (!(entity instanceof TNTPrimed) || !entity.hasMetadata(mcMMO.tntMetadataKey)) {
|
||||
return;
|
||||
}
|
||||
if (entity instanceof TNTPrimed && entity.hasMetadata(mcMMO.tntMetadataKey)) {
|
||||
// We can make this assumption because we (should) be the only ones using this exact metadata
|
||||
Player player = plugin.getServer().getPlayer(entity.getMetadata(mcMMO.tntMetadataKey).get(0).asString());
|
||||
|
||||
// We can make this assumption because we (should) be the only ones using this exact metadata
|
||||
Player player = plugin.getServer().getPlayer(entity.getMetadata(mcMMO.tntMetadataKey).get(0).asString());
|
||||
if (Misc.isNPCEntity(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Misc.isNPCEntity(player)) {
|
||||
return;
|
||||
}
|
||||
if (!WorldConfig.getInstance().isSkillEnabled(SkillType.MINING, entity.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
MiningManager miningManager = UserManager.getPlayer(player).getMiningManager();
|
||||
MiningManager miningManager = UserManager.getPlayer(player).getMiningManager();
|
||||
|
||||
if (miningManager.canUseBiggerBombs()) {
|
||||
event.setRadius(miningManager.biggerBombs(event.getRadius()));
|
||||
if (miningManager.canUseBiggerBombs()) {
|
||||
event.setRadius(miningManager.biggerBombs(event.getRadius()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -422,25 +391,27 @@ public class EntityListener implements Listener {
|
||||
* @param event The event to modify
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onEnitityExplode(EntityExplodeEvent event) {
|
||||
public void onEntityExplode(EntityExplodeEvent event) {
|
||||
Entity entity = event.getEntity();
|
||||
|
||||
if (!(entity instanceof TNTPrimed) || !entity.hasMetadata(mcMMO.tntMetadataKey)) {
|
||||
return;
|
||||
}
|
||||
if (entity instanceof TNTPrimed && entity.hasMetadata(mcMMO.tntMetadataKey)) {
|
||||
// We can make this assumption because we (should) be the only ones using this exact metadata
|
||||
Player player = plugin.getServer().getPlayer(entity.getMetadata(mcMMO.tntMetadataKey).get(0).asString());
|
||||
|
||||
// We can make this assumption because we (should) be the only ones using this exact metadata
|
||||
Player player = plugin.getServer().getPlayer(entity.getMetadata(mcMMO.tntMetadataKey).get(0).asString());
|
||||
if (Misc.isNPCEntity(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Misc.isNPCEntity(player)) {
|
||||
return;
|
||||
}
|
||||
if (!WorldConfig.getInstance().isSkillEnabled(SkillType.MINING, entity.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
MiningManager miningManager = UserManager.getPlayer(player).getMiningManager();
|
||||
MiningManager miningManager = UserManager.getPlayer(player).getMiningManager();
|
||||
|
||||
if (miningManager.canUseBlastMining()) {
|
||||
miningManager.blastMiningDropProcessing(event.getYield(), event.blockList());
|
||||
event.setYield(0);
|
||||
if (miningManager.canUseBlastMining()) {
|
||||
miningManager.blastMiningDropProcessing(event.getYield(), event.blockList());
|
||||
event.setYield(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -453,65 +424,79 @@ public class EntityListener implements Listener {
|
||||
public void onFoodLevelChange(FoodLevelChangeEvent event) {
|
||||
Entity entity = event.getEntity();
|
||||
|
||||
if (!(entity instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
if (entity instanceof Player) {
|
||||
Player player = (Player) entity;
|
||||
|
||||
Player player = (Player) entity;
|
||||
|
||||
if (Misc.isNPCEntity(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int currentFoodLevel = player.getFoodLevel();
|
||||
int newFoodLevel = event.getFoodLevel();
|
||||
int foodChange = newFoodLevel - currentFoodLevel;
|
||||
|
||||
if (foodChange <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Some foods have 3 ranks
|
||||
* Some foods have 5 ranks
|
||||
* The number of ranks is based on how 'common' the item is
|
||||
* We can adjust this quite easily if we find something is giving too much of a bonus
|
||||
*/
|
||||
switch (player.getItemInHand().getType()) {
|
||||
case BAKED_POTATO: /* RESTORES 3 HUNGER - RESTORES 5 1/2 HUNGER @ 1000 */
|
||||
case BREAD: /* RESTORES 2 1/2 HUNGER - RESTORES 5 HUNGER @ 1000 */
|
||||
case CARROT_ITEM: /* RESTORES 2 HUNGER - RESTORES 4 1/2 HUNGER @ 1000 */
|
||||
case GOLDEN_CARROT: /* RESTORES 3 HUNGER - RESTORES 5 1/2 HUNGER @ 1000 */
|
||||
case MUSHROOM_SOUP: /* RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */
|
||||
case PUMPKIN_PIE: /* RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */
|
||||
if (Permissions.farmersDiet(player)) {
|
||||
event.setFoodLevel(UserManager.getPlayer(player).getHerbalismManager().farmersDiet(Herbalism.farmersDietRankLevel1, newFoodLevel));
|
||||
}
|
||||
if (Misc.isNPCEntity(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
case COOKIE: /* RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */
|
||||
case MELON: /* RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
|
||||
case POISONOUS_POTATO: /* RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
|
||||
case POTATO_ITEM: /* RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */
|
||||
if (Permissions.farmersDiet(player)) {
|
||||
event.setFoodLevel(UserManager.getPlayer(player).getHerbalismManager().farmersDiet(Herbalism.farmersDietRankLevel2, newFoodLevel));
|
||||
}
|
||||
return;
|
||||
int currentFoodLevel = player.getFoodLevel();
|
||||
int newFoodLevel = event.getFoodLevel();
|
||||
int foodChange = newFoodLevel - currentFoodLevel;
|
||||
|
||||
case COOKED_FISH: /* RESTORES 2 1/2 HUNGER - RESTORES 5 HUNGER @ 1000 */
|
||||
if (Permissions.fishermansDiet(player)) {
|
||||
event.setFoodLevel(UserManager.getPlayer(player).getFishingManager().handleFishermanDiet(Fishing.fishermansDietRankLevel1, newFoodLevel));
|
||||
}
|
||||
if (foodChange <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
case RAW_FISH: /* RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
|
||||
if (Permissions.fishermansDiet(player)) {
|
||||
event.setFoodLevel(UserManager.getPlayer(player).getFishingManager().handleFishermanDiet(Fishing.fishermansDietRankLevel2, newFoodLevel));
|
||||
}
|
||||
return;
|
||||
/*
|
||||
* Some foods have 3 ranks
|
||||
* Some foods have 5 ranks
|
||||
* The number of ranks is based on how 'common' the item is
|
||||
* We can adjust this quite easily if we find something is giving too much of a bonus
|
||||
*/
|
||||
switch (player.getItemInHand().getType()) {
|
||||
case BAKED_POTATO: /* RESTORES 3 HUNGER - RESTORES 5 1/2 HUNGER @ 1000 */
|
||||
case BREAD: /* RESTORES 2 1/2 HUNGER - RESTORES 5 HUNGER @ 1000 */
|
||||
case CARROT_ITEM: /* RESTORES 2 HUNGER - RESTORES 4 1/2 HUNGER @ 1000 */
|
||||
case GOLDEN_CARROT: /* RESTORES 3 HUNGER - RESTORES 5 1/2 HUNGER @ 1000 */
|
||||
case MUSHROOM_SOUP: /* RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */
|
||||
case PUMPKIN_PIE: /* RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */
|
||||
if (!WorldConfig.getInstance().isSkillEnabled(SkillType.HERBALISM, player.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
default:
|
||||
return;
|
||||
if (Permissions.farmersDiet(player)) {
|
||||
event.setFoodLevel(UserManager.getPlayer(player).getHerbalismManager().farmersDiet(Herbalism.farmersDietRankLevel1, newFoodLevel));
|
||||
}
|
||||
return;
|
||||
|
||||
case COOKIE: /* RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */
|
||||
case MELON: /* RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
|
||||
case POISONOUS_POTATO: /* RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
|
||||
case POTATO_ITEM: /* RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */
|
||||
if (!WorldConfig.getInstance().isSkillEnabled(SkillType.HERBALISM, player.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Permissions.farmersDiet(player)) {
|
||||
event.setFoodLevel(UserManager.getPlayer(player).getHerbalismManager().farmersDiet(Herbalism.farmersDietRankLevel2, newFoodLevel));
|
||||
}
|
||||
return;
|
||||
|
||||
case COOKED_FISH: /* RESTORES 2 1/2 HUNGER - RESTORES 5 HUNGER @ 1000 */
|
||||
if (!WorldConfig.getInstance().isSkillEnabled(SkillType.FISHING, player.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Permissions.fishermansDiet(player)) {
|
||||
event.setFoodLevel(UserManager.getPlayer(player).getFishingManager().handleFishermanDiet(Fishing.fishermansDietRankLevel1, newFoodLevel));
|
||||
}
|
||||
return;
|
||||
|
||||
case RAW_FISH: /* RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
|
||||
if (!WorldConfig.getInstance().isSkillEnabled(SkillType.FISHING, player.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Permissions.fishermansDiet(player)) {
|
||||
event.setFoodLevel(UserManager.getPlayer(player).getFishingManager().handleFishermanDiet(Fishing.fishermansDietRankLevel2, newFoodLevel));
|
||||
}
|
||||
return;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -525,6 +510,10 @@ public class EntityListener implements Listener {
|
||||
Player player = (Player) event.getOwner();
|
||||
LivingEntity entity = event.getEntity();
|
||||
|
||||
if (!WorldConfig.getInstance().isSkillEnabled(SkillType.TAMING, player.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Misc.isNPCEntity(player) || Misc.isNPCEntity(entity) || entity.hasMetadata(mcMMO.entityMetadataKey)) {
|
||||
return;
|
||||
}
|
||||
@@ -542,21 +531,24 @@ public class EntityListener implements Listener {
|
||||
Entity entity = event.getEntity();
|
||||
Entity target = event.getTarget();
|
||||
|
||||
if (!(entity instanceof Tameable) || !(target instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
if (entity instanceof Tameable && target instanceof Player) {
|
||||
Player player = (Player) target;
|
||||
Tameable tameable = (Tameable) entity;
|
||||
|
||||
Player player = (Player) target;
|
||||
Tameable tameable = (Tameable) entity;
|
||||
if (!WorldConfig.getInstance().isSkillEnabled(SkillType.TAMING, player.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!CombatUtils.isFriendlyPet(player, tameable)) {
|
||||
return;
|
||||
}
|
||||
if (!CombatUtils.isFriendlyPet(player, tameable)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// isFriendlyPet ensures that the Tameable is: Tamed, owned by a player, and the owner is in the same party
|
||||
// So we can make some assumptions here, about our casting and our check
|
||||
if (!(Permissions.friendlyFire(player) && Permissions.friendlyFire((Player) tameable.getOwner()))) {
|
||||
event.setCancelled(true);
|
||||
// isFriendlyPet ensures that the Tameable is: Tamed, owned by a player, and the owner is in the same party
|
||||
// So we can make some assumptions here, about our casting and our check
|
||||
if (!(Permissions.friendlyFire(player) && Permissions.friendlyFire((Player) tameable.getOwner()))) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
package com.gmail.nossr50.listeners;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Furnace;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -13,12 +18,17 @@ import org.bukkit.event.inventory.FurnaceSmeltEvent;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.inventory.FurnaceInventory;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.config.WorldConfig;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.runnables.PlayerUpdateInventoryTask;
|
||||
import com.gmail.nossr50.skills.smelting.SmeltingManager;
|
||||
import com.gmail.nossr50.util.ItemUtils;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
@@ -32,22 +42,37 @@ public class InventoryListener implements Listener {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onInventoryOpen(InventoryOpenEvent event) {
|
||||
HumanEntity player = event.getPlayer();
|
||||
|
||||
if (!WorldConfig.getInstance().isSkillEnabled(SkillType.SMELTING, player.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Misc.isNPCEntity(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Block furnaceBlock = Misc.processInventoryOpenorCloseEvent(event);
|
||||
Inventory inventory = event.getInventory();
|
||||
|
||||
if (furnaceBlock != null && !furnaceBlock.hasMetadata(mcMMO.furnaceMetadataKey)) {
|
||||
furnaceBlock.setMetadata(mcMMO.furnaceMetadataKey, new FixedMetadataValue(plugin, player.getName()));
|
||||
if (inventory instanceof FurnaceInventory) {
|
||||
Furnace furnace = (Furnace) inventory.getHolder();
|
||||
|
||||
if (furnace == null) {
|
||||
return;
|
||||
}
|
||||
if (furnace.getBurnTime() == 0) {
|
||||
Block furnaceBlock = furnace.getBlock();
|
||||
|
||||
if (!furnaceBlock.hasMetadata(mcMMO.furnaceMetadataKey)) {
|
||||
furnaceBlock.setMetadata(mcMMO.furnaceMetadataKey, new FixedMetadataValue(plugin, player.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onInventoryClose(InventoryCloseEvent event) {
|
||||
HumanEntity player = event.getPlayer();
|
||||
|
||||
@@ -55,65 +80,117 @@ public class InventoryListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
Block furnaceBlock = Misc.processInventoryOpenorCloseEvent(event);
|
||||
if (!WorldConfig.getInstance().isSkillEnabled(SkillType.SMELTING, player.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (furnaceBlock != null && furnaceBlock.hasMetadata(mcMMO.furnaceMetadataKey)) {
|
||||
furnaceBlock.removeMetadata(mcMMO.furnaceMetadataKey, plugin);
|
||||
Inventory inventory = event.getInventory();
|
||||
|
||||
if (inventory instanceof FurnaceInventory) {
|
||||
Furnace furnace = (Furnace) inventory.getHolder();
|
||||
|
||||
if (furnace == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (furnace.getBurnTime() == 0) {
|
||||
Block furnaceBlock = furnace.getBlock();
|
||||
|
||||
if (furnaceBlock.hasMetadata(mcMMO.furnaceMetadataKey)) {
|
||||
furnaceBlock.removeMetadata(mcMMO.furnaceMetadataKey, plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onFurnaceBurnEvent(FurnaceBurnEvent event) {
|
||||
Block furnaceBlock = event.getBlock();
|
||||
ItemStack smelting = Misc.getSmeltingFromFurnace(furnaceBlock);
|
||||
BlockState furnaceState = furnaceBlock.getState();
|
||||
|
||||
if (!ItemUtils.isSmeltable(smelting)) {
|
||||
if (!WorldConfig.getInstance().isSkillEnabled(SkillType.SMELTING, furnaceState.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = Misc.getPlayerFromFurnace(furnaceBlock);
|
||||
if (furnaceState instanceof Furnace) {
|
||||
ItemStack smelting = ((Furnace) furnaceState).getInventory().getSmelting();
|
||||
List<MetadataValue> metadata = furnaceBlock.getMetadata(mcMMO.furnaceMetadataKey);
|
||||
|
||||
if (Misc.isNPCEntity(player) || !Permissions.fuelEfficiency(player)) {
|
||||
return;
|
||||
if (!metadata.isEmpty() && smelting != null && ItemUtils.isSmeltable(smelting)) {
|
||||
// We can make this assumption because we (should) be the only ones using this exact metadata
|
||||
Player player = plugin.getServer().getPlayer(metadata.get(0).asString());
|
||||
|
||||
if (Misc.isNPCEntity(player) || !Permissions.fuelEfficiency(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setBurnTime(UserManager.getPlayer(player).getSmeltingManager().fuelEfficiency(event.getBurnTime()));
|
||||
}
|
||||
}
|
||||
|
||||
event.setBurnTime(UserManager.getPlayer(player).getSmeltingManager().fuelEfficiency(event.getBurnTime()));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onFurnaceSmeltEvent(FurnaceSmeltEvent event) {
|
||||
Block furnaceBlock = event.getBlock();
|
||||
ItemStack smelting = Misc.getSmeltingFromFurnace(furnaceBlock);
|
||||
BlockState furnaceState = furnaceBlock.getState();
|
||||
|
||||
if (!ItemUtils.isSmeltable(smelting)) {
|
||||
if (!WorldConfig.getInstance().isSkillEnabled(SkillType.SMELTING, furnaceState.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = Misc.getPlayerFromFurnace(furnaceBlock);
|
||||
if (furnaceState instanceof Furnace) {
|
||||
ItemStack smelting = ((Furnace) furnaceState).getInventory().getSmelting();
|
||||
List<MetadataValue> metadata = furnaceBlock.getMetadata(mcMMO.furnaceMetadataKey);
|
||||
|
||||
if (Misc.isNPCEntity(player) || !Permissions.skillEnabled(player, SkillType.SMELTING)) {
|
||||
return;
|
||||
if (Config.getInstance().getPotatoEnabled() && smelting.getType() == Material.POTATO_ITEM) {
|
||||
if ((Config.getInstance().getPotatoChance() / 100.0) >= Misc.getRandom().nextDouble()) {
|
||||
event.setCancelled(true);
|
||||
furnaceState.getWorld().createExplosion(furnaceState.getLocation(), 4F, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!metadata.isEmpty() && smelting != null && ItemUtils.isSmeltable(smelting)) {
|
||||
// We can make this assumption because we (should) be the only ones using this exact metadata
|
||||
Player player = plugin.getServer().getPlayer(metadata.get(0).asString());
|
||||
|
||||
if (Misc.isNPCEntity(player) || !Permissions.skillEnabled(player, SkillType.SMELTING)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setResult(UserManager.getPlayer(player).getSmeltingManager().smeltProcessing(event.getSource().getType(), event.getResult()));
|
||||
}
|
||||
}
|
||||
|
||||
event.setResult(UserManager.getPlayer(player).getSmeltingManager().smeltProcessing(smelting.getType(), event.getResult()));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onFurnaceExtractEvent(FurnaceExtractEvent event) {
|
||||
Block furnaceBlock = event.getBlock();
|
||||
ItemStack result = Misc.getResultFromFurnace(furnaceBlock);
|
||||
BlockState furnaceState = furnaceBlock.getState();
|
||||
|
||||
if (!ItemUtils.isSmelted(result)) {
|
||||
if (!WorldConfig.getInstance().isSkillEnabled(SkillType.SMELTING, furnaceState.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = Misc.getPlayerFromFurnace(furnaceBlock);
|
||||
if (furnaceState instanceof Furnace) {
|
||||
ItemStack result = ((Furnace) furnaceState).getInventory().getResult();
|
||||
List<MetadataValue> metadata = furnaceBlock.getMetadata(mcMMO.furnaceMetadataKey);
|
||||
|
||||
if (Misc.isNPCEntity(player) || !Permissions.vanillaXpBoost(player, SkillType.SMELTING)) {
|
||||
return;
|
||||
if (!metadata.isEmpty() && result != null && ItemUtils.isSmelted(result)) {
|
||||
// We can make this assumption because we (should) be the only ones using this exact metadata
|
||||
Player player = plugin.getServer().getPlayer(metadata.get(0).asString());
|
||||
|
||||
if (Misc.isNPCEntity(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SmeltingManager smeltingManager = UserManager.getPlayer(player).getSmeltingManager();
|
||||
|
||||
if (smeltingManager.canUseVanillaXpBoost()) {
|
||||
event.setExpToDrop(smeltingManager.vanillaXPBoost(event.getExpToDrop()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
event.setExpToDrop(UserManager.getPlayer(player).getSmeltingManager().vanillaXPBoost(event.getExpToDrop()));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
@@ -123,18 +200,18 @@ public class InventoryListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onCraftItem(CraftItemEvent event) {
|
||||
ItemStack result = event.getRecipe().getResult();
|
||||
final HumanEntity whoClicked = event.getWhoClicked();
|
||||
|
||||
if (Misc.isNPCEntity(whoClicked) || !(whoClicked instanceof Player)) {
|
||||
if (!ItemUtils.isMcMMOItem(result) || Misc.isNPCEntity(whoClicked) || !(whoClicked instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack result = event.getRecipe().getResult();
|
||||
|
||||
if (!ItemUtils.isMcMMOItem(result)) {
|
||||
return;
|
||||
}
|
||||
|
||||
new PlayerUpdateInventoryTask((Player) whoClicked).runTaskLater(plugin, 0);
|
||||
mcMMO.p.getServer().getScheduler().runTaskLater(mcMMO.p, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
((Player) whoClicked).updateInventory();
|
||||
}
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
@@ -23,6 +22,7 @@ import org.bukkit.event.player.PlayerFishEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
import org.bukkit.event.player.PlayerLoginEvent.Result;
|
||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
@@ -30,17 +30,15 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.chat.ChatManager;
|
||||
import com.gmail.nossr50.chat.ChatManagerFactory;
|
||||
import com.gmail.nossr50.chat.ChatMode;
|
||||
import com.gmail.nossr50.chat.PartyChatManager;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.config.WorldConfig;
|
||||
import com.gmail.nossr50.datatypes.party.Party;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.skills.AbilityType;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.events.fake.FakeBlockBreakEvent;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.party.ShareHandler;
|
||||
import com.gmail.nossr50.runnables.skills.AbilityDisableTask;
|
||||
import com.gmail.nossr50.runnables.skills.BleedTimerTask;
|
||||
import com.gmail.nossr50.skills.fishing.FishingManager;
|
||||
import com.gmail.nossr50.skills.herbalism.HerbalismManager;
|
||||
@@ -129,6 +127,37 @@ public class PlayerListener implements Listener {
|
||||
mcMMOPlayer.removeParty();
|
||||
player.sendMessage(LocaleLoader.getString("Party.Forbidden"));
|
||||
}
|
||||
|
||||
for (AbilityType abilityType : AbilityType.values()) {
|
||||
if (mcMMOPlayer.getAbilityMode(abilityType)) {
|
||||
if (!WorldConfig.getInstance().isAbilityEnabled(SkillType.byAbility(abilityType), player.getWorld().getName())) {
|
||||
// Make sure to handle any important deactivation processes
|
||||
new AbilityDisableTask(mcMMOPlayer, abilityType).run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Monitor PlayerLogin events.
|
||||
*
|
||||
* @param event The event to watch
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerLogin(PlayerLoginEvent event) {
|
||||
if (event.getResult() != Result.ALLOWED) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (Misc.isNPCEntity(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
UserManager.addUser(player).actualizeRespawnATS();
|
||||
ScoreboardManager.enablePowerLevelDisplay(player);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,6 +182,10 @@ public class PlayerListener implements Listener {
|
||||
public void onPlayerFish(PlayerFishEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (!WorldConfig.getInstance().isSkillEnabled(SkillType.FISHING, player.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Misc.isNPCEntity(player) || !Permissions.skillEnabled(player, SkillType.FISHING)) {
|
||||
return;
|
||||
}
|
||||
@@ -163,10 +196,10 @@ public class PlayerListener implements Listener {
|
||||
case FISHING:
|
||||
if (!Permissions.krakenBypass(player)) {
|
||||
event.setCancelled(fishingManager.exploitPrevention());
|
||||
}
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (fishingManager.canMasterAngler()) {
|
||||
@@ -192,16 +225,9 @@ public class PlayerListener implements Listener {
|
||||
|
||||
case IN_GROUND:
|
||||
Fish hook = event.getHook();
|
||||
Block block = event.getPlayer().getTargetBlock(null, 100);
|
||||
Block block = hook.getLocation().getBlock();
|
||||
|
||||
if (fishingManager.canIceFish(block)) {
|
||||
FakeBlockBreakEvent blockBreakEvent = new FakeBlockBreakEvent(block, player);
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(blockBreakEvent);
|
||||
|
||||
if (blockBreakEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
fishingManager.iceFishing(hook, block);
|
||||
}
|
||||
@@ -266,24 +292,6 @@ public class PlayerListener implements Listener {
|
||||
BleedTimerTask.bleedOut(player); // Bleed it out
|
||||
}
|
||||
|
||||
/**
|
||||
* Start user data prefetch.
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onLoginStart(PlayerLoginEvent event) {
|
||||
UserManager.prefetchUserData(event.getPlayer().getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel user data prefetch if a plugin kicks them.
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false)
|
||||
public void onLoginComplete(PlayerLoginEvent event) {
|
||||
if (event.getResult() != PlayerLoginEvent.Result.ALLOWED) {
|
||||
UserManager.discardPrefetch(event.getPlayer().getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Monitor PlayerJoin events.
|
||||
*
|
||||
@@ -293,13 +301,6 @@ public class PlayerListener implements Listener {
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (Misc.isNPCEntity(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
UserManager.addUser(player).actualizeRespawnATS();
|
||||
ScoreboardManager.enablePowerLevelDisplay(player);
|
||||
|
||||
if (Config.getInstance().getMOTDEnabled() && Permissions.motd(player)) {
|
||||
Motd.displayAll(player);
|
||||
}
|
||||
@@ -358,32 +359,42 @@ public class PlayerListener implements Listener {
|
||||
case RIGHT_CLICK_BLOCK:
|
||||
int blockID = block.getTypeId();
|
||||
|
||||
if ((Config.getInstance().getAbilitiesOnlyActivateWhenSneaking() && player.isSneaking()) || !Config.getInstance().getAbilitiesOnlyActivateWhenSneaking()) {
|
||||
/* REPAIR CHECKS */
|
||||
if (blockID == Repair.repairAnvilId && Permissions.skillEnabled(player, SkillType.REPAIR) && mcMMO.getRepairableManager().isRepairable(heldItem)) {
|
||||
RepairManager repairManager = mcMMOPlayer.getRepairManager();
|
||||
event.setCancelled(true);
|
||||
|
||||
// Make sure the player knows what he's doing when trying to repair an enchanted item
|
||||
if (!(heldItem.getEnchantments().size() > 0) || repairManager.checkConfirmation(blockID, true)) {
|
||||
repairManager.handleRepair(heldItem);
|
||||
player.updateInventory();
|
||||
}
|
||||
/* REPAIR CHECKS */
|
||||
if (blockID == Repair.repairAnvilId && Permissions.skillEnabled(player, SkillType.REPAIR) && mcMMO.getRepairableManager().isRepairable(heldItem)) {
|
||||
if (!WorldConfig.getInstance().isSkillEnabled(SkillType.REPAIR, player.getWorld().getName())) {
|
||||
break;
|
||||
}
|
||||
/* SALVAGE CHECKS */
|
||||
else if (blockID == Repair.salvageAnvilId && Permissions.salvage(player) && Repair.isSalvageable(heldItem)) {
|
||||
RepairManager repairManager = mcMMOPlayer.getRepairManager();
|
||||
event.setCancelled(true);
|
||||
|
||||
// Make sure the player knows what he's doing when trying to salvage an enchanted item
|
||||
if (!(heldItem.getEnchantments().size() > 0) || repairManager.checkConfirmation(blockID, true)) {
|
||||
repairManager.handleSalvage(block.getLocation(), heldItem);
|
||||
player.updateInventory();
|
||||
}
|
||||
RepairManager repairManager = mcMMOPlayer.getRepairManager();
|
||||
event.setCancelled(true);
|
||||
|
||||
// Make sure the player knows what he's doing when trying to repair an enchanted item
|
||||
if (!(heldItem.getEnchantments().size() > 0) || repairManager.checkConfirmation(blockID, true)) {
|
||||
repairManager.handleRepair(heldItem);
|
||||
player.updateInventory();
|
||||
}
|
||||
}
|
||||
/* SALVAGE CHECKS */
|
||||
else if (blockID == Repair.salvageAnvilId && Permissions.salvage(player) && Repair.isSalvageable(heldItem) && !ItemUtils.isChainmailArmor(heldItem)) {
|
||||
if (!WorldConfig.getInstance().isSkillEnabled(SkillType.REPAIR, player.getWorld().getName())) {
|
||||
break;
|
||||
}
|
||||
|
||||
RepairManager repairManager = mcMMOPlayer.getRepairManager();
|
||||
event.setCancelled(true);
|
||||
|
||||
// Make sure the player knows what he's doing when trying to salvage an enchanted item
|
||||
if (!(heldItem.getEnchantments().size() > 0) || repairManager.checkConfirmation(blockID, true)) {
|
||||
repairManager.handleSalvage(block.getLocation(), heldItem);
|
||||
player.updateInventory();
|
||||
}
|
||||
}
|
||||
/* BLAST MINING CHECK */
|
||||
else if (miningManager.canDetonate()) {
|
||||
if (!WorldConfig.getInstance().isSkillEnabled(SkillType.MINING, player.getWorld().getName())) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (blockID == Material.TNT.getId()) {
|
||||
event.setCancelled(true); // Don't detonate the TNT if they're too close
|
||||
}
|
||||
@@ -397,32 +408,38 @@ public class PlayerListener implements Listener {
|
||||
case LEFT_CLICK_BLOCK:
|
||||
blockID = block.getTypeId();
|
||||
|
||||
if ((Config.getInstance().getAbilitiesOnlyActivateWhenSneaking() && player.isSneaking()) || !Config.getInstance().getAbilitiesOnlyActivateWhenSneaking()) {
|
||||
/* REPAIR CHECKS */
|
||||
if (blockID == Repair.repairAnvilId && Permissions.skillEnabled(player, SkillType.REPAIR) && mcMMO.getRepairableManager().isRepairable(heldItem)) {
|
||||
RepairManager repairManager = mcMMOPlayer.getRepairManager();
|
||||
if (!WorldConfig.getInstance().isSkillEnabled(SkillType.REPAIR, player.getWorld().getName())) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Cancel repairing an enchanted item
|
||||
if (repairManager.checkConfirmation(blockID, false) && Config.getInstance().getRepairConfirmRequired()) {
|
||||
mcMMOPlayer.setLastAnvilUse(Repair.repairAnvilId, 0);
|
||||
player.sendMessage(LocaleLoader.getString("Skills.Cancelled", LocaleLoader.getString("Repair.Pretty.Name")));
|
||||
}
|
||||
/* REPAIR CHECKS */
|
||||
if (blockID == Repair.repairAnvilId && Permissions.skillEnabled(player, SkillType.REPAIR) && mcMMO.getRepairableManager().isRepairable(heldItem)) {
|
||||
RepairManager repairManager = mcMMOPlayer.getRepairManager();
|
||||
|
||||
// Cancel repairing an enchanted item
|
||||
if (repairManager.checkConfirmation(blockID, false) && Config.getInstance().getRepairConfirmRequired()) {
|
||||
mcMMOPlayer.setLastAnvilUse(Repair.repairAnvilId, 0);
|
||||
player.sendMessage(LocaleLoader.getString("Skills.Cancelled", LocaleLoader.getString("Repair.Pretty.Name")));
|
||||
}
|
||||
/* SALVAGE CHECKS */
|
||||
else if (blockID == Repair.salvageAnvilId && Permissions.salvage(player) && Repair.isSalvageable(heldItem)) {
|
||||
RepairManager repairManager = mcMMOPlayer.getRepairManager();
|
||||
}
|
||||
/* SALVAGE CHECKS */
|
||||
else if (blockID == Repair.salvageAnvilId && Permissions.salvage(player) && Repair.isSalvageable(heldItem)) {
|
||||
RepairManager repairManager = mcMMOPlayer.getRepairManager();
|
||||
|
||||
// Cancel salvaging an enchanted item
|
||||
if (repairManager.checkConfirmation(blockID, false) && Config.getInstance().getRepairConfirmRequired()) {
|
||||
mcMMOPlayer.setLastAnvilUse(Repair.salvageAnvilId, 0);
|
||||
player.sendMessage(LocaleLoader.getString("Skills.Cancelled", LocaleLoader.getString("Salvage.Pretty.Name")));
|
||||
}
|
||||
// Cancel salvaging an enchanted item
|
||||
if (repairManager.checkConfirmation(blockID, false) && Config.getInstance().getRepairConfirmRequired()) {
|
||||
mcMMOPlayer.setLastAnvilUse(Repair.salvageAnvilId, 0);
|
||||
player.sendMessage(LocaleLoader.getString("Skills.Cancelled", LocaleLoader.getString("Salvage.Pretty.Name")));
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case RIGHT_CLICK_AIR:
|
||||
if (!WorldConfig.getInstance().isSkillEnabled(SkillType.MINING, player.getWorld().getName())) {
|
||||
break;
|
||||
}
|
||||
|
||||
/* BLAST MINING CHECK */
|
||||
if (miningManager.canDetonate()) {
|
||||
miningManager.remoteDetonation();
|
||||
@@ -479,6 +496,10 @@ public class PlayerListener implements Listener {
|
||||
ChimaeraWing.activationCheck(player);
|
||||
}
|
||||
|
||||
if (!WorldConfig.getInstance().isSkillEnabled(SkillType.HERBALISM, player.getWorld().getName())) {
|
||||
break;
|
||||
}
|
||||
|
||||
/* GREEN THUMB CHECK */
|
||||
HerbalismManager herbalismManager = mcMMOPlayer.getHerbalismManager();
|
||||
|
||||
@@ -519,6 +540,10 @@ public class PlayerListener implements Listener {
|
||||
case LEFT_CLICK_AIR:
|
||||
case LEFT_CLICK_BLOCK:
|
||||
|
||||
if (!WorldConfig.getInstance().isSkillEnabled(SkillType.TAMING, player.getWorld().getName())) {
|
||||
break;
|
||||
}
|
||||
|
||||
/* CALL OF THE WILD CHECKS */
|
||||
if (player.isSneaking() && Permissions.callOfTheWild(player)) {
|
||||
Material type = heldItem.getType();
|
||||
@@ -559,8 +584,6 @@ public class PlayerListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
ChatManager chatManager = null;
|
||||
|
||||
if (mcMMOPlayer.getPartyChatMode()) {
|
||||
Party party = mcMMOPlayer.getParty();
|
||||
|
||||
@@ -570,15 +593,11 @@ public class PlayerListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
chatManager = ChatManagerFactory.getChatManager(plugin, ChatMode.PARTY);
|
||||
((PartyChatManager) chatManager).setParty(party);
|
||||
ChatManager.handlePartyChat(plugin, party, player.getName(), player.getDisplayName(), event.getMessage(), event.isAsynchronous());
|
||||
event.setCancelled(true);
|
||||
}
|
||||
else if (mcMMOPlayer.getAdminChatMode()) {
|
||||
chatManager = ChatManagerFactory.getChatManager(plugin, ChatMode.ADMIN);
|
||||
}
|
||||
|
||||
if (chatManager != null) {
|
||||
chatManager.handleChat(player, event.getMessage(), event.isAsynchronous());
|
||||
ChatManager.handleAdminChat(plugin, player.getName(), player.getDisplayName(), event.getMessage(), event.isAsynchronous());
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -18,7 +19,8 @@ import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.blockmeta.conversion.BlockStoreConversionMain;
|
||||
|
||||
public class WorldListener implements Listener {
|
||||
private final ArrayList<BlockStoreConversionMain> converters = new ArrayList<BlockStoreConversionMain>();
|
||||
private ArrayList<BlockStoreConversionMain> converters = new ArrayList<BlockStoreConversionMain>();
|
||||
|
||||
private final mcMMO plugin;
|
||||
|
||||
public WorldListener(final mcMMO plugin) {
|
||||
@@ -32,12 +34,12 @@ public class WorldListener implements Listener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onStructureGrow(StructureGrowEvent event) {
|
||||
if (!mcMMO.getPlaceStore().isTrue(event.getLocation().getBlock())) {
|
||||
return;
|
||||
}
|
||||
Location location = event.getLocation();
|
||||
|
||||
for (BlockState blockState : event.getBlocks()) {
|
||||
mcMMO.getPlaceStore().setFalse(blockState);
|
||||
if (mcMMO.getPlaceStore().isTrue(location.getBlockX(), location.getBlockY(), location.getBlockZ(), location.getWorld())) {
|
||||
for (BlockState blockState : event.getBlocks()) {
|
||||
mcMMO.getPlaceStore().setFalse(blockState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,8 +51,9 @@ public class WorldListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onWorldInit(WorldInitEvent event) {
|
||||
World world = event.getWorld();
|
||||
File dataDir = new File(world.getWorldFolder(), "mcmmo_data");
|
||||
|
||||
if (!new File(world.getWorldFolder(), "mcmmo_data").exists() || plugin == null) {
|
||||
if (!dataDir.exists() || plugin == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.config.HiddenConfig;
|
||||
import com.gmail.nossr50.config.WorldConfig;
|
||||
import com.gmail.nossr50.config.mods.CustomArmorConfig;
|
||||
import com.gmail.nossr50.config.mods.CustomBlockConfig;
|
||||
import com.gmail.nossr50.config.mods.CustomEntityConfig;
|
||||
@@ -23,7 +24,6 @@ import com.gmail.nossr50.config.mods.CustomToolConfig;
|
||||
import com.gmail.nossr50.config.spout.SpoutConfig;
|
||||
import com.gmail.nossr50.config.treasure.TreasureConfig;
|
||||
import com.gmail.nossr50.database.DatabaseManager;
|
||||
import com.gmail.nossr50.database.DatabaseManagerFactory;
|
||||
import com.gmail.nossr50.listeners.BlockListener;
|
||||
import com.gmail.nossr50.listeners.EntityListener;
|
||||
import com.gmail.nossr50.listeners.InventoryListener;
|
||||
@@ -35,7 +35,6 @@ import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.metrics.MetricsManager;
|
||||
import com.gmail.nossr50.party.PartyManager;
|
||||
import com.gmail.nossr50.runnables.SaveTimerTask;
|
||||
import com.gmail.nossr50.runnables.UpdateCheckerTask;
|
||||
import com.gmail.nossr50.runnables.database.UserPurgeTask;
|
||||
import com.gmail.nossr50.runnables.party.PartyAutoKickTask;
|
||||
import com.gmail.nossr50.runnables.skills.BleedTimerTask;
|
||||
@@ -46,8 +45,8 @@ import com.gmail.nossr50.skills.repair.RepairableManagerFactory;
|
||||
import com.gmail.nossr50.skills.repair.config.RepairConfigManager;
|
||||
import com.gmail.nossr50.util.ChimaeraWing;
|
||||
import com.gmail.nossr50.util.LogFilter;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.UpdateChecker;
|
||||
import com.gmail.nossr50.util.blockmeta.chunkmeta.ChunkManager;
|
||||
import com.gmail.nossr50.util.blockmeta.chunkmeta.ChunkManagerFactory;
|
||||
import com.gmail.nossr50.util.commands.CommandRegistrationManager;
|
||||
@@ -111,7 +110,7 @@ public class mcMMO extends JavaPlugin {
|
||||
|
||||
combatTagEnabled = getServer().getPluginManager().getPlugin("CombatTag") != null;
|
||||
|
||||
databaseManager = DatabaseManagerFactory.getDatabaseManager();
|
||||
databaseManager = new DatabaseManager(this, Config.getInstance().getUseMySQL());
|
||||
|
||||
registerEvents();
|
||||
registerCustomRecipes();
|
||||
@@ -229,17 +228,12 @@ public class mcMMO extends JavaPlugin {
|
||||
return placeStore;
|
||||
}
|
||||
|
||||
public static RepairableManager getRepairableManager() {
|
||||
return repairableManager;
|
||||
}
|
||||
|
||||
public static DatabaseManager getDatabaseManager() {
|
||||
return databaseManager;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void setDatabaseManager(DatabaseManager databaseManager) {
|
||||
mcMMO.databaseManager = databaseManager;
|
||||
public static RepairableManager getRepairableManager() {
|
||||
return repairableManager;
|
||||
}
|
||||
|
||||
public static boolean isSpoutEnabled() {
|
||||
@@ -262,43 +256,45 @@ public class mcMMO extends JavaPlugin {
|
||||
}
|
||||
|
||||
private void checkForUpdates() {
|
||||
if (!Config.getInstance().getUpdateCheckEnabled()) {
|
||||
return;
|
||||
}
|
||||
if (Config.getInstance().getUpdateCheckEnabled()) {
|
||||
try {
|
||||
updateAvailable = UpdateChecker.updateAvailable();
|
||||
}
|
||||
catch (Exception e) {
|
||||
updateAvailable = false;
|
||||
}
|
||||
|
||||
getServer().getScheduler().runTaskAsynchronously(this, new UpdateCheckerTask());
|
||||
}
|
||||
|
||||
public void updateCheckerCallback(boolean updateAvailable) {
|
||||
this.updateAvailable = updateAvailable;
|
||||
if (updateAvailable) {
|
||||
getLogger().info(LocaleLoader.getString("UpdateChecker.outdated"));
|
||||
getLogger().info(LocaleLoader.getString("UpdateChecker.newavailable"));
|
||||
if (updateAvailable) {
|
||||
getLogger().info(LocaleLoader.getString("UpdateChecker.outdated"));
|
||||
getLogger().info(LocaleLoader.getString("UpdateChecker.newavailable"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadConfigFiles() {
|
||||
// Force the loading of config files
|
||||
Config configInstance = Config.getInstance();
|
||||
TreasureConfig.getInstance();
|
||||
HiddenConfig.getInstance();
|
||||
AdvancedConfig.getInstance();
|
||||
WorldConfig.getInstance();
|
||||
new ChildConfig();
|
||||
|
||||
List<Repairable> repairables = new ArrayList<Repairable>();
|
||||
|
||||
if (Config.getInstance().getToolModsEnabled()) {
|
||||
if (configInstance.getToolModsEnabled()) {
|
||||
repairables.addAll(CustomToolConfig.getInstance().getLoadedRepairables());
|
||||
}
|
||||
|
||||
if (Config.getInstance().getArmorModsEnabled()) {
|
||||
if (configInstance.getArmorModsEnabled()) {
|
||||
repairables.addAll(CustomArmorConfig.getInstance().getLoadedRepairables());
|
||||
}
|
||||
|
||||
if (Config.getInstance().getBlockModsEnabled()) {
|
||||
if (configInstance.getBlockModsEnabled()) {
|
||||
CustomBlockConfig.getInstance();
|
||||
}
|
||||
|
||||
if (Config.getInstance().getEntityModsEnabled()) {
|
||||
if (configInstance.getEntityModsEnabled()) {
|
||||
CustomEntityConfig.getInstance();
|
||||
}
|
||||
|
||||
@@ -309,22 +305,21 @@ public class mcMMO extends JavaPlugin {
|
||||
repairableManager.registerRepairables(repairables);
|
||||
|
||||
// Check if Repair Anvil and Salvage Anvil have different itemID's
|
||||
if (Config.getInstance().getSalvageAnvilId() == Config.getInstance().getRepairAnvilId()) {
|
||||
if (configInstance.getSalvageAnvilId() == configInstance.getRepairAnvilId()) {
|
||||
getLogger().warning("Can't use the same itemID for Repair/Salvage Anvils!");
|
||||
}
|
||||
}
|
||||
|
||||
private void setupSpout() {
|
||||
if (!getServer().getPluginManager().isPluginEnabled("Spout")) {
|
||||
return;
|
||||
// Check for Spout
|
||||
if (getServer().getPluginManager().isPluginEnabled("Spout")) {
|
||||
spoutEnabled = true;
|
||||
|
||||
SpoutConfig.getInstance();
|
||||
getServer().getPluginManager().registerEvents(new SpoutListener(), this);
|
||||
SpoutUtils.preCacheFiles();
|
||||
SpoutUtils.reloadSpoutPlayers(); // Handle spout players after a /reload
|
||||
}
|
||||
|
||||
spoutEnabled = true;
|
||||
|
||||
SpoutConfig.getInstance();
|
||||
getServer().getPluginManager().registerEvents(new SpoutListener(), this);
|
||||
SpoutUtils.preCacheFiles();
|
||||
SpoutUtils.reloadSpoutPlayers(); // Handle spout players after a /reload
|
||||
}
|
||||
|
||||
private void registerEvents() {
|
||||
@@ -351,23 +346,23 @@ public class mcMMO extends JavaPlugin {
|
||||
new SaveTimerTask().runTaskTimer(this, saveIntervalTicks, saveIntervalTicks);
|
||||
|
||||
// Bleed timer (Runs every two seconds)
|
||||
new BleedTimerTask().runTaskTimer(this, 2 * Misc.TICK_CONVERSION_FACTOR, 2 * Misc.TICK_CONVERSION_FACTOR);
|
||||
new BleedTimerTask().runTaskTimer(this, 40, 40);
|
||||
|
||||
// Old & Powerless User remover
|
||||
long purgeIntervalTicks = Config.getInstance().getPurgeInterval() * 60 * 60 * Misc.TICK_CONVERSION_FACTOR;
|
||||
long purgeIntervalTicks = Config.getInstance().getPurgeInterval() * 60 * 60 * 20;
|
||||
|
||||
if (purgeIntervalTicks == 0) {
|
||||
new UserPurgeTask().runTaskLater(this, 2 * Misc.TICK_CONVERSION_FACTOR); // Start 2 seconds after startup.
|
||||
new UserPurgeTask().runTaskLater(this, 40); // Start 2 seconds after startup.
|
||||
}
|
||||
else if (purgeIntervalTicks > 0) {
|
||||
new UserPurgeTask().runTaskTimer(this, purgeIntervalTicks, purgeIntervalTicks);
|
||||
}
|
||||
|
||||
// Automatically remove old members from parties
|
||||
long kickIntervalTicks = Config.getInstance().getAutoPartyKickInterval() * 60 * 60 * Misc.TICK_CONVERSION_FACTOR;
|
||||
long kickIntervalTicks = Config.getInstance().getAutoPartyKickInterval() * 60 * 60 * 20;
|
||||
|
||||
if (kickIntervalTicks == 0) {
|
||||
new PartyAutoKickTask().runTaskLater(this, 2 * Misc.TICK_CONVERSION_FACTOR); // Start 2 seconds after startup.
|
||||
new PartyAutoKickTask().runTaskLater(this, 40); // Start 2 seconds after startup.
|
||||
}
|
||||
else if (kickIntervalTicks > 0) {
|
||||
new PartyAutoKickTask().runTaskTimer(this, kickIntervalTicks, kickIntervalTicks);
|
||||
|
||||
@@ -64,11 +64,14 @@ public final class PartyManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (firstMcMMOPlayer.getParty() == null || secondMcMMOPlayer.getParty() == null) {
|
||||
Party firstParty = firstMcMMOPlayer.getParty();
|
||||
Party secondParty = secondMcMMOPlayer.getParty();
|
||||
|
||||
if (firstParty == null || secondParty == null || firstParty != secondParty) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return firstMcMMOPlayer.getParty().equals(secondMcMMOPlayer.getParty());
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,15 +83,13 @@ public final class PartyManager {
|
||||
*/
|
||||
public static List<Player> getNearMembers(Player player, Party party, double range) {
|
||||
List<Player> nearMembers = new ArrayList<Player>();
|
||||
|
||||
if (party != null) {
|
||||
for (Player member : party.getOnlineMembers()) {
|
||||
if (!player.equals(member) && member.isValid() && Misc.isNear(player.getLocation(), member.getLocation(), range)) {
|
||||
if (!player.getName().equalsIgnoreCase(member.getName()) && !member.isDead() && Misc.isNear(player.getLocation(), member.getLocation(), range)) {
|
||||
nearMembers.add(member);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nearMembers;
|
||||
}
|
||||
|
||||
@@ -99,9 +100,13 @@ public final class PartyManager {
|
||||
* @return all the players in the player's party
|
||||
*/
|
||||
public static LinkedHashSet<String> getAllMembers(Player player) {
|
||||
Party party = getPlayerParty(player.getName());
|
||||
Party party = UserManager.getPlayer(player).getParty();
|
||||
|
||||
return party == null ? null : party.getMembers();
|
||||
if (party == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return party.getMembers();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,7 +116,13 @@ public final class PartyManager {
|
||||
* @return all online players in this party
|
||||
*/
|
||||
public static List<Player> getOnlineMembers(String partyName) {
|
||||
return getOnlineMembers(getParty(partyName));
|
||||
Party party = getParty(partyName);
|
||||
|
||||
if (party == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return party.getOnlineMembers();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,11 +132,13 @@ public final class PartyManager {
|
||||
* @return all online players in this party
|
||||
*/
|
||||
public static List<Player> getOnlineMembers(Player player) {
|
||||
return getOnlineMembers(getPlayerParty(player.getName()));
|
||||
}
|
||||
Party party = getPlayerParty(player.getName());
|
||||
|
||||
private static List<Player> getOnlineMembers(Party party) {
|
||||
return party == null ? null : party.getOnlineMembers();
|
||||
if (party == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return getOnlineMembers(party.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -179,24 +192,29 @@ public final class PartyManager {
|
||||
*/
|
||||
public static void removeFromParty(OfflinePlayer player, Party party) {
|
||||
LinkedHashSet<String> members = party.getMembers();
|
||||
String playerName = player.getName();
|
||||
|
||||
members.remove(playerName);
|
||||
members.remove(player.getName());
|
||||
|
||||
if (members.isEmpty()) {
|
||||
parties.remove(party);
|
||||
}
|
||||
else {
|
||||
// If the leaving player was the party leader, appoint a new leader from the party members
|
||||
if (party.getLeader().equalsIgnoreCase(playerName)) {
|
||||
if (party.getLeader().equalsIgnoreCase(player.getName())) {
|
||||
String newLeader = members.iterator().next();
|
||||
party.setLeader(newLeader);
|
||||
}
|
||||
|
||||
informPartyMembersQuit(party, playerName);
|
||||
informPartyMembersQuit(player, party);
|
||||
}
|
||||
|
||||
processPartyLeaving(UserManager.getPlayer(player));
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player.getName());
|
||||
|
||||
if (mcMMOPlayer != null) {
|
||||
mcMMOPlayer.removeParty();
|
||||
mcMMOPlayer.setPartyChat(false);
|
||||
mcMMOPlayer.setItemShareModifier(10);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -205,10 +223,19 @@ public final class PartyManager {
|
||||
* @param party The party to remove
|
||||
*/
|
||||
public static void disbandParty(Party party) {
|
||||
for (String memberName : party.getMembers()) {
|
||||
processPartyLeaving(UserManager.getPlayer(memberName));
|
||||
LinkedHashSet<String> members = party.getMembers();
|
||||
|
||||
for (String memberName : members) {
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(memberName);
|
||||
|
||||
if (mcMMOPlayer != null) {
|
||||
mcMMOPlayer.removeParty();
|
||||
mcMMOPlayer.setPartyChat(false);
|
||||
mcMMOPlayer.setItemShareModifier(10);
|
||||
}
|
||||
}
|
||||
|
||||
members.clear();
|
||||
parties.remove(party);
|
||||
}
|
||||
|
||||
@@ -222,25 +249,29 @@ public final class PartyManager {
|
||||
*/
|
||||
public static void createParty(Player player, McMMOPlayer mcMMOPlayer, String partyName, String password) {
|
||||
partyName = partyName.replace(".", "");
|
||||
|
||||
Party party = getParty(partyName);
|
||||
String playerName = player.getName();
|
||||
|
||||
if (party != null) {
|
||||
if (party == null) {
|
||||
party = new Party();
|
||||
|
||||
party.setName(partyName);
|
||||
party.setLeader(player.getName());
|
||||
party.setLocked(true); // Parties are now invite-only by default, can be set to open with /party unlock
|
||||
|
||||
if (password != null) {
|
||||
party.setPassword(password);
|
||||
player.sendMessage(LocaleLoader.getString("Party.Password.Set", password));
|
||||
}
|
||||
|
||||
parties.add(party);
|
||||
}
|
||||
else {
|
||||
player.sendMessage(LocaleLoader.getString("Commands.Party.AlreadyExists"));
|
||||
return;
|
||||
}
|
||||
|
||||
party = new Party(playerName, partyName, password);
|
||||
|
||||
if (password != null) {
|
||||
player.sendMessage(LocaleLoader.getString("Party.Password.Set", password));
|
||||
}
|
||||
|
||||
parties.add(party);
|
||||
|
||||
player.sendMessage(LocaleLoader.getString("Commands.Party.Create", party.getName()));
|
||||
addToParty(playerName, mcMMOPlayer, party);
|
||||
addToParty(player, mcMMOPlayer, party);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -252,12 +283,16 @@ public final class PartyManager {
|
||||
* @param password the password for this party, null if there was no password
|
||||
*/
|
||||
public static void joinParty(Player player, McMMOPlayer mcMMOPlayer, Party party, String password) {
|
||||
if (!checkPartyPassword(player, party, password) || mcMMOPlayer.getParty() == party) {
|
||||
if (!checkPartyPassword(player, party, password)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mcMMOPlayer.getParty() == party) {
|
||||
return;
|
||||
}
|
||||
|
||||
player.sendMessage(LocaleLoader.getString("Commands.Party.Join", party.getName()));
|
||||
addToParty(player.getName(), mcMMOPlayer, party);
|
||||
addToParty(player, mcMMOPlayer, party);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -269,28 +304,27 @@ public final class PartyManager {
|
||||
* @return true if the player can join the party
|
||||
*/
|
||||
public static boolean checkPartyPassword(Player player, Party party, String password) {
|
||||
if (!party.isLocked()) {
|
||||
return true;
|
||||
// Don't care about passwords if it isn't locked
|
||||
if (party.isLocked()) {
|
||||
String partyPassword = party.getPassword();
|
||||
|
||||
if (partyPassword != null) {
|
||||
if (password == null) {
|
||||
player.sendMessage(LocaleLoader.getString("Party.Password.None"));
|
||||
return false;
|
||||
}
|
||||
else if (!password.equals(partyPassword)) {
|
||||
player.sendMessage(LocaleLoader.getString("Party.Password.Incorrect"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
player.sendMessage(LocaleLoader.getString("Party.Locked"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
String partyPassword = party.getPassword();
|
||||
|
||||
if (partyPassword == null) {
|
||||
player.sendMessage(LocaleLoader.getString("Party.Locked"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (password == null) {
|
||||
player.sendMessage(LocaleLoader.getString("Party.Password.None"));
|
||||
return false;
|
||||
}
|
||||
else if (!password.equals(partyPassword)) {
|
||||
player.sendMessage(LocaleLoader.getString("Party.Password.Incorrect"));
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -312,7 +346,7 @@ public final class PartyManager {
|
||||
|
||||
player.sendMessage(LocaleLoader.getString("Commands.Invite.Accepted", invite.getName()));
|
||||
mcMMOPlayer.removePartyInvite();
|
||||
addToParty(player.getName(), mcMMOPlayer, invite);
|
||||
addToParty(player, mcMMOPlayer, invite);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -322,15 +356,15 @@ public final class PartyManager {
|
||||
* @param mcMMOPlayer The player to add to the party
|
||||
* @param party The party
|
||||
*/
|
||||
public static void addToParty(String playerName, McMMOPlayer mcMMOPlayer, Party party) {
|
||||
public static void addToParty(OfflinePlayer player, McMMOPlayer mcMMOPlayer, Party party) {
|
||||
if (mcMMOPlayer.getParty() == party) {
|
||||
return;
|
||||
}
|
||||
|
||||
informPartyMembersJoin(party, playerName);
|
||||
informPartyMembersJoin(player, party);
|
||||
mcMMOPlayer.setParty(party);
|
||||
|
||||
party.getMembers().add(playerName);
|
||||
party.getMembers().add(player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -381,7 +415,11 @@ public final class PartyManager {
|
||||
* @return true if the player can invite
|
||||
*/
|
||||
public static boolean canInvite(Player player, Party party) {
|
||||
return !(party.isLocked() && !party.getLeader().equalsIgnoreCase(player.getName()));
|
||||
if (party.isLocked() && !party.getLeader().equalsIgnoreCase(player.getName())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -391,7 +429,13 @@ public final class PartyManager {
|
||||
* @return true if this is a valid party, false otherwise
|
||||
*/
|
||||
public static boolean isParty(String partyName) {
|
||||
return getParty(partyName) != null;
|
||||
for (Party party : parties) {
|
||||
if (party.getName().equals(partyName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -405,8 +449,9 @@ public final class PartyManager {
|
||||
YamlConfiguration partiesFile = YamlConfiguration.loadConfiguration(partyFile);
|
||||
|
||||
for (String partyName : partiesFile.getConfigurationSection("").getKeys(false)) {
|
||||
Party party = new Party(partyName);
|
||||
Party party = new Party();
|
||||
|
||||
party.setName(partyName);
|
||||
party.setLeader(partiesFile.getString(partyName + ".Leader"));
|
||||
party.setPassword(partiesFile.getString(partyName + ".Password"));
|
||||
party.setLocked(partiesFile.getBoolean(partyName + ".Locked"));
|
||||
@@ -479,36 +524,30 @@ public final class PartyManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify party members when a player joins.
|
||||
* Notify party members when a player joins
|
||||
*
|
||||
* @param player The player that joins
|
||||
* @param party The concerned party
|
||||
* @param playerName The name of the player that joined
|
||||
*/
|
||||
private static void informPartyMembersJoin(Party party, String playerName) {
|
||||
private static void informPartyMembersJoin(OfflinePlayer player, Party party) {
|
||||
for (Player member : party.getOnlineMembers()) {
|
||||
member.sendMessage(LocaleLoader.getString("Party.InformedOnJoin", playerName));
|
||||
if (!member.equals(player)) {
|
||||
member.sendMessage(LocaleLoader.getString("Party.InformedOnJoin", player.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify party members when a party member quits.
|
||||
*
|
||||
* @param player The player that quits
|
||||
* @param party The concerned party
|
||||
* @param playerName The name of the player that left
|
||||
*/
|
||||
private static void informPartyMembersQuit(Party party, String playerName) {
|
||||
private static void informPartyMembersQuit(OfflinePlayer player, Party party) {
|
||||
for (Player member : party.getOnlineMembers()) {
|
||||
member.sendMessage(LocaleLoader.getString("Party.InformedOnQuit", playerName));
|
||||
if (!member.equals(player)) {
|
||||
member.sendMessage(LocaleLoader.getString("Party.InformedOnQuit", player.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void processPartyLeaving(McMMOPlayer mcMMOPlayer) {
|
||||
if (mcMMOPlayer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
mcMMOPlayer.removeParty();
|
||||
mcMMOPlayer.setPartyChat(false);
|
||||
mcMMOPlayer.setItemShareModifier(10);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,12 @@ public final class ShareHandler {
|
||||
}
|
||||
|
||||
double partySize = nearMembers.size() + 1;
|
||||
double shareBonus = Math.min(Config.getInstance().getPartyShareBonusBase() + partySize * Config.getInstance().getPartyShareBonusIncrease(), Config.getInstance().getPartyShareBonusCap());
|
||||
double shareBonus = Config.getInstance().getPartyShareBonusBase() + partySize * Config.getInstance().getPartyShareBonusIncrease();
|
||||
|
||||
if (shareBonus > Config.getInstance().getPartyShareBonusCap()) {
|
||||
shareBonus = Config.getInstance().getPartyShareBonusCap();
|
||||
}
|
||||
|
||||
float splitXp = (float) (xp / partySize * shareBonus);
|
||||
|
||||
for (Player member : nearMembers) {
|
||||
@@ -73,6 +78,7 @@ public final class ShareHandler {
|
||||
}
|
||||
|
||||
mcMMOPlayer.beginUnsharedXpGain(skillType, splitXp);
|
||||
|
||||
return true;
|
||||
|
||||
case NONE:
|
||||
@@ -90,43 +96,32 @@ public final class ShareHandler {
|
||||
*/
|
||||
public static boolean handleItemShare(Item drop, McMMOPlayer mcMMOPlayer) {
|
||||
ItemStack itemStack = drop.getItemStack();
|
||||
ItemShareType dropType = ItemShareType.getShareType(itemStack);
|
||||
|
||||
if (dropType == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Party party = mcMMOPlayer.getParty();
|
||||
|
||||
if (!party.sharingDrops(dropType)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ShareMode shareMode = party.getItemShareMode();
|
||||
|
||||
if (shareMode == ShareMode.NONE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
|
||||
nearMembers = PartyManager.getNearMembers(player, party, Config.getInstance().getPartyShareRange());
|
||||
|
||||
if (nearMembers.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Player winningPlayer = null;
|
||||
|
||||
ItemStack newStack = itemStack.clone();
|
||||
|
||||
nearMembers.add(player);
|
||||
partySize = nearMembers.size();
|
||||
|
||||
drop.remove();
|
||||
newStack.setAmount(1);
|
||||
|
||||
switch (shareMode) {
|
||||
ItemShareType dropType = ItemShareType.getShareType(itemStack);
|
||||
|
||||
if (dropType == null || !party.sharingDrops(dropType)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (party.getItemShareMode()) {
|
||||
case EQUAL:
|
||||
McMMOPlayer mcMMOTarget;
|
||||
nearMembers = PartyManager.getNearMembers(player, party, Config.getInstance().getPartyShareRange());
|
||||
|
||||
if (nearMembers.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
nearMembers.add(player);
|
||||
partySize = nearMembers.size();
|
||||
|
||||
drop.remove();
|
||||
int itemWeight = ItemWeightConfig.getInstance().getItemWeight(itemStack.getType());
|
||||
|
||||
for (int i = 0; i < itemStack.getAmount(); i++) {
|
||||
@@ -137,46 +132,64 @@ public final class ShareHandler {
|
||||
int itemShareModifier = mcMMOMember.getItemShareModifier();
|
||||
int diceRoll = Misc.getRandom().nextInt(itemShareModifier);
|
||||
|
||||
if (diceRoll <= highestRoll) {
|
||||
if (diceRoll > highestRoll) {
|
||||
highestRoll = diceRoll;
|
||||
|
||||
if (winningPlayer != null) {
|
||||
McMMOPlayer mcMMOWinning = UserManager.getPlayer(winningPlayer);
|
||||
mcMMOWinning.setItemShareModifier(mcMMOWinning.getItemShareModifier() + itemWeight);
|
||||
}
|
||||
|
||||
winningPlayer = member;
|
||||
}
|
||||
else {
|
||||
mcMMOMember.setItemShareModifier(itemShareModifier + itemWeight);
|
||||
continue;
|
||||
}
|
||||
|
||||
highestRoll = diceRoll;
|
||||
|
||||
if (winningPlayer != null) {
|
||||
McMMOPlayer mcMMOWinning = UserManager.getPlayer(winningPlayer);
|
||||
mcMMOWinning.setItemShareModifier(mcMMOWinning.getItemShareModifier() + itemWeight);
|
||||
}
|
||||
|
||||
winningPlayer = member;
|
||||
}
|
||||
|
||||
McMMOPlayer mcMMOTarget = UserManager.getPlayer(winningPlayer);
|
||||
mcMMOTarget = UserManager.getPlayer(winningPlayer);
|
||||
mcMMOTarget.setItemShareModifier(mcMMOTarget.getItemShareModifier() - itemWeight);
|
||||
awardDrop(winningPlayer, newStack);
|
||||
}
|
||||
|
||||
if (winningPlayer.getInventory().addItem(newStack).size() != 0) {
|
||||
winningPlayer.getWorld().dropItemNaturally(winningPlayer.getLocation(), newStack);
|
||||
}
|
||||
|
||||
winningPlayer.updateInventory();
|
||||
}
|
||||
return true;
|
||||
|
||||
case RANDOM:
|
||||
for (int i = 0; i < itemStack.getAmount(); i++) {
|
||||
winningPlayer = nearMembers.get(Misc.getRandom().nextInt(partySize));
|
||||
awardDrop(winningPlayer, newStack);
|
||||
nearMembers = PartyManager.getNearMembers(player, party, Config.getInstance().getPartyShareRange());
|
||||
|
||||
if (nearMembers.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
partySize = nearMembers.size() + 1;
|
||||
|
||||
drop.remove();
|
||||
|
||||
for (int i = 0; i < itemStack.getAmount(); i++) {
|
||||
int randomMember = Misc.getRandom().nextInt(partySize);
|
||||
|
||||
if (randomMember >= nearMembers.size()) {
|
||||
winningPlayer = player;
|
||||
}
|
||||
else {
|
||||
winningPlayer = nearMembers.get(randomMember);
|
||||
}
|
||||
|
||||
if (winningPlayer.getInventory().addItem(newStack).size() != 0) {
|
||||
winningPlayer.getWorld().dropItemNaturally(winningPlayer.getLocation(), newStack);
|
||||
}
|
||||
|
||||
winningPlayer.updateInventory();
|
||||
}
|
||||
return true;
|
||||
|
||||
case NONE:
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static void awardDrop(Player winningPlayer, ItemStack drop) {
|
||||
if (winningPlayer.getInventory().addItem(drop).size() != 0) {
|
||||
winningPlayer.getWorld().dropItemNaturally(winningPlayer.getLocation(), drop);
|
||||
}
|
||||
|
||||
winningPlayer.updateInventory();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
package com.gmail.nossr50.runnables;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class PlayerUpdateInventoryTask extends BukkitRunnable {
|
||||
private Player player;
|
||||
|
||||
public PlayerUpdateInventoryTask(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
player.updateInventory();
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package com.gmail.nossr50.runnables;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.UpdateChecker;
|
||||
|
||||
/**
|
||||
* Async task
|
||||
*/
|
||||
public class UpdateCheckerTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
mcMMO.p.updateCheckerCallback(UpdateChecker.updateAvailable());
|
||||
}
|
||||
catch (Exception e) {
|
||||
mcMMO.p.updateCheckerCallback(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,9 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.database.FlatfileDatabaseManager;
|
||||
import com.gmail.nossr50.database.SQLDatabaseManager;
|
||||
|
||||
public class McrankCommandAsyncTask extends BukkitRunnable {
|
||||
private final String playerName;
|
||||
@@ -18,9 +21,8 @@ public class McrankCommandAsyncTask extends BukkitRunnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Map<String, Integer> skills = mcMMO.getDatabaseManager().readRank(playerName);
|
||||
Map<String, Integer> skills = Config.getInstance().getUseMySQL() ? SQLDatabaseManager.readSQLRank(playerName) : FlatfileDatabaseManager.getPlayerRanks(playerName);
|
||||
|
||||
new McrankCommandDisplayTask(skills, sender, playerName).runTaskLater(mcMMO.p, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,8 +31,8 @@ public class McrankCommandDisplayTask extends BukkitRunnable {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Heading"));
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Player", playerName));
|
||||
|
||||
for (SkillType skill : SkillType.nonChildSkills()) {
|
||||
if (player != null && !Permissions.skillEnabled(player, skill)) {
|
||||
for (SkillType skill : SkillType.values()) {
|
||||
if (skill.isChildSkill() || (player != null && !Permissions.skillEnabled(player, skill))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,28 +1,31 @@
|
||||
package com.gmail.nossr50.runnables.commands;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.database.PlayerStat;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.database.SQLDatabaseManager;
|
||||
|
||||
public class MctopCommandAsyncTask extends BukkitRunnable {
|
||||
private CommandSender sender;
|
||||
private String skill;
|
||||
private String query;
|
||||
private int page;
|
||||
|
||||
public MctopCommandAsyncTask(int page, String skill, CommandSender sender) {
|
||||
public MctopCommandAsyncTask(int page, String query, CommandSender sender) {
|
||||
this.page = page;
|
||||
this.skill = skill;
|
||||
this.query = query.equalsIgnoreCase("ALL") ? "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing" : query;
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
final List<PlayerStat> userStats = mcMMO.getDatabaseManager().readLeaderboard(skill, page, 10);
|
||||
String tablePrefix = Config.getInstance().getMySQLTablePrefix();
|
||||
final Collection<ArrayList<String>> userStats = SQLDatabaseManager.read("SELECT " + query + ", user, NOW() FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON (user_id = id) WHERE " + query + " > 0 ORDER BY " + query + " DESC, user LIMIT " + ((page * 10) - 10) + ",10").values();
|
||||
|
||||
new MctopCommandDisplayTask(userStats, page, skill, sender).runTaskLater(mcMMO.p, 1);
|
||||
new MctopCommandDisplayTask(userStats, page, tablePrefix, sender).runTaskLater(mcMMO.p, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,44 +1,44 @@
|
||||
package com.gmail.nossr50.runnables.commands;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.gmail.nossr50.datatypes.database.PlayerStat;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.util.StringUtils;
|
||||
|
||||
public class MctopCommandDisplayTask extends BukkitRunnable {
|
||||
private List<PlayerStat> userStats;
|
||||
private Collection<ArrayList<String>> userStats;
|
||||
private CommandSender sender;
|
||||
private String skill;
|
||||
private String query;
|
||||
private int page;
|
||||
|
||||
public MctopCommandDisplayTask(List<PlayerStat> userStats, int page, String skill, CommandSender sender) {
|
||||
public MctopCommandDisplayTask(Collection<ArrayList<String>> userStats, int page, String query, CommandSender sender) {
|
||||
this.userStats = userStats;
|
||||
this.page = page;
|
||||
this.skill = skill;
|
||||
this.query = query;
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (skill.equalsIgnoreCase("all")) {
|
||||
if (query.equalsIgnoreCase("taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing")) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Leaderboard"));
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Leaderboard", StringUtils.getCapitalized(skill)));
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Leaderboard", StringUtils.getCapitalized(query)));
|
||||
}
|
||||
|
||||
int place = (page * 10) - 9;
|
||||
|
||||
for (PlayerStat stat : userStats) {
|
||||
String digit = ((place < 10) ? "0" : "") + String.valueOf(place);
|
||||
for (ArrayList<String> stat : userStats) {
|
||||
String digit = (place < 10) ? "0" : "" + String.valueOf(place);
|
||||
|
||||
// Format: 1. Playername - skill value
|
||||
sender.sendMessage(digit + ". " + ChatColor.GREEN + stat.name + " - " + ChatColor.WHITE + stat.statVal);
|
||||
sender.sendMessage(digit + ". " + ChatColor.GREEN + stat.get(1) + " - " + ChatColor.WHITE + stat.get(0));
|
||||
place++;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
package com.gmail.nossr50.runnables.database;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.database.DatabaseManager;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
|
||||
public class ConversionTask extends BukkitRunnable {
|
||||
private final DatabaseManager sourceDb;
|
||||
private final CommandSender sender;
|
||||
private final String message;
|
||||
|
||||
public ConversionTask(DatabaseManager from, CommandSender sendback, String oldType, String newType) {
|
||||
sourceDb = from;
|
||||
sender = sendback;
|
||||
message = LocaleLoader.getString("Commands.mmoupdate.Finish", oldType, newType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
sourceDb.convertUsers(mcMMO.getDatabaseManager());
|
||||
|
||||
// Announce completeness
|
||||
mcMMO.p.getServer().getScheduler().runTask(mcMMO.p, new CompleteAnnouncement());
|
||||
}
|
||||
|
||||
public class CompleteAnnouncement implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
sender.sendMessage(message);
|
||||
} catch (Exception e) {
|
||||
mcMMO.p.getLogger().log(Level.WARNING, "Exception sending database conversion completion message to " + sender.getName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,279 @@
|
||||
package com.gmail.nossr50.runnables.database;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.database.SQLDatabaseManager;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.StringUtils;
|
||||
|
||||
public class SQLConversionTask extends BukkitRunnable {
|
||||
private String tablePrefix = Config.getInstance().getMySQLTablePrefix();
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
String location = mcMMO.getUsersFilePath();
|
||||
|
||||
try {
|
||||
FileReader file = new FileReader(location);
|
||||
BufferedReader in = new BufferedReader(file);
|
||||
String line = "";
|
||||
String playerName = null;
|
||||
String mining = null;
|
||||
String woodcutting = null;
|
||||
String repair = null;
|
||||
String unarmed = null;
|
||||
String herbalism = null;
|
||||
String excavation = null;
|
||||
String archery = null;
|
||||
String swords = null;
|
||||
String axes = null;
|
||||
String acrobatics = null;
|
||||
String taming = null;
|
||||
String fishing = null;
|
||||
String miningXP = null;
|
||||
String woodCuttingXP = null;
|
||||
String repairXP = null;
|
||||
String unarmedXP = null;
|
||||
String herbalismXP = null;
|
||||
String excavationXP = null;
|
||||
String archeryXP = null;
|
||||
String swordsXP = null;
|
||||
String axesXP = null;
|
||||
String acrobaticsXP = null;
|
||||
String tamingXP = null;
|
||||
String fishingXP = null;
|
||||
int id = 0;
|
||||
int theCount = 0;
|
||||
|
||||
while ((line = in.readLine()) != null) {
|
||||
|
||||
// Find if the line contains the player we want.
|
||||
String[] character = line.split(":");
|
||||
playerName = character[0];
|
||||
|
||||
// Check for things we don't want put in the DB
|
||||
if (playerName == null || playerName.equalsIgnoreCase("null") || playerName.equalsIgnoreCase("#Storage place for user information")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (character.length > 1) {
|
||||
mining = character[1];
|
||||
}
|
||||
|
||||
if (character.length > 4) {
|
||||
miningXP = character[4];
|
||||
}
|
||||
|
||||
if (character.length > 5) {
|
||||
woodcutting = character[5];
|
||||
}
|
||||
|
||||
if (character.length > 6) {
|
||||
woodCuttingXP = character[6];
|
||||
}
|
||||
|
||||
if (character.length > 7) {
|
||||
repair = character[7];
|
||||
}
|
||||
|
||||
if (character.length > 8) {
|
||||
unarmed = character[8];
|
||||
}
|
||||
|
||||
if (character.length > 9) {
|
||||
herbalism = character[9];
|
||||
}
|
||||
|
||||
if (character.length > 10) {
|
||||
excavation = character[10];
|
||||
}
|
||||
|
||||
if (character.length > 11) {
|
||||
archery = character[11];
|
||||
}
|
||||
|
||||
if (character.length > 12) {
|
||||
swords = character[12];
|
||||
}
|
||||
|
||||
if (character.length > 13) {
|
||||
axes = character[13];
|
||||
}
|
||||
|
||||
if (character.length > 14) {
|
||||
acrobatics = character[14];
|
||||
}
|
||||
|
||||
if (character.length > 15) {
|
||||
repairXP = character[15];
|
||||
}
|
||||
|
||||
if (character.length > 16) {
|
||||
unarmedXP = character[16];
|
||||
}
|
||||
|
||||
if (character.length > 17) {
|
||||
herbalismXP = character[17];
|
||||
}
|
||||
|
||||
if (character.length > 18) {
|
||||
excavationXP = character[18];
|
||||
}
|
||||
|
||||
if (character.length > 19) {
|
||||
archeryXP = character[19];
|
||||
}
|
||||
|
||||
if (character.length > 20) {
|
||||
swordsXP = character[20];
|
||||
}
|
||||
|
||||
if (character.length > 21) {
|
||||
axesXP = character[21];
|
||||
}
|
||||
|
||||
if (character.length > 22) {
|
||||
acrobaticsXP = character[22];
|
||||
}
|
||||
|
||||
if (character.length > 24) {
|
||||
taming = character[24];
|
||||
}
|
||||
|
||||
if (character.length > 25) {
|
||||
tamingXP = character[25];
|
||||
}
|
||||
|
||||
if (character.length > 34) {
|
||||
fishing = character[34];
|
||||
}
|
||||
|
||||
if (character.length > 35) {
|
||||
fishingXP = character[35];
|
||||
}
|
||||
|
||||
// Check to see if the user is in the DB
|
||||
id = SQLDatabaseManager.getInt("SELECT id FROM "
|
||||
+ tablePrefix
|
||||
+ "users WHERE user = '" + playerName + "'");
|
||||
|
||||
if (id > 0) {
|
||||
theCount++;
|
||||
|
||||
// Update the skill values
|
||||
SQLDatabaseManager.write("UPDATE "
|
||||
+ tablePrefix
|
||||
+ "users SET lastlogin = " + 0
|
||||
+ " WHERE id = " + id);
|
||||
SQLDatabaseManager.write("UPDATE "
|
||||
+ tablePrefix
|
||||
+ "skills SET "
|
||||
+ " taming = taming+" + StringUtils.getInt(taming)
|
||||
+ ", mining = mining+" + StringUtils.getInt(mining)
|
||||
+ ", repair = repair+" + StringUtils.getInt(repair)
|
||||
+ ", woodcutting = woodcutting+" + StringUtils.getInt(woodcutting)
|
||||
+ ", unarmed = unarmed+" + StringUtils.getInt(unarmed)
|
||||
+ ", herbalism = herbalism+" + StringUtils.getInt(herbalism)
|
||||
+ ", excavation = excavation+" + StringUtils.getInt(excavation)
|
||||
+ ", archery = archery+" + StringUtils.getInt(archery)
|
||||
+ ", swords = swords+" + StringUtils.getInt(swords)
|
||||
+ ", axes = axes+" + StringUtils.getInt(axes)
|
||||
+ ", acrobatics = acrobatics+" + StringUtils.getInt(acrobatics)
|
||||
+ ", fishing = fishing+" + StringUtils.getInt(fishing)
|
||||
+ " WHERE user_id = " + id);
|
||||
SQLDatabaseManager.write("UPDATE "
|
||||
+ tablePrefix
|
||||
+ "experience SET "
|
||||
+ " taming = " + StringUtils.getInt(tamingXP)
|
||||
+ ", mining = " + StringUtils.getInt(miningXP)
|
||||
+ ", repair = " + StringUtils.getInt(repairXP)
|
||||
+ ", woodcutting = " + StringUtils.getInt(woodCuttingXP)
|
||||
+ ", unarmed = " + StringUtils.getInt(unarmedXP)
|
||||
+ ", herbalism = " + StringUtils.getInt(herbalismXP)
|
||||
+ ", excavation = " + StringUtils.getInt(excavationXP)
|
||||
+ ", archery = " + StringUtils.getInt(archeryXP)
|
||||
+ ", swords = " + StringUtils.getInt(swordsXP)
|
||||
+ ", axes = " + StringUtils.getInt(axesXP)
|
||||
+ ", acrobatics = " + StringUtils.getInt(acrobaticsXP)
|
||||
+ ", fishing = " + StringUtils.getInt(fishingXP)
|
||||
+ " WHERE user_id = " + id);
|
||||
}
|
||||
else {
|
||||
theCount++;
|
||||
|
||||
// Create the user in the DB
|
||||
SQLDatabaseManager.write("INSERT INTO "
|
||||
+ tablePrefix
|
||||
+ "users (user, lastlogin) VALUES ('"
|
||||
+ playerName + "',"
|
||||
+ System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR + ")");
|
||||
id = SQLDatabaseManager.getInt("SELECT id FROM "
|
||||
+ tablePrefix
|
||||
+ "users WHERE user = '"
|
||||
+ playerName + "'");
|
||||
SQLDatabaseManager.write("INSERT INTO "
|
||||
+ tablePrefix
|
||||
+ "skills (user_id) VALUES (" + id + ")");
|
||||
SQLDatabaseManager.write("INSERT INTO "
|
||||
+ tablePrefix
|
||||
+ "experience (user_id) VALUES (" + id
|
||||
+ ")");
|
||||
// Update the skill values
|
||||
SQLDatabaseManager.write("UPDATE "
|
||||
+ tablePrefix
|
||||
+ "users SET lastlogin = " + 0
|
||||
+ " WHERE id = " + id);
|
||||
/*
|
||||
Database.write("UPDATE "
|
||||
+ tablePrefix
|
||||
+ "users SET party = '" + party
|
||||
+ "' WHERE id = " + id);
|
||||
*/
|
||||
SQLDatabaseManager.write("UPDATE "
|
||||
+ tablePrefix
|
||||
+ "skills SET "
|
||||
+ " taming = taming+" + StringUtils.getInt(taming)
|
||||
+ ", mining = mining+" + StringUtils.getInt(mining)
|
||||
+ ", repair = repair+" + StringUtils.getInt(repair)
|
||||
+ ", woodcutting = woodcutting+" + StringUtils.getInt(woodcutting)
|
||||
+ ", unarmed = unarmed+" + StringUtils.getInt(unarmed)
|
||||
+ ", herbalism = herbalism+" + StringUtils.getInt(herbalism)
|
||||
+ ", excavation = excavation+" + StringUtils.getInt(excavation)
|
||||
+ ", archery = archery+" + StringUtils.getInt(archery)
|
||||
+ ", swords = swords+" + StringUtils.getInt(swords)
|
||||
+ ", axes = axes+" + StringUtils.getInt(axes)
|
||||
+ ", acrobatics = acrobatics+" + StringUtils.getInt(acrobatics)
|
||||
+ ", fishing = fishing+" + StringUtils.getInt(fishing)
|
||||
+ " WHERE user_id = " + id);
|
||||
SQLDatabaseManager.write("UPDATE "
|
||||
+ tablePrefix
|
||||
+ "experience SET "
|
||||
+ " taming = " + StringUtils.getInt(tamingXP)
|
||||
+ ", mining = " + StringUtils.getInt(miningXP)
|
||||
+ ", repair = " + StringUtils.getInt(repairXP)
|
||||
+ ", woodcutting = " + StringUtils.getInt(woodCuttingXP)
|
||||
+ ", unarmed = " + StringUtils.getInt(unarmedXP)
|
||||
+ ", herbalism = " + StringUtils.getInt(herbalismXP)
|
||||
+ ", excavation = " + StringUtils.getInt(excavationXP)
|
||||
+ ", archery = " + StringUtils.getInt(archeryXP)
|
||||
+ ", swords = " + StringUtils.getInt(swordsXP)
|
||||
+ ", axes = " + StringUtils.getInt(axesXP)
|
||||
+ ", acrobatics = " + StringUtils.getInt(acrobaticsXP)
|
||||
+ ", fishing = " + StringUtils.getInt(fishingXP)
|
||||
+ " WHERE user_id = " + id);
|
||||
}
|
||||
}
|
||||
|
||||
mcMMO.p.getLogger().info("[mcMMO] MySQL Updated from users file, " + theCount + " items added/updated to MySQL DB");
|
||||
in.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
mcMMO.p.getLogger().severe("Exception while reading " + location + " (Are you sure you formatted it correctly?)" + e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import com.gmail.nossr50.util.player.UserManager;
|
||||
public class SQLReconnectTask extends BukkitRunnable {
|
||||
@Override
|
||||
public void run() {
|
||||
if (((SQLDatabaseManager) mcMMO.getDatabaseManager()).checkConnected()) {
|
||||
if (SQLDatabaseManager.checkConnected()) {
|
||||
UserManager.saveAll(); // Save all profiles
|
||||
UserManager.clearAll(); // Clear the profiles
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@ public class ChimaeraWingWarmup extends BukkitRunnable {
|
||||
private void checkChimaeraWingTeleport() {
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
Location previousLocation = mcMMOPlayer.getTeleportCommenceLocation();
|
||||
long recentlyHurt = mcMMOPlayer.getRecentlyHurt();
|
||||
ItemStack inHand = player.getItemInHand();
|
||||
|
||||
mcMMOPlayer.setTeleportCommenceLocation(null);
|
||||
|
||||
@@ -36,23 +38,16 @@ public class ChimaeraWingWarmup extends BukkitRunnable {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack inHand = player.getItemInHand();
|
||||
|
||||
if (!ItemUtils.isChimaeraWing(inHand) || inHand.getAmount() < Config.getInstance().getChimaeraUseCost()) {
|
||||
player.sendMessage(LocaleLoader.getString("Skills.NeedMore", LocaleLoader.getString("Item.ChimaeraWing.Name")));
|
||||
return;
|
||||
}
|
||||
|
||||
long recentlyHurt = mcMMOPlayer.getRecentlyHurt();
|
||||
int hurtCooldown = Config.getInstance().getChimaeraRecentlyHurtCooldown();
|
||||
int recentlyhurt_cooldown = Config.getInstance().getChimaeraRecentlyHurtCooldown();
|
||||
|
||||
if (hurtCooldown > 0) {
|
||||
int timeRemaining = SkillUtils.calculateTimeLeft(recentlyHurt * Misc.TIME_CONVERSION_FACTOR, hurtCooldown, player);
|
||||
|
||||
if (timeRemaining > 0) {
|
||||
player.sendMessage(LocaleLoader.getString("Item.Injured.Wait", timeRemaining));
|
||||
return;
|
||||
}
|
||||
if (!SkillUtils.cooldownOver(recentlyHurt * Misc.TIME_CONVERSION_FACTOR, recentlyhurt_cooldown, player)) {
|
||||
player.sendMessage(LocaleLoader.getString("Item.Injured.Wait", SkillUtils.calculateTimeLeft(recentlyHurt * Misc.TIME_CONVERSION_FACTOR, recentlyhurt_cooldown, player)));
|
||||
return;
|
||||
}
|
||||
|
||||
ChimaeraWing.chimaeraExecuteTeleport();
|
||||
|
||||
@@ -47,15 +47,11 @@ public class TeleportationWarmup extends BukkitRunnable {
|
||||
return;
|
||||
}
|
||||
|
||||
int hurtCooldown = Config.getInstance().getPTPCommandRecentlyHurtCooldown();
|
||||
int recentlyhurt_cooldown = Config.getInstance().getPTPCommandRecentlyHurtCooldown();
|
||||
|
||||
if (hurtCooldown > 0) {
|
||||
int timeRemaining = SkillUtils.calculateTimeLeft(recentlyHurt * Misc.TIME_CONVERSION_FACTOR, hurtCooldown, teleportingPlayer);
|
||||
|
||||
if (timeRemaining > 0) {
|
||||
teleportingPlayer.sendMessage(LocaleLoader.getString("Item.Injured.Wait", timeRemaining));
|
||||
return;
|
||||
}
|
||||
if (!SkillUtils.cooldownOver(recentlyHurt * Misc.TIME_CONVERSION_FACTOR, recentlyhurt_cooldown, teleportingPlayer)) {
|
||||
teleportingPlayer.sendMessage(LocaleLoader.getString("Item.Injured.Wait", SkillUtils.calculateTimeLeft(recentlyHurt * Misc.TIME_CONVERSION_FACTOR, recentlyhurt_cooldown, teleportingPlayer)));
|
||||
return;
|
||||
}
|
||||
|
||||
PtpCommand.handlePartyTeleportEvent(teleportingPlayer, targetPlayer);
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.gmail.nossr50.runnables.party;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
@@ -14,25 +15,29 @@ import com.gmail.nossr50.datatypes.party.Party;
|
||||
import com.gmail.nossr50.party.PartyManager;
|
||||
|
||||
public class PartyAutoKickTask extends BukkitRunnable {
|
||||
private final static long KICK_TIME = 24L * 60L * 60L * 1000L * Config.getInstance().getAutoPartyKickTime();
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
updatePartyMembers();
|
||||
}
|
||||
|
||||
private void updatePartyMembers() {
|
||||
HashMap<OfflinePlayer, Party> toRemove = new HashMap<OfflinePlayer, Party>();
|
||||
List<String> processedPlayers = new ArrayList<String>();
|
||||
|
||||
long currentTime = System.currentTimeMillis();
|
||||
long kickTime = 24L * 60L * 60L * 1000L * Config.getInstance().getAutoPartyKickTime();
|
||||
|
||||
for (Iterator<Party> partyIterator = PartyManager.getParties().iterator(); partyIterator.hasNext();) {
|
||||
Party party = partyIterator.next();
|
||||
|
||||
for (Party party : PartyManager.getParties()) {
|
||||
for (String memberName : party.getMembers()) {
|
||||
OfflinePlayer member = mcMMO.p.getServer().getOfflinePlayer(memberName);
|
||||
boolean isProcessed = processedPlayers.contains(memberName);
|
||||
|
||||
if ((!member.isOnline() && (currentTime - member.getLastPlayed() > KICK_TIME)) || isProcessed) {
|
||||
if ((currentTime - member.getLastPlayed() > kickTime) || processedPlayers.contains(memberName)) {
|
||||
toRemove.put(member, party);
|
||||
}
|
||||
|
||||
if (!isProcessed) {
|
||||
if (!processedPlayers.contains(memberName)) {
|
||||
processedPlayers.add(memberName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
package com.gmail.nossr50.runnables.player;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
|
||||
public class PlayerProfileLoader implements Callable<PlayerProfile> {
|
||||
private final String playerName;
|
||||
|
||||
public PlayerProfileLoader(String player) {
|
||||
this.playerName = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerProfile call() {
|
||||
return mcMMO.getDatabaseManager().loadPlayerProfile(playerName, true);
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,6 @@ import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityDeactivateEvent;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.skills.ParticleEffectUtils;
|
||||
import com.gmail.nossr50.util.skills.PerksUtils;
|
||||
import com.gmail.nossr50.util.skills.SkillUtils;
|
||||
|
||||
public class AbilityDisableTask extends BukkitRunnable {
|
||||
@@ -60,6 +59,6 @@ public class AbilityDisableTask extends BukkitRunnable {
|
||||
}
|
||||
|
||||
SkillUtils.sendSkillMessage(player, ability.getAbilityPlayerOff(player));
|
||||
new AbilityCooldownTask(mcMMOPlayer, ability).runTaskLaterAsynchronously(mcMMO.p, PerksUtils.handleCooldownPerks(player, ability.getCooldown()) * Misc.TICK_CONVERSION_FACTOR);
|
||||
new AbilityCooldownTask(mcMMOPlayer, ability).runTaskLaterAsynchronously(mcMMO.p, ability.getCooldown() * 20);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,41 +19,43 @@ public class ChildConfig extends AutoUpdateConfigLoader {
|
||||
protected void loadKeys() {
|
||||
config.setDefaults(YamlConfiguration.loadConfiguration(plugin.getResource("child.yml")));
|
||||
|
||||
for (SkillType skill : SkillType.childSkills()) {
|
||||
plugin.debug("Finding parents of " + skill.name());
|
||||
for (SkillType skill : SkillType.values()) {
|
||||
if (skill.isChildSkill()) {
|
||||
plugin.debug("Finding parents of " + skill.name());
|
||||
|
||||
List<String> parentNames = config.getStringList(StringUtils.getCapitalized(skill.name()));
|
||||
EnumSet<SkillType> parentSkills = EnumSet.noneOf(SkillType.class);
|
||||
boolean useDefaults = false; // If we had an error we back out and use defaults
|
||||
List<String> parentNames = config.getStringList(StringUtils.getCapitalized(skill.name()));
|
||||
EnumSet<SkillType> parentSkills = EnumSet.noneOf(SkillType.class);
|
||||
boolean useDefaults = false; // If we had an error we back out and use defaults
|
||||
|
||||
for (String name : parentNames) {
|
||||
try {
|
||||
SkillType parentSkill = SkillType.valueOf(name.toUpperCase());
|
||||
FamilyTree.enforceNotChildSkill(parentSkill);
|
||||
parentSkills.add(parentSkill);
|
||||
for (String name : parentNames) {
|
||||
try {
|
||||
SkillType parentSkill = Enum.valueOf(SkillType.class, name.toUpperCase());
|
||||
FamilyTree.enforceNotChildSkill(parentSkill);
|
||||
parentSkills.add(parentSkill);
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
plugin.getLogger().warning(name + " is not a valid skill type, or is a child skill!");
|
||||
useDefaults = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
plugin.getLogger().warning(name + " is not a valid skill type, or is a child skill!");
|
||||
useDefaults = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (useDefaults) {
|
||||
parentSkills.clear();
|
||||
for (String name : config.getDefaults().getStringList(StringUtils.getCapitalized(skill.name()))) {
|
||||
/* We do less checks in here because it's from inside our jar.
|
||||
* If they're dedicated enough to have modified it, they can have the errors it may produce.
|
||||
* Alternatively, this can be used to allow child skills to be parent skills, provided there are no circular dependencies this is an advanced sort of configuration.
|
||||
*/
|
||||
parentSkills.add(SkillType.valueOf(name.toUpperCase()));
|
||||
if (useDefaults) {
|
||||
parentSkills.clear();
|
||||
for (String name : config.getDefaults().getStringList(StringUtils.getCapitalized(skill.name()))) {
|
||||
/* We do less checks in here because it's from inside our jar.
|
||||
* If they're dedicated enough to have modified it, they can have the errors it may produce.
|
||||
* Alternatively, this can be used to allow child skills to be parent skills, provided there are no circular dependencies this is an advanced sort of configuration.
|
||||
*/
|
||||
parentSkills.add(SkillType.valueOf(name.toUpperCase()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Register them
|
||||
for (SkillType parentSkill : parentSkills) {
|
||||
plugin.debug("Registering " + parentSkill.name() + " as parent of " + skill.name());
|
||||
FamilyTree.registerParent(skill, parentSkill);
|
||||
// Register them
|
||||
for (SkillType parentSkill : parentSkills) {
|
||||
plugin.debug("Registering " + parentSkill.name() + " as parent of " + skill.name());
|
||||
FamilyTree.registerParent(skill, parentSkill);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,7 @@ package com.gmail.nossr50.skills.fishing;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
@@ -39,9 +37,6 @@ import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.datatypes.treasure.FishingTreasure;
|
||||
import com.gmail.nossr50.datatypes.treasure.ShakeTreasure;
|
||||
import com.gmail.nossr50.events.fake.FakePlayerFishEvent;
|
||||
import com.gmail.nossr50.events.skills.fishing.McMMOPlayerFishingTreasureEvent;
|
||||
import com.gmail.nossr50.events.skills.fishing.McMMOPlayerMagicHunterEvent;
|
||||
import com.gmail.nossr50.events.skills.fishing.McMMOPlayerShakeEvent;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.runnables.skills.KrakenAttackTask;
|
||||
import com.gmail.nossr50.skills.SkillManager;
|
||||
@@ -57,7 +52,6 @@ public class FishingManager extends SkillManager {
|
||||
|
||||
private int fishingTries = 0;
|
||||
private long fishingTimestamp = 0L;
|
||||
private Location fishingTarget;
|
||||
|
||||
public FishingManager(McMMOPlayer mcMMOPlayer) {
|
||||
super(mcMMOPlayer, SkillType.FISHING);
|
||||
@@ -114,15 +108,13 @@ public class FishingManager extends SkillManager {
|
||||
mcMMO.p.getServer().broadcastMessage(ChatColor.RED + AdvancedConfig.getInstance().getServerUnleashMessage().replace("(PLAYER)", player.getDisplayName()));
|
||||
}
|
||||
|
||||
if (player.getItemInHand().getType() == Material.FISHING_ROD) {
|
||||
player.setItemInHand(null);
|
||||
}
|
||||
player.setItemInHand(null);
|
||||
|
||||
Creature kraken = (Creature) world.spawnEntity(player.getEyeLocation(), (Misc.getRandom().nextInt(100) == 0 ? EntityType.CHICKEN : EntityType.SQUID));
|
||||
kraken.setCustomName(AdvancedConfig.getInstance().getKrakenName());
|
||||
|
||||
if (!kraken.isValid()) {
|
||||
int attackInterval = AdvancedConfig.getInstance().getKrakenAttackInterval() * Misc.TICK_CONVERSION_FACTOR;
|
||||
int attackInterval = AdvancedConfig.getInstance().getKrakenAttackInterval() * 20;
|
||||
new KrakenAttackTask(kraken, player, player.getLocation()).runTaskTimer(mcMMO.p, attackInterval, attackInterval);
|
||||
|
||||
if (!forceSpawn) {
|
||||
@@ -135,7 +127,7 @@ public class FishingManager extends SkillManager {
|
||||
kraken.setMaxHealth(AdvancedConfig.getInstance().getKrakenHealth());
|
||||
kraken.setHealth(kraken.getMaxHealth());
|
||||
|
||||
int attackInterval = AdvancedConfig.getInstance().getKrakenAttackInterval() * Misc.TICK_CONVERSION_FACTOR;
|
||||
int attackInterval = AdvancedConfig.getInstance().getKrakenAttackInterval() * 20;
|
||||
new KrakenAttackTask(kraken, player).runTaskTimer(mcMMO.p, attackInterval, attackInterval);
|
||||
|
||||
if (!forceSpawn) {
|
||||
@@ -150,24 +142,11 @@ public class FishingManager extends SkillManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
Block targetBlock = getPlayer().getTargetBlock(null, 100);
|
||||
|
||||
if (!targetBlock.isLiquid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
long currentTime = System.currentTimeMillis();
|
||||
boolean hasFished = (currentTime < fishingTimestamp + FISHING_COOLDOWN_SECONDS);
|
||||
boolean hasFished = currentTime < fishingTimestamp + FISHING_COOLDOWN_SECONDS;
|
||||
|
||||
fishingTries = hasFished ? fishingTries + 1 : Math.max(fishingTries - 1, 0);
|
||||
fishingTimestamp = currentTime;
|
||||
|
||||
Location targetLocation = targetBlock.getLocation();
|
||||
boolean sameTarget = (fishingTarget != null && fishingTarget.equals(targetLocation));
|
||||
|
||||
fishingTries = sameTarget ? fishingTries + 1 : Math.max(fishingTries - 1, 0);
|
||||
fishingTarget = targetLocation;
|
||||
|
||||
return unleashTheKraken(false);
|
||||
}
|
||||
|
||||
@@ -182,9 +161,9 @@ public class FishingManager extends SkillManager {
|
||||
|
||||
// Make sure this is a body of water, not just a block of ice.
|
||||
Biome biome = block.getBiome();
|
||||
boolean isFrozenBiome = (biome == Biome.FROZEN_OCEAN || biome == Biome.FROZEN_RIVER || biome == Biome.TAIGA || biome == Biome.TAIGA_HILLS || biome == Biome.ICE_PLAINS || biome == Biome.ICE_MOUNTAINS);
|
||||
boolean isFrozenBiome = (biome == Biome.FROZEN_OCEAN || biome == Biome.FROZEN_RIVER);
|
||||
|
||||
if (!isFrozenBiome && (block.getRelative(BlockFace.DOWN, 3).getType() != Material.STATIONARY_WATER)) {
|
||||
if (!isFrozenBiome && block.getRelative(BlockFace.DOWN, 3).getType() == (Material.STATIONARY_WATER)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -290,43 +269,13 @@ public class FishingManager extends SkillManager {
|
||||
treasureXp = treasure.getXp();
|
||||
ItemStack treasureDrop = treasure.getDrop().clone(); // Not cloning is bad, m'kay?
|
||||
|
||||
McMMOPlayerFishingTreasureEvent event;
|
||||
Map<Enchantment, Integer> enchants = new HashMap<Enchantment, Integer>();
|
||||
|
||||
if (Permissions.magicHunter(player) && ItemUtils.isEnchantable(treasureDrop)) {
|
||||
enchants = handleMagicHunter(treasureDrop);
|
||||
event = new McMMOPlayerMagicHunterEvent(player, treasureDrop, treasureXp, enchants);
|
||||
}
|
||||
else {
|
||||
event = new McMMOPlayerFishingTreasureEvent(player, treasureDrop, treasureXp);
|
||||
}
|
||||
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
treasureDrop = event.getTreasure();
|
||||
treasureXp = event.getXp();
|
||||
|
||||
if (event.isCancelled()) {
|
||||
treasureDrop = null;
|
||||
treasureXp = 0;
|
||||
if (Permissions.magicHunter(player) && ItemUtils.isEnchantable(treasureDrop) && handleMagicHunter(treasureDrop)) {
|
||||
player.sendMessage(LocaleLoader.getString("Fishing.MagicFound"));
|
||||
}
|
||||
|
||||
// Drop the original catch at the feet of the player and set the treasure as the real catch
|
||||
if (treasureDrop != null) {
|
||||
boolean enchanted = false;
|
||||
|
||||
if (!enchants.isEmpty()) {
|
||||
treasureDrop.addUnsafeEnchantments(enchants);
|
||||
enchanted = true;
|
||||
}
|
||||
|
||||
if (enchanted) {
|
||||
player.sendMessage(LocaleLoader.getString("Fishing.MagicFound"));
|
||||
}
|
||||
|
||||
Misc.dropItem(player.getEyeLocation(), fishingCatch.getItemStack());
|
||||
fishingCatch.setItemStack(treasureDrop);
|
||||
}
|
||||
Misc.dropItem(player.getEyeLocation(), fishingCatch.getItemStack());
|
||||
fishingCatch.setItemStack(treasureDrop);
|
||||
}
|
||||
|
||||
applyXpGain(Config.getInstance().getFishingBaseXP() + treasureXp);
|
||||
@@ -402,14 +351,6 @@ public class FishingManager extends SkillManager {
|
||||
break;
|
||||
}
|
||||
|
||||
McMMOPlayerShakeEvent event = new McMMOPlayerShakeEvent(getPlayer(), drop);
|
||||
|
||||
drop = event.getDrop();
|
||||
|
||||
if (event.isCancelled() || drop == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Misc.dropItem(target.getLocation(), drop);
|
||||
CombatUtils.dealDamage(target, Math.max(target.getMaxHealth() / 4, 1)); // Make it so you can shake a mob no more than 4 times.
|
||||
}
|
||||
@@ -458,7 +399,7 @@ public class FishingManager extends SkillManager {
|
||||
* @param treasureDrop The {@link ItemStack} to enchant
|
||||
* @return true if the item has been enchanted
|
||||
*/
|
||||
private Map<Enchantment, Integer> handleMagicHunter(ItemStack treasureDrop) {
|
||||
private boolean handleMagicHunter(ItemStack treasureDrop) {
|
||||
Player player = getPlayer();
|
||||
int activationChance = this.activationChance;
|
||||
|
||||
@@ -466,10 +407,8 @@ public class FishingManager extends SkillManager {
|
||||
activationChance *= Fishing.STORM_MODIFIER;
|
||||
}
|
||||
|
||||
Map<Enchantment, Integer> enchants = new HashMap<Enchantment, Integer>();
|
||||
|
||||
if (Misc.getRandom().nextInt(activationChance) > getLootTier() * AdvancedConfig.getInstance().getFishingMagicMultiplier()) {
|
||||
return enchants;
|
||||
return false;
|
||||
}
|
||||
|
||||
List<Enchantment> possibleEnchantments = getPossibleEnchantments(treasureDrop);
|
||||
@@ -477,6 +416,7 @@ public class FishingManager extends SkillManager {
|
||||
// This make sure that the order isn't always the same, for example previously Unbreaking had a lot more chance to be used than any other enchant
|
||||
Collections.shuffle(possibleEnchantments, Misc.getRandom());
|
||||
|
||||
boolean enchanted = false;
|
||||
int specificChance = 1;
|
||||
|
||||
for (Enchantment possibleEnchantment : possibleEnchantments) {
|
||||
@@ -484,12 +424,13 @@ public class FishingManager extends SkillManager {
|
||||
continue;
|
||||
}
|
||||
|
||||
enchants.put(possibleEnchantment, Math.max(Misc.getRandom().nextInt(possibleEnchantment.getMaxLevel()) + 1, possibleEnchantment.getStartLevel()));
|
||||
treasureDrop.addEnchantment(possibleEnchantment, Math.max(Misc.getRandom().nextInt(possibleEnchantment.getMaxLevel()) + 1, possibleEnchantment.getStartLevel()));
|
||||
|
||||
specificChance++;
|
||||
enchanted = true;
|
||||
}
|
||||
|
||||
return enchants;
|
||||
return enchanted;
|
||||
}
|
||||
|
||||
private List<Enchantment> getPossibleEnchantments(ItemStack treasureDrop) {
|
||||
|
||||
@@ -109,7 +109,7 @@ public class MiningManager extends SkillManager {
|
||||
|
||||
getProfile().setSkillDATS(AbilityType.BLAST_MINING, System.currentTimeMillis());
|
||||
mcMMOPlayer.setAbilityInformed(AbilityType.BLAST_MINING, false);
|
||||
new AbilityCooldownTask(mcMMOPlayer, AbilityType.BLAST_MINING).runTaskLaterAsynchronously(mcMMO.p, AbilityType.BLAST_MINING.getCooldown() * Misc.TICK_CONVERSION_FACTOR);
|
||||
new AbilityCooldownTask(mcMMOPlayer, AbilityType.BLAST_MINING).runTaskLaterAsynchronously(mcMMO.p, AbilityType.BLAST_MINING.getCooldown() * 20);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -284,10 +284,12 @@ public class MiningManager extends SkillManager {
|
||||
private boolean blastMiningCooldownOver() {
|
||||
Player player = getPlayer();
|
||||
PlayerProfile profile = getProfile();
|
||||
int timeRemaining = SkillUtils.calculateTimeLeft(profile.getSkillDATS(AbilityType.BLAST_MINING) * Misc.TIME_CONVERSION_FACTOR, AbilityType.BLAST_MINING.getCooldown(), player);
|
||||
|
||||
if (timeRemaining > 0) {
|
||||
player.sendMessage(LocaleLoader.getString("Skills.TooTired", timeRemaining));
|
||||
long oldTime = profile.getSkillDATS(AbilityType.BLAST_MINING) * Misc.TIME_CONVERSION_FACTOR;
|
||||
int cooldown = AbilityType.BLAST_MINING.getCooldown();
|
||||
|
||||
if (!SkillUtils.cooldownOver(oldTime, cooldown, player)) {
|
||||
player.sendMessage(LocaleLoader.getString("Skills.TooTired", SkillUtils.calculateTimeLeft(oldTime, cooldown, player)));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,11 +29,11 @@ public class Repair {
|
||||
* @return true if the item is salvageable, false otherwise
|
||||
*/
|
||||
public static boolean isSalvageable(ItemStack item) {
|
||||
if (Config.getInstance().getSalvageTools() && ItemUtils.isMinecraftTool(item)) {
|
||||
if (Config.getInstance().getSalvageTools() && (ItemUtils.isMinecraftTool(item) || ItemUtils.isStringTool(item) || item.getType() == Material.BUCKET)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Config.getInstance().getSalvageArmor() && !ItemUtils.isChainmailArmor(item) && ItemUtils.isMinecraftArmor(item)) {
|
||||
if (Config.getInstance().getSalvageArmor() && ItemUtils.isMinecraftArmor(item)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -88,14 +88,21 @@ public class RepairConfig extends ConfigLoader {
|
||||
}
|
||||
|
||||
protected List<Repairable> getLoadedRepairables() {
|
||||
return repairables == null ? new ArrayList<Repairable>() : repairables;
|
||||
if (repairables == null) {
|
||||
return new ArrayList<Repairable>();
|
||||
}
|
||||
|
||||
return repairables;
|
||||
}
|
||||
|
||||
private boolean noErrorsInRepairable(List<String> issues) {
|
||||
if (issues.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (String issue : issues) {
|
||||
plugin.getLogger().warning(issue);
|
||||
}
|
||||
|
||||
return issues.isEmpty();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,10 @@ public class SmeltingManager extends SkillManager {
|
||||
return getSkillLevel() >= Smelting.fluxMiningUnlockLevel && BlockUtils.affectedByFluxMining(blockState) && Permissions.fluxMining(getPlayer()) && !mcMMO.getPlaceStore().isTrue(blockState);
|
||||
}
|
||||
|
||||
public boolean canUseVanillaXpBoost() {
|
||||
return getSkillLevel() >= Smelting.Tier.ONE.getLevel() && Permissions.vanillaXpBoost(getPlayer(), skill);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the Flux Mining ability.
|
||||
*
|
||||
@@ -118,6 +122,6 @@ public class SmeltingManager extends SkillManager {
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,10 +230,14 @@ public final class Woodcutting {
|
||||
|
||||
short finalDurability = (short) (inHand.getDurability() + durabilityLoss);
|
||||
short maxDurability = ModUtils.isCustomTool(inHand) ? ModUtils.getToolFromItemStack(inHand).getDurability() : inHandMaterial.getMaxDurability();
|
||||
boolean overMax = (finalDurability >= maxDurability);
|
||||
|
||||
inHand.setDurability(overMax ? maxDurability : finalDurability);
|
||||
return !overMax;
|
||||
if (finalDurability >= maxDurability) {
|
||||
inHand.setDurability(maxDurability);
|
||||
return false;
|
||||
}
|
||||
|
||||
inHand.setDurability(finalDurability);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,7 +7,7 @@ import org.bukkit.material.CocoaPlant;
|
||||
import org.bukkit.material.CocoaPlant.CocoaPlantSize;
|
||||
import org.bukkit.material.NetherWarts;
|
||||
|
||||
import com.gmail.nossr50.skills.repair.Repair;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
|
||||
public final class BlockUtils {
|
||||
private BlockUtils() {}
|
||||
@@ -306,9 +306,9 @@ public final class BlockUtils {
|
||||
* @param blockState The {@link BlockState} of the block to check
|
||||
* @return true if the block is an mcMMO anvil, false otherwise
|
||||
*/
|
||||
public static boolean isMcMMOAnvil(BlockState blockState) {
|
||||
private static boolean isMcMMOAnvil(BlockState blockState) {
|
||||
int blockId = blockState.getTypeId();
|
||||
|
||||
return blockId == Repair.repairAnvilId || blockId == Repair.salvageAnvilId;
|
||||
return blockId == Config.getInstance().getRepairAnvilId() || blockId == Config.getInstance().getSalvageAnvilId();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,13 +35,9 @@ public final class ChimaeraWing {
|
||||
* @param player Player whose item usage to check
|
||||
*/
|
||||
public static void activationCheck(Player player) {
|
||||
if (!Config.getInstance().getChimaeraEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack inHand = player.getItemInHand();
|
||||
|
||||
if (!ItemUtils.isChimaeraWing(inHand)) {
|
||||
if (!Config.getInstance().getChimaeraEnabled() || !ItemUtils.isChimaeraWing(inHand)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -52,43 +48,32 @@ public final class ChimaeraWing {
|
||||
|
||||
mcMMOPlayer = UserManager.getPlayer(player);
|
||||
|
||||
location = player.getLocation();
|
||||
int amount = inHand.getAmount();
|
||||
long recentlyHurt = mcMMOPlayer.getRecentlyHurt();
|
||||
long lastTeleport = mcMMOPlayer.getLastTeleport();
|
||||
|
||||
if (mcMMOPlayer.getTeleportCommenceLocation() != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int amount = inHand.getAmount();
|
||||
if (Config.getInstance().getChimaeraCooldown() > 0 && !SkillUtils.cooldownOver(lastTeleport * Misc.TIME_CONVERSION_FACTOR, Config.getInstance().getChimaeraCooldown(), player)) {
|
||||
player.sendMessage(LocaleLoader.getString("Item.Generic.Wait", SkillUtils.calculateTimeLeft(lastTeleport * Misc.TIME_CONVERSION_FACTOR, Config.getInstance().getChimaeraCooldown(), player)));
|
||||
return;
|
||||
}
|
||||
|
||||
int recentlyhurt_cooldown = Config.getInstance().getChimaeraRecentlyHurtCooldown();
|
||||
|
||||
if (!SkillUtils.cooldownOver(recentlyHurt * Misc.TIME_CONVERSION_FACTOR, recentlyhurt_cooldown, player)) {
|
||||
player.sendMessage(LocaleLoader.getString("Item.Injured.Wait", SkillUtils.calculateTimeLeft(recentlyHurt * Misc.TIME_CONVERSION_FACTOR, recentlyhurt_cooldown, player)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (amount < Config.getInstance().getChimaeraUseCost()) {
|
||||
player.sendMessage(LocaleLoader.getString("Skills.NeedMore", LocaleLoader.getString("Item.ChimaeraWing.Name")));
|
||||
return;
|
||||
}
|
||||
|
||||
long lastTeleport = mcMMOPlayer.getLastTeleport();
|
||||
int cooldown = Config.getInstance().getChimaeraCooldown();
|
||||
|
||||
if (cooldown > 0 ) {
|
||||
int timeRemaining = SkillUtils.calculateTimeLeft(lastTeleport * Misc.TIME_CONVERSION_FACTOR, cooldown, player);
|
||||
|
||||
if (timeRemaining > 0) {
|
||||
player.sendMessage(LocaleLoader.getString("Item.Generic.Wait", timeRemaining));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
long recentlyHurt = mcMMOPlayer.getRecentlyHurt();
|
||||
int hurtCooldown = Config.getInstance().getChimaeraRecentlyHurtCooldown();
|
||||
|
||||
if (hurtCooldown > 0) {
|
||||
int timeRemaining = SkillUtils.calculateTimeLeft(recentlyHurt * Misc.TIME_CONVERSION_FACTOR, hurtCooldown, player);
|
||||
|
||||
if (timeRemaining > 0) {
|
||||
player.sendMessage(LocaleLoader.getString("Item.Injured.Wait", timeRemaining));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
location = player.getLocation();
|
||||
|
||||
if (Config.getInstance().getChimaeraPreventUseUnderground()) {
|
||||
if (location.getY() < player.getWorld().getHighestBlockYAt(location)) {
|
||||
player.setItemInHand(new ItemStack(getChimaeraWing(amount - Config.getInstance().getChimaeraUseCost())));
|
||||
|
||||
@@ -21,7 +21,11 @@ public final class HardcoreManager {
|
||||
PlayerProfile playerProfile = UserManager.getPlayer(player).getProfile();
|
||||
int totalLost = 0;
|
||||
|
||||
for (SkillType skillType : SkillType.nonChildSkills()) {
|
||||
for (SkillType skillType : SkillType.values()) {
|
||||
if (skillType.isChildSkill()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int playerSkillLevel = playerProfile.getSkillLevel(skillType);
|
||||
|
||||
if (playerSkillLevel <= 0) {
|
||||
@@ -48,7 +52,11 @@ public final class HardcoreManager {
|
||||
PlayerProfile victimProfile = UserManager.getPlayer(victim).getProfile();
|
||||
int totalStolen = 0;
|
||||
|
||||
for (SkillType skillType : SkillType.nonChildSkills()) {
|
||||
for (SkillType skillType : SkillType.values()) {
|
||||
if (skillType.isChildSkill()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int killerSkillLevel = killerProfile.getSkillLevel(skillType);
|
||||
int victimSkillLevel = victimProfile.getSkillLevel(skillType);
|
||||
|
||||
|
||||
@@ -461,10 +461,6 @@ public class ItemUtils {
|
||||
}
|
||||
|
||||
public static boolean isSmeltable(ItemStack item) {
|
||||
if (item == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (item.getType()) {
|
||||
case COAL_ORE:
|
||||
case DIAMOND_ORE:
|
||||
@@ -483,10 +479,6 @@ public class ItemUtils {
|
||||
}
|
||||
|
||||
public static boolean isSmelted(ItemStack item) {
|
||||
if (item == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (item.getType()) {
|
||||
case COAL:
|
||||
case DIAMOND:
|
||||
|
||||
@@ -1,23 +1,15 @@
|
||||
package com.gmail.nossr50.util;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Furnace;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryEvent;
|
||||
import org.bukkit.inventory.FurnaceInventory;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
@@ -28,11 +20,8 @@ import com.gmail.nossr50.util.spout.SpoutUtils;
|
||||
|
||||
public final class Misc {
|
||||
private static Random random = new Random();
|
||||
|
||||
public static final int TIME_CONVERSION_FACTOR = 1000;
|
||||
public static final int TICK_CONVERSION_FACTOR = 20;
|
||||
|
||||
public static final int PLAYER_RESPAWN_COOLDOWN_SECONDS = 5;
|
||||
public static final int TIME_CONVERSION_FACTOR = 1000;
|
||||
public static final double SKILL_MESSAGE_MAX_SENDING_DISTANCE = 10.0;
|
||||
|
||||
// Sound Pitches & Volumes from CB
|
||||
@@ -215,52 +204,6 @@ public final class Misc {
|
||||
}
|
||||
}
|
||||
|
||||
public static Block processInventoryOpenorCloseEvent(InventoryEvent event) {
|
||||
Inventory inventory = event.getInventory();
|
||||
|
||||
if (!(inventory instanceof FurnaceInventory)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Furnace furnace = (Furnace) inventory.getHolder();
|
||||
|
||||
if (furnace == null || furnace.getBurnTime() != 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return furnace.getBlock();
|
||||
}
|
||||
|
||||
public static Player getPlayerFromFurnace(Block furnaceBlock) {
|
||||
List<MetadataValue> metadata = furnaceBlock.getMetadata(mcMMO.furnaceMetadataKey);
|
||||
|
||||
if (metadata.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return mcMMO.p.getServer().getPlayerExact(metadata.get(0).asString());
|
||||
}
|
||||
|
||||
public static ItemStack getSmeltingFromFurnace(Block furnaceBlock) {
|
||||
BlockState furnaceState = furnaceBlock.getState();
|
||||
|
||||
if (!(furnaceState instanceof Furnace)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return ((Furnace) furnaceState).getInventory().getSmelting();
|
||||
}
|
||||
|
||||
public static ItemStack getResultFromFurnace(Block furnaceBlock) {
|
||||
BlockState furnaceState = furnaceBlock.getState();
|
||||
|
||||
if (!(furnaceState instanceof Furnace)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return ((Furnace) furnaceState).getInventory().getResult();
|
||||
}
|
||||
|
||||
public static Random getRandom() {
|
||||
return random;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.bukkit.metadata.FixedMetadataValue;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.config.WorldConfig;
|
||||
import com.gmail.nossr50.datatypes.MobHealthbarType;
|
||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
import com.gmail.nossr50.runnables.MobHealthDisplayUpdaterTask;
|
||||
@@ -44,7 +45,7 @@ public final class MobHealthbarUtils {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isBoss(target)) {
|
||||
if (!WorldConfig.getInstance().isMobHealthEnabled(player.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -87,7 +88,7 @@ public final class MobHealthbarUtils {
|
||||
target.setMetadata(mcMMO.customVisibleKey, new FixedMetadataValue(mcMMO.p, false));
|
||||
}
|
||||
|
||||
new MobHealthDisplayUpdaterTask(target).runTaskLater(mcMMO.p, displayTime * Misc.TICK_CONVERSION_FACTOR); // Clear health display after 3 seconds
|
||||
new MobHealthDisplayUpdaterTask(target).runTaskLater(mcMMO.p, displayTime * 20); // Clear health display after 3 seconds
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,21 +154,4 @@ public final class MobHealthbarUtils {
|
||||
|
||||
return healthbar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a given LivingEntity is a boss.
|
||||
*
|
||||
* @param livingEntity The {@link LivingEntity} of the livingEntity to check
|
||||
* @return true if the livingEntity is a boss, false otherwise
|
||||
*/
|
||||
public static boolean isBoss(LivingEntity livingEntity) {
|
||||
switch (livingEntity.getType()) {
|
||||
case ENDER_DRAGON:
|
||||
case WITHER:
|
||||
return true;
|
||||
|
||||
default:
|
||||
return ModUtils.isCustomBossEntity(livingEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user