mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2026-02-18 17:53:00 +01:00
Compare commits
63 Commits
dev-partym
...
dev-asyncL
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ffd11f6e0e | ||
|
|
f1f9ffc10b | ||
|
|
8fe18be79b | ||
|
|
f0dcfb0346 | ||
|
|
c85d52e594 | ||
|
|
4342abca3d | ||
|
|
11e4ff34d6 | ||
|
|
f118ac14ca | ||
|
|
f5eb7a10de | ||
|
|
36b09421e8 | ||
|
|
d6b39a11e7 | ||
|
|
23729f45ee | ||
|
|
27d7b73e57 | ||
|
|
af60f08a8b | ||
|
|
c19d3fd068 | ||
|
|
0f8312dd5e | ||
|
|
1edb11cedf | ||
|
|
6fea7c8d74 | ||
|
|
a4a1ba4331 | ||
|
|
de46277bea | ||
|
|
6d7d811814 | ||
|
|
98b98256b7 | ||
|
|
abd389f4de | ||
|
|
602956a555 | ||
|
|
8d0601babc | ||
|
|
050be563bf | ||
|
|
965dbda101 | ||
|
|
f2b2cd9cc0 | ||
|
|
3a78e1b487 | ||
|
|
db637f0bc9 | ||
|
|
b15f1dde28 | ||
|
|
28a78d820a | ||
|
|
a1792fe125 | ||
|
|
3f7b17961f | ||
|
|
0ea07d4bc7 | ||
|
|
190b7ee1f5 | ||
|
|
4ff4271da2 | ||
|
|
8705974e08 | ||
|
|
de0487d16f | ||
|
|
fc0c386ecb | ||
|
|
86db4251a2 | ||
|
|
effe5ec305 | ||
|
|
8fb92292bd | ||
|
|
375fa4f75c | ||
|
|
da25b02e0a | ||
|
|
d43ae17bd2 | ||
|
|
f81a763d6c | ||
|
|
385f8ca0b3 | ||
|
|
0ba4bc25c7 | ||
|
|
b0eb4b93a8 | ||
|
|
54f135aebd | ||
|
|
10e369f9c5 | ||
|
|
1ae9b0f4d2 | ||
|
|
198ee6a7ed | ||
|
|
2414ddf485 | ||
|
|
2cd52db8c9 | ||
|
|
5e00636761 | ||
|
|
a82cc9609b | ||
|
|
45c6c20ccd | ||
|
|
7a61f55e49 | ||
|
|
aa0b77a64c | ||
|
|
030c8e59d7 | ||
|
|
f21fbe2d40 |
@@ -28,6 +28,11 @@ Version 1.4.06-dev
|
|||||||
+ Added multiplier to Archery XP based on bow force
|
+ Added multiplier to Archery XP based on bow force
|
||||||
+ Added information about /party itemshare and /party expshare to the party help page
|
+ Added information about /party itemshare and /party expshare to the party help page
|
||||||
+ Added option to use scoreboards for power level display instead of Spout.
|
+ Added option to use scoreboards for power level display instead of Spout.
|
||||||
|
+ Added permission node to prevent inspecting hidden players
|
||||||
|
+ Added 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 custom Spout titles were overwritten by mcMMO.
|
||||||
= Fixed bug where Nether Quartz wasn't included in Smelting or item sharing
|
= Fixed bug where Nether Quartz wasn't included in Smelting or item sharing
|
||||||
= Fixed bug where players were able to join the same party multiple times
|
= Fixed bug where players were able to join the same party multiple times
|
||||||
@@ -48,6 +53,10 @@ Version 1.4.06-dev
|
|||||||
= Fixed bug where Blast Mining would drop wrong items
|
= 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 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 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 Spout notification tiers to be stored in SpoutConfig instead of AdvancedConfig
|
||||||
! Changed Berserk to add items to inventory rather than denying pickup
|
! Changed Berserk to add items to inventory rather than denying pickup
|
||||||
! Changed Call of the Wild, newly summoned pet's will have a custom name. (added permission node to disable this)
|
! Changed Call of the Wild, newly summoned pet's will have a custom name. (added permission node to disable this)
|
||||||
|
|||||||
4
pom.xml
4
pom.xml
@@ -145,7 +145,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bukkit</groupId>
|
<groupId>org.bukkit</groupId>
|
||||||
<artifactId>bukkit</artifactId>
|
<artifactId>bukkit</artifactId>
|
||||||
<version>LATEST</version>
|
<version>1.5.2-R1.0</version>
|
||||||
<type>jar</type>
|
<type>jar</type>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
@@ -165,7 +165,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.turt2live.metrics</groupId>
|
<groupId>com.turt2live.metrics</groupId>
|
||||||
<artifactId>MetricsExtension</artifactId>
|
<artifactId>MetricsExtension</artifactId>
|
||||||
<version>0.0.4-SNAPSHOT</version>
|
<version>0.0.5-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import com.gmail.nossr50.chat.ChatManager;
|
import com.gmail.nossr50.chat.ChatManager;
|
||||||
|
import com.gmail.nossr50.chat.ChatManagerFactory;
|
||||||
|
import com.gmail.nossr50.chat.ChatMode;
|
||||||
|
import com.gmail.nossr50.chat.PartyChatManager;
|
||||||
import com.gmail.nossr50.party.PartyManager;
|
import com.gmail.nossr50.party.PartyManager;
|
||||||
import com.gmail.nossr50.util.player.UserManager;
|
import com.gmail.nossr50.util.player.UserManager;
|
||||||
|
|
||||||
@@ -22,7 +25,7 @@ public final class ChatAPI {
|
|||||||
* @param message The message to send
|
* @param message The message to send
|
||||||
*/
|
*/
|
||||||
public static void sendPartyChat(Plugin plugin, String sender, String displayName, String party, String message) {
|
public static void sendPartyChat(Plugin plugin, String sender, String displayName, String party, String message) {
|
||||||
ChatManager.handlePartyChat(plugin, PartyManager.getParty(party), sender, displayName, message);
|
getPartyChatManager(plugin, party).handleChat(sender, displayName, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -36,7 +39,7 @@ public final class ChatAPI {
|
|||||||
* @param message The message to send
|
* @param message The message to send
|
||||||
*/
|
*/
|
||||||
public static void sendPartyChat(Plugin plugin, String sender, String party, String message) {
|
public static void sendPartyChat(Plugin plugin, String sender, String party, String message) {
|
||||||
ChatManager.handlePartyChat(plugin, PartyManager.getParty(party), sender, sender, message);
|
getPartyChatManager(plugin, party).handleChat(sender, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -50,7 +53,7 @@ public final class ChatAPI {
|
|||||||
* @param message The message to send
|
* @param message The message to send
|
||||||
*/
|
*/
|
||||||
public static void sendAdminChat(Plugin plugin, String sender, String displayName, String message) {
|
public static void sendAdminChat(Plugin plugin, String sender, String displayName, String message) {
|
||||||
ChatManager.handleAdminChat(plugin, sender, displayName, message);
|
ChatManagerFactory.getChatManager(plugin, ChatMode.ADMIN).handleChat(sender, displayName, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -63,7 +66,7 @@ public final class ChatAPI {
|
|||||||
* @param message The message to send
|
* @param message The message to send
|
||||||
*/
|
*/
|
||||||
public static void sendAdminChat(Plugin plugin, String sender, String message) {
|
public static void sendAdminChat(Plugin plugin, String sender, String message) {
|
||||||
ChatManager.handleAdminChat(plugin, sender, sender, message);
|
ChatManagerFactory.getChatManager(plugin, ChatMode.ADMIN).handleChat(sender, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -73,7 +76,7 @@ public final class ChatAPI {
|
|||||||
* @return true if the player is using party chat, false otherwise
|
* @return true if the player is using party chat, false otherwise
|
||||||
*/
|
*/
|
||||||
public static boolean isUsingPartyChat(Player player) {
|
public static boolean isUsingPartyChat(Player player) {
|
||||||
return isUsingPartyChat(player.getName());
|
return UserManager.getPlayer(player).getPartyChatMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -93,7 +96,7 @@ public final class ChatAPI {
|
|||||||
* @return true if the player is using admin chat, false otherwise
|
* @return true if the player is using admin chat, false otherwise
|
||||||
*/
|
*/
|
||||||
public static boolean isUsingAdminChat(Player player) {
|
public static boolean isUsingAdminChat(Player player) {
|
||||||
return isUsingAdminChat(player.getName());
|
return UserManager.getPlayer(player).getAdminChatMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -112,7 +115,7 @@ public final class ChatAPI {
|
|||||||
* @param player The player to toggle party chat on.
|
* @param player The player to toggle party chat on.
|
||||||
*/
|
*/
|
||||||
public static void togglePartyChat(Player player) {
|
public static void togglePartyChat(Player player) {
|
||||||
togglePartyChat(player.getName());
|
UserManager.getPlayer(player).togglePartyChat();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -121,7 +124,7 @@ public final class ChatAPI {
|
|||||||
* @param playerName The name of the player to toggle party chat on.
|
* @param playerName The name of the player to toggle party chat on.
|
||||||
*/
|
*/
|
||||||
public static void togglePartyChat(String playerName) {
|
public static void togglePartyChat(String playerName) {
|
||||||
UserManager.getPlayer(playerName).setPartyChat(!isUsingPartyChat(playerName));
|
UserManager.getPlayer(playerName).togglePartyChat();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -130,7 +133,7 @@ public final class ChatAPI {
|
|||||||
* @param player The player to toggle admin chat on.
|
* @param player The player to toggle admin chat on.
|
||||||
*/
|
*/
|
||||||
public static void toggleAdminChat(Player player) {
|
public static void toggleAdminChat(Player player) {
|
||||||
toggleAdminChat(player.getName());
|
UserManager.getPlayer(player).toggleAdminChat();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -139,6 +142,13 @@ public final class ChatAPI {
|
|||||||
* @param playerName The name of the player to toggle party chat on.
|
* @param playerName The name of the player to toggle party chat on.
|
||||||
*/
|
*/
|
||||||
public static void toggleAdminChat(String playerName) {
|
public static void toggleAdminChat(String playerName) {
|
||||||
UserManager.getPlayer(playerName).setAdminChat(!isUsingAdminChat(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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.api.exceptions.InvalidPlayerException;
|
import com.gmail.nossr50.api.exceptions.InvalidPlayerException;
|
||||||
import com.gmail.nossr50.api.exceptions.InvalidSkillException;
|
import com.gmail.nossr50.api.exceptions.InvalidSkillException;
|
||||||
import com.gmail.nossr50.config.Config;
|
import com.gmail.nossr50.config.Config;
|
||||||
@@ -15,6 +16,37 @@ import com.gmail.nossr50.util.player.UserManager;
|
|||||||
public final class ExperienceAPI {
|
public final class ExperienceAPI {
|
||||||
private 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.
|
* Adds raw XP to the player.
|
||||||
* </br>
|
* </br>
|
||||||
@@ -27,13 +59,7 @@ public final class ExperienceAPI {
|
|||||||
* @throws InvalidSkillException if the given skill is not valid
|
* @throws InvalidSkillException if the given skill is not valid
|
||||||
*/
|
*/
|
||||||
public static void addRawXP(Player player, String skillType, int XP) {
|
public static void addRawXP(Player player, String skillType, int XP) {
|
||||||
SkillType skill = SkillType.getSkill(skillType);
|
UserManager.getPlayer(player).applyXpGain(getSkillType(skillType), XP);
|
||||||
|
|
||||||
if (skill == null) {
|
|
||||||
throw new InvalidSkillException();
|
|
||||||
}
|
|
||||||
|
|
||||||
UserManager.getPlayer(player).applyXpGain(skill, XP);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -49,13 +75,7 @@ public final class ExperienceAPI {
|
|||||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||||
*/
|
*/
|
||||||
public static void addRawXPOffline(String playerName, String skillType, int XP) {
|
public static void addRawXPOffline(String playerName, String skillType, int XP) {
|
||||||
SkillType skill = SkillType.getSkill(skillType);
|
addOfflineXP(playerName, getSkillType(skillType), XP);
|
||||||
|
|
||||||
if (skill == null) {
|
|
||||||
throw new InvalidSkillException();
|
|
||||||
}
|
|
||||||
|
|
||||||
addOfflineXP(playerName, skill, XP);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -70,13 +90,7 @@ public final class ExperienceAPI {
|
|||||||
* @throws InvalidSkillException if the given skill is not valid
|
* @throws InvalidSkillException if the given skill is not valid
|
||||||
*/
|
*/
|
||||||
public static void addMultipliedXP(Player player, String skillType, int XP) {
|
public static void addMultipliedXP(Player player, String skillType, int XP) {
|
||||||
SkillType skill = SkillType.getSkill(skillType);
|
UserManager.getPlayer(player).applyXpGain(getSkillType(skillType), (int) (XP * Config.getInstance().getExperienceGainsGlobalMultiplier()));
|
||||||
|
|
||||||
if (skill == null) {
|
|
||||||
throw new InvalidSkillException();
|
|
||||||
}
|
|
||||||
|
|
||||||
UserManager.getPlayer(player).applyXpGain(skill, (int) (XP * Config.getInstance().getExperienceGainsGlobalMultiplier()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -92,13 +106,7 @@ public final class ExperienceAPI {
|
|||||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||||
*/
|
*/
|
||||||
public static void addMultipliedXPOffline(String playerName, String skillType, int XP) {
|
public static void addMultipliedXPOffline(String playerName, String skillType, int XP) {
|
||||||
SkillType skill = SkillType.getSkill(skillType);
|
addOfflineXP(playerName, getSkillType(skillType), (int) (XP * Config.getInstance().getExperienceGainsGlobalMultiplier()));
|
||||||
|
|
||||||
if (skill == null) {
|
|
||||||
throw new InvalidSkillException();
|
|
||||||
}
|
|
||||||
|
|
||||||
addOfflineXP(playerName, skill, (int) (XP * Config.getInstance().getExperienceGainsGlobalMultiplier()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -113,11 +121,7 @@ public final class ExperienceAPI {
|
|||||||
* @throws InvalidSkillException if the given skill is not valid
|
* @throws InvalidSkillException if the given skill is not valid
|
||||||
*/
|
*/
|
||||||
public static void addModifiedXP(Player player, String skillType, int XP) {
|
public static void addModifiedXP(Player player, String skillType, int XP) {
|
||||||
SkillType skill = SkillType.getSkill(skillType);
|
SkillType skill = getSkillType(skillType);
|
||||||
|
|
||||||
if (skill == null) {
|
|
||||||
throw new InvalidSkillException();
|
|
||||||
}
|
|
||||||
|
|
||||||
UserManager.getPlayer(player).applyXpGain(skill, (int) (XP / skill.getXpModifier() * Config.getInstance().getExperienceGainsGlobalMultiplier()));
|
UserManager.getPlayer(player).applyXpGain(skill, (int) (XP / skill.getXpModifier() * Config.getInstance().getExperienceGainsGlobalMultiplier()));
|
||||||
}
|
}
|
||||||
@@ -135,17 +139,14 @@ public final class ExperienceAPI {
|
|||||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||||
*/
|
*/
|
||||||
public static void addModifiedXPOffline(String playerName, String skillType, int XP) {
|
public static void addModifiedXPOffline(String playerName, String skillType, int XP) {
|
||||||
SkillType skill = SkillType.getSkill(skillType);
|
SkillType skill = getSkillType(skillType);
|
||||||
|
|
||||||
if (skill == null) {
|
|
||||||
throw new InvalidSkillException();
|
|
||||||
}
|
|
||||||
|
|
||||||
addOfflineXP(playerName, skill, (int) (XP / skill.getXpModifier() * Config.getInstance().getExperienceGainsGlobalMultiplier()));
|
addOfflineXP(playerName, skill, (int) (XP / skill.getXpModifier() * Config.getInstance().getExperienceGainsGlobalMultiplier()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds XP to the player, calculates for XP Rate, skill modifiers and perks. May be shared with the party.
|
* Adds XP to the player, calculates for XP Rate, skill modifiers, perks, child skills,
|
||||||
|
* and party sharing.
|
||||||
* </br>
|
* </br>
|
||||||
* This function is designed for API usage.
|
* This function is designed for API usage.
|
||||||
*
|
*
|
||||||
@@ -156,13 +157,7 @@ public final class ExperienceAPI {
|
|||||||
* @throws InvalidSkillException if the given skill is not valid
|
* @throws InvalidSkillException if the given skill is not valid
|
||||||
*/
|
*/
|
||||||
public static void addXP(Player player, String skillType, int XP) {
|
public static void addXP(Player player, String skillType, int XP) {
|
||||||
SkillType skill = SkillType.getSkill(skillType);
|
UserManager.getPlayer(player).beginXpGain(getSkillType(skillType), XP);
|
||||||
|
|
||||||
if (skill == null) {
|
|
||||||
throw new InvalidSkillException();
|
|
||||||
}
|
|
||||||
|
|
||||||
UserManager.getPlayer(player).beginXpGain(skill, XP);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -178,17 +173,7 @@ public final class ExperienceAPI {
|
|||||||
* @throws UnsupportedOperationException if the given skill is a child skill
|
* @throws UnsupportedOperationException if the given skill is a child skill
|
||||||
*/
|
*/
|
||||||
public static int getXP(Player player, String skillType) {
|
public static int getXP(Player player, String skillType) {
|
||||||
SkillType skill = SkillType.getSkill(skillType);
|
return UserManager.getPlayer(player).getProfile().getSkillXpLevel(getNonChildSkillType(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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -205,17 +190,7 @@ public final class ExperienceAPI {
|
|||||||
* @throws UnsupportedOperationException if the given skill is a child skill
|
* @throws UnsupportedOperationException if the given skill is a child skill
|
||||||
*/
|
*/
|
||||||
public static int getOfflineXP(String playerName, String skillType) {
|
public static int getOfflineXP(String playerName, String skillType) {
|
||||||
SkillType skill = SkillType.getSkill(skillType);
|
return getOfflineProfile(playerName).getSkillXpLevel(getNonChildSkillType(skillType));
|
||||||
|
|
||||||
if (skill == null) {
|
|
||||||
throw new InvalidSkillException();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (skill.isChildSkill()) {
|
|
||||||
throw new UnsupportedOperationException("Child skills do not have XP");
|
|
||||||
}
|
|
||||||
|
|
||||||
return getOfflineProfile(playerName).getSkillXpLevel(skill);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -231,17 +206,7 @@ public final class ExperienceAPI {
|
|||||||
* @throws UnsupportedOperationException if the given skill is a child skill
|
* @throws UnsupportedOperationException if the given skill is a child skill
|
||||||
*/
|
*/
|
||||||
public static float getXPRaw(Player player, String skillType) {
|
public static float getXPRaw(Player player, String skillType) {
|
||||||
SkillType skill = SkillType.getSkill(skillType);
|
return UserManager.getPlayer(player).getProfile().getSkillXpLevelRaw(getNonChildSkillType(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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -258,17 +223,7 @@ public final class ExperienceAPI {
|
|||||||
* @throws UnsupportedOperationException if the given skill is a child skill
|
* @throws UnsupportedOperationException if the given skill is a child skill
|
||||||
*/
|
*/
|
||||||
public static float getOfflineXPRaw(String playerName, String skillType) {
|
public static float getOfflineXPRaw(String playerName, String skillType) {
|
||||||
SkillType skill = SkillType.getSkill(skillType);
|
return getOfflineProfile(playerName).getSkillXpLevelRaw(getNonChildSkillType(skillType));
|
||||||
|
|
||||||
if (skill == null) {
|
|
||||||
throw new InvalidSkillException();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (skill.isChildSkill()) {
|
|
||||||
throw new UnsupportedOperationException("Child skills do not have XP");
|
|
||||||
}
|
|
||||||
|
|
||||||
return getOfflineProfile(playerName).getSkillXpLevelRaw(skill);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -284,17 +239,7 @@ public final class ExperienceAPI {
|
|||||||
* @throws UnsupportedOperationException if the given skill is a child skill
|
* @throws UnsupportedOperationException if the given skill is a child skill
|
||||||
*/
|
*/
|
||||||
public static int getXPToNextLevel(Player player, String skillType) {
|
public static int getXPToNextLevel(Player player, String skillType) {
|
||||||
SkillType skill = SkillType.getSkill(skillType);
|
return UserManager.getPlayer(player).getProfile().getXpToLevel(getNonChildSkillType(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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -311,17 +256,7 @@ public final class ExperienceAPI {
|
|||||||
* @throws UnsupportedOperationException if the given skill is a child skill
|
* @throws UnsupportedOperationException if the given skill is a child skill
|
||||||
*/
|
*/
|
||||||
public static int getOfflineXPToNextLevel(String playerName, String skillType) {
|
public static int getOfflineXPToNextLevel(String playerName, String skillType) {
|
||||||
SkillType skill = SkillType.getSkill(skillType);
|
return getOfflineProfile(playerName).getXpToLevel(getNonChildSkillType(skillType));
|
||||||
|
|
||||||
if (skill == null) {
|
|
||||||
throw new InvalidSkillException();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (skill.isChildSkill()) {
|
|
||||||
throw new UnsupportedOperationException("Child skills do not have XP");
|
|
||||||
}
|
|
||||||
|
|
||||||
return getOfflineProfile(playerName).getXpToLevel(skill);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -337,15 +272,7 @@ public final class ExperienceAPI {
|
|||||||
* @throws UnsupportedOperationException if the given skill is a child skill
|
* @throws UnsupportedOperationException if the given skill is a child skill
|
||||||
*/
|
*/
|
||||||
public static int getXPRemaining(Player player, String skillType) {
|
public static int getXPRemaining(Player player, String skillType) {
|
||||||
SkillType skill = SkillType.getSkill(skillType);
|
SkillType skill = getNonChildSkillType(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();
|
PlayerProfile profile = UserManager.getPlayer(player).getProfile();
|
||||||
|
|
||||||
@@ -366,15 +293,7 @@ public final class ExperienceAPI {
|
|||||||
* @throws UnsupportedOperationException if the given skill is a child skill
|
* @throws UnsupportedOperationException if the given skill is a child skill
|
||||||
*/
|
*/
|
||||||
public static int getOfflineXPRemaining(String playerName, String skillType) {
|
public static int getOfflineXPRemaining(String playerName, String skillType) {
|
||||||
SkillType skill = SkillType.getSkill(skillType);
|
SkillType skill = getNonChildSkillType(skillType);
|
||||||
|
|
||||||
if (skill == null) {
|
|
||||||
throw new InvalidSkillException();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (skill.isChildSkill()) {
|
|
||||||
throw new UnsupportedOperationException("Child skills do not have XP");
|
|
||||||
}
|
|
||||||
|
|
||||||
PlayerProfile profile = getOfflineProfile(playerName);
|
PlayerProfile profile = getOfflineProfile(playerName);
|
||||||
|
|
||||||
@@ -393,13 +312,7 @@ public final class ExperienceAPI {
|
|||||||
* @throws InvalidSkillException if the given skill is not valid
|
* @throws InvalidSkillException if the given skill is not valid
|
||||||
*/
|
*/
|
||||||
public static void addLevel(Player player, String skillType, int levels) {
|
public static void addLevel(Player player, String skillType, int levels) {
|
||||||
SkillType skill = SkillType.getSkill(skillType);
|
UserManager.getPlayer(player).getProfile().addLevels(getSkillType(skillType), levels);
|
||||||
|
|
||||||
if (skill == null) {
|
|
||||||
throw new InvalidSkillException();
|
|
||||||
}
|
|
||||||
|
|
||||||
UserManager.getPlayer(player).getProfile().addLevels(skill, levels);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -416,11 +329,7 @@ public final class ExperienceAPI {
|
|||||||
*/
|
*/
|
||||||
public static void addLevelOffline(String playerName, String skillType, int levels) {
|
public static void addLevelOffline(String playerName, String skillType, int levels) {
|
||||||
PlayerProfile profile = getOfflineProfile(playerName);
|
PlayerProfile profile = getOfflineProfile(playerName);
|
||||||
SkillType skill = SkillType.getSkill(skillType);
|
SkillType skill = getSkillType(skillType);
|
||||||
|
|
||||||
if (skill == null) {
|
|
||||||
throw new InvalidSkillException();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (skill.isChildSkill()) {
|
if (skill.isChildSkill()) {
|
||||||
Set<SkillType> parentSkills = FamilyTree.getParents(skill);
|
Set<SkillType> parentSkills = FamilyTree.getParents(skill);
|
||||||
@@ -449,13 +358,7 @@ public final class ExperienceAPI {
|
|||||||
* @throws InvalidSkillException if the given skill is not valid
|
* @throws InvalidSkillException if the given skill is not valid
|
||||||
*/
|
*/
|
||||||
public static int getLevel(Player player, String skillType) {
|
public static int getLevel(Player player, String skillType) {
|
||||||
SkillType skill = SkillType.getSkill(skillType);
|
return UserManager.getPlayer(player).getProfile().getSkillLevel(getSkillType(skillType));
|
||||||
|
|
||||||
if (skill == null) {
|
|
||||||
throw new InvalidSkillException();
|
|
||||||
}
|
|
||||||
|
|
||||||
return UserManager.getPlayer(player).getProfile().getSkillLevel(skill);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -471,13 +374,7 @@ public final class ExperienceAPI {
|
|||||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||||
*/
|
*/
|
||||||
public static int getLevelOffline(String playerName, String skillType) {
|
public static int getLevelOffline(String playerName, String skillType) {
|
||||||
SkillType skill = SkillType.getSkill(skillType);
|
return getOfflineProfile(playerName).getSkillLevel(getSkillType(skillType));
|
||||||
|
|
||||||
if (skill == null) {
|
|
||||||
throw new InvalidSkillException();
|
|
||||||
}
|
|
||||||
|
|
||||||
return getOfflineProfile(playerName).getSkillLevel(skill);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -524,13 +421,7 @@ public final class ExperienceAPI {
|
|||||||
* @throws InvalidSkillException if the given skill is not valid
|
* @throws InvalidSkillException if the given skill is not valid
|
||||||
*/
|
*/
|
||||||
public static int getLevelCap(String skillType) {
|
public static int getLevelCap(String skillType) {
|
||||||
SkillType skill = SkillType.getSkill(skillType);
|
return Config.getInstance().getLevelCap(getSkillType(skillType));
|
||||||
|
|
||||||
if (skill == null) {
|
|
||||||
throw new InvalidSkillException();
|
|
||||||
}
|
|
||||||
|
|
||||||
return Config.getInstance().getLevelCap(skill);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -556,13 +447,7 @@ public final class ExperienceAPI {
|
|||||||
* @throws InvalidSkillException if the given skill is not valid
|
* @throws InvalidSkillException if the given skill is not valid
|
||||||
*/
|
*/
|
||||||
public static void setLevel(Player player, String skillType, int skillLevel) {
|
public static void setLevel(Player player, String skillType, int skillLevel) {
|
||||||
SkillType skill = SkillType.getSkill(skillType);
|
UserManager.getPlayer(player).getProfile().modifySkill(getSkillType(skillType), skillLevel);
|
||||||
|
|
||||||
if (skill == null) {
|
|
||||||
throw new InvalidSkillException();
|
|
||||||
}
|
|
||||||
|
|
||||||
UserManager.getPlayer(player).getProfile().modifySkill(skill, skillLevel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -578,13 +463,7 @@ public final class ExperienceAPI {
|
|||||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||||
*/
|
*/
|
||||||
public static void setLevelOffline(String playerName, String skillType, int skillLevel) {
|
public static void setLevelOffline(String playerName, String skillType, int skillLevel) {
|
||||||
SkillType skill = SkillType.getSkill(skillType);
|
getOfflineProfile(playerName).modifySkill(getSkillType(skillType), skillLevel);
|
||||||
|
|
||||||
if (skill == null) {
|
|
||||||
throw new InvalidSkillException();
|
|
||||||
}
|
|
||||||
|
|
||||||
getOfflineProfile(playerName).modifySkill(skill, skillLevel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -600,17 +479,7 @@ public final class ExperienceAPI {
|
|||||||
* @throws UnsupportedOperationException if the given skill is a child skill
|
* @throws UnsupportedOperationException if the given skill is a child skill
|
||||||
*/
|
*/
|
||||||
public static void setXP(Player player, String skillType, int newValue) {
|
public static void setXP(Player player, String skillType, int newValue) {
|
||||||
SkillType skill = SkillType.getSkill(skillType);
|
UserManager.getPlayer(player).getProfile().setSkillXpLevel(getNonChildSkillType(skillType), newValue);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -627,17 +496,7 @@ public final class ExperienceAPI {
|
|||||||
* @throws UnsupportedOperationException if the given skill is a child skill
|
* @throws UnsupportedOperationException if the given skill is a child skill
|
||||||
*/
|
*/
|
||||||
public static void setXPOffline(String playerName, String skillType, int newValue) {
|
public static void setXPOffline(String playerName, String skillType, int newValue) {
|
||||||
SkillType skill = SkillType.getSkill(skillType);
|
getOfflineProfile(playerName).setSkillXpLevel(getNonChildSkillType(skillType), newValue);
|
||||||
|
|
||||||
if (skill == null) {
|
|
||||||
throw new InvalidSkillException();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (skill.isChildSkill()) {
|
|
||||||
throw new UnsupportedOperationException("Child skills do not have XP");
|
|
||||||
}
|
|
||||||
|
|
||||||
getOfflineProfile(playerName).setSkillXpLevel(skill, newValue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -653,17 +512,7 @@ public final class ExperienceAPI {
|
|||||||
* @throws UnsupportedOperationException if the given skill is a child skill
|
* @throws UnsupportedOperationException if the given skill is a child skill
|
||||||
*/
|
*/
|
||||||
public static void removeXP(Player player, String skillType, int xp) {
|
public static void removeXP(Player player, String skillType, int xp) {
|
||||||
SkillType skill = SkillType.getSkill(skillType);
|
UserManager.getPlayer(player).getProfile().removeXp(getNonChildSkillType(skillType), xp);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -680,26 +529,11 @@ public final class ExperienceAPI {
|
|||||||
* @throws UnsupportedOperationException if the given skill is a child skill
|
* @throws UnsupportedOperationException if the given skill is a child skill
|
||||||
*/
|
*/
|
||||||
public static void removeXPOffline(String playerName, String skillType, int xp) {
|
public static void removeXPOffline(String playerName, String skillType, int xp) {
|
||||||
SkillType skill = SkillType.getSkill(skillType);
|
getOfflineProfile(playerName).removeXp(getNonChildSkillType(skillType), xp);
|
||||||
|
|
||||||
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) {
|
private static void addOfflineXP(String playerName, SkillType skill, int XP) {
|
||||||
PlayerProfile profile = getOfflineProfile(playerName);
|
PlayerProfile profile = getOfflineProfile(playerName);
|
||||||
|
|
||||||
@@ -719,7 +553,7 @@ public final class ExperienceAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static PlayerProfile getOfflineProfile(String playerName) {
|
private static PlayerProfile getOfflineProfile(String playerName) {
|
||||||
PlayerProfile profile = new PlayerProfile(playerName, false);
|
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(playerName, false);
|
||||||
|
|
||||||
if (!profile.isLoaded()) {
|
if (!profile.isLoaded()) {
|
||||||
throw new InvalidPlayerException();
|
throw new InvalidPlayerException();
|
||||||
@@ -727,4 +561,24 @@ public final class ExperienceAPI {
|
|||||||
|
|
||||||
return profile;
|
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,14 +77,13 @@ public final class PartyAPI {
|
|||||||
*/
|
*/
|
||||||
public static void addToParty(Player player, String partyName) {
|
public static void addToParty(Player player, String partyName) {
|
||||||
Party party = PartyManager.getParty(partyName);
|
Party party = PartyManager.getParty(partyName);
|
||||||
|
String playerName = player.getName();
|
||||||
|
|
||||||
if (party == null) {
|
if (party == null) {
|
||||||
party = new Party();
|
party = new Party(playerName, partyName);
|
||||||
party.setName(partyName);
|
|
||||||
party.setLeader(player.getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PartyManager.addToParty(player, UserManager.getPlayer(player), party);
|
PartyManager.addToParty(playerName, UserManager.getPlayer(player), party);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
22
src/main/java/com/gmail/nossr50/chat/AdminChatManager.java
Normal file
22
src/main/java/com/gmail/nossr50/chat/AdminChatManager.java
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
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,78 +1,51 @@
|
|||||||
package com.gmail.nossr50.chat;
|
package com.gmail.nossr50.chat;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.events.chat.McMMOChatEvent;
|
||||||
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;
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
|
|
||||||
public final class ChatManager {
|
public abstract class ChatManager {
|
||||||
public ChatManager() {}
|
protected Plugin plugin;
|
||||||
|
protected boolean useDisplayNames;
|
||||||
|
protected String chatPrefix;
|
||||||
|
|
||||||
public static void handleAdminChat(Plugin plugin, String playerName, String displayName, String message, boolean isAsync) {
|
protected String displayName;
|
||||||
McMMOAdminChatEvent chatEvent = new McMMOAdminChatEvent(plugin, playerName, displayName, message, isAsync);
|
protected String message;
|
||||||
mcMMO.p.getServer().getPluginManager().callEvent(chatEvent);
|
|
||||||
|
|
||||||
if (chatEvent.isCancelled()) {
|
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()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Config.getInstance().getAdminDisplayNames()) {
|
displayName = useDisplayNames ? event.getDisplayName() : event.getSender();
|
||||||
displayName = chatEvent.getDisplayName();
|
message = LocaleLoader.getString(chatPrefix, displayName) + event.getMessage();
|
||||||
}
|
|
||||||
else {
|
|
||||||
displayName = chatEvent.getSender();
|
|
||||||
}
|
|
||||||
|
|
||||||
String adminMessage = chatEvent.getMessage();
|
sendMessage();
|
||||||
|
|
||||||
mcMMO.p.getServer().broadcast(LocaleLoader.getString("Commands.AdminChat.Prefix", displayName) + adminMessage, "mcmmo.chat.adminchat");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handleAdminChat(Plugin plugin, String senderName, String message) {
|
public void handleChat(String senderName, String message) {
|
||||||
handleAdminChat(plugin, senderName, senderName, message);
|
handleChat(senderName, senderName, message, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handleAdminChat(Plugin plugin, String playerName, String displayName, String message) {
|
public void handleChat(Player player, String message, boolean isAsync) {
|
||||||
handleAdminChat(plugin, playerName, displayName, message, false);
|
handleChat(player.getName(), player.getDisplayName(), message, isAsync);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handlePartyChat(Plugin plugin, Party party, String playerName, String displayName, String message, boolean isAsync) {
|
public void handleChat(String senderName, String displayName, String message) {
|
||||||
String partyName = party.getName();
|
handleChat(senderName, displayName, message, false);
|
||||||
|
|
||||||
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 static void handlePartyChat(Plugin plugin, Party party, String senderName, String message) {
|
public abstract void handleChat(String senderName, String displayName, String message, boolean isAsync);
|
||||||
handlePartyChat(plugin, party, senderName, senderName, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void handlePartyChat(Plugin plugin, Party party, String playerName, String displayName, String message) {
|
protected abstract void sendMessage();
|
||||||
handlePartyChat(plugin, party, playerName, displayName, message, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
29
src/main/java/com/gmail/nossr50/chat/ChatManagerFactory.java
Normal file
29
src/main/java/com/gmail/nossr50/chat/ChatManagerFactory.java
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
34
src/main/java/com/gmail/nossr50/chat/PartyChatManager.java
Normal file
34
src/main/java/com/gmail/nossr50/chat/PartyChatManager.java
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
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,6 +7,7 @@ import java.util.Set;
|
|||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.TabExecutor;
|
import org.bukkit.command.TabExecutor;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.util.StringUtil;
|
import org.bukkit.util.StringUtil;
|
||||||
|
|
||||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||||
@@ -29,7 +30,7 @@ public class KrakenCommand implements TabExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
UserManager.getPlayer(sender.getName()).getFishingManager().unleashTheKraken();
|
UserManager.getPlayer((Player) sender).getFishingManager().unleashTheKraken();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import java.util.List;
|
|||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.TabExecutor;
|
import org.bukkit.command.TabExecutor;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||||
import com.gmail.nossr50.locale.LocaleLoader;
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
@@ -17,7 +18,7 @@ public class McnotifyCommand implements TabExecutor {
|
|||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
switch (args.length) {
|
switch (args.length) {
|
||||||
case 0:
|
case 0:
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer((Player) sender);
|
||||||
|
|
||||||
sender.sendMessage(LocaleLoader.getString("Commands.Notifications." + (mcMMOPlayer.useChatNotifications() ? "Off" : "On")));
|
sender.sendMessage(LocaleLoader.getString("Commands.Notifications." + (mcMMOPlayer.useChatNotifications() ? "Off" : "On")));
|
||||||
mcMMOPlayer.toggleChatNotifications();
|
mcMMOPlayer.toggleChatNotifications();
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import java.util.List;
|
|||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.TabExecutor;
|
import org.bukkit.command.TabExecutor;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.util.StringUtil;
|
import org.bukkit.util.StringUtil;
|
||||||
|
|
||||||
import com.gmail.nossr50.datatypes.MobHealthbarType;
|
import com.gmail.nossr50.datatypes.MobHealthbarType;
|
||||||
@@ -38,7 +39,7 @@ public class MobhealthCommand implements TabExecutor {
|
|||||||
|
|
||||||
switch (args.length) {
|
switch (args.length) {
|
||||||
case 1:
|
case 1:
|
||||||
PlayerProfile playerProfile = UserManager.getPlayer(sender.getName()).getProfile();
|
PlayerProfile playerProfile = UserManager.getPlayer((Player) sender).getProfile();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
MobHealthbarType type = MobHealthbarType.valueOf(args[0].toUpperCase().trim());
|
MobHealthbarType type = MobHealthbarType.valueOf(args[0].toUpperCase().trim());
|
||||||
|
|||||||
@@ -33,8 +33,8 @@ public abstract class ToggleCommand implements TabExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
player = (Player) sender;
|
||||||
player = mcMMOPlayer.getPlayer();
|
mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
|
|
||||||
applyCommandAction();
|
applyCommandAction();
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
package com.gmail.nossr50.commands.chat;
|
package com.gmail.nossr50.commands.chat;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
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.ChatMode;
|
||||||
import com.gmail.nossr50.locale.LocaleLoader;
|
|
||||||
|
|
||||||
public class AdminChatCommand extends ChatCommand {
|
public class AdminChatCommand extends ChatCommand {
|
||||||
public AdminChatCommand() {
|
public AdminChatCommand() {
|
||||||
@@ -15,12 +11,6 @@ public class AdminChatCommand extends ChatCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void handleChatSending(CommandSender sender, String[] args) {
|
protected void handleChatSending(CommandSender sender, String[] args) {
|
||||||
if (sender instanceof Player) {
|
chatManager.handleChat(sender.getName(), getDisplayName(sender), buildChatMessage(args, 0));
|
||||||
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,8 +6,12 @@ import java.util.List;
|
|||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.TabExecutor;
|
import org.bukkit.command.TabExecutor;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.util.StringUtil;
|
import org.bukkit.util.StringUtil;
|
||||||
|
|
||||||
|
import com.gmail.nossr50.mcMMO;
|
||||||
|
import com.gmail.nossr50.chat.ChatManager;
|
||||||
|
import com.gmail.nossr50.chat.ChatManagerFactory;
|
||||||
import com.gmail.nossr50.chat.ChatMode;
|
import com.gmail.nossr50.chat.ChatMode;
|
||||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||||
import com.gmail.nossr50.locale.LocaleLoader;
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
@@ -18,10 +22,12 @@ import com.google.common.collect.ImmutableList;
|
|||||||
|
|
||||||
public abstract class ChatCommand implements TabExecutor {
|
public abstract class ChatCommand implements TabExecutor {
|
||||||
protected ChatMode chatMode;
|
protected ChatMode chatMode;
|
||||||
|
protected ChatManager chatManager;
|
||||||
private McMMOPlayer mcMMOPlayer;
|
private McMMOPlayer mcMMOPlayer;
|
||||||
|
|
||||||
public ChatCommand(ChatMode chatMode) {
|
public ChatCommand(ChatMode chatMode) {
|
||||||
this.chatMode = chatMode;
|
this.chatMode = chatMode;
|
||||||
|
this.chatManager = ChatManagerFactory.getChatManager(mcMMO.p, chatMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -32,7 +38,7 @@ public abstract class ChatCommand implements TabExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
mcMMOPlayer = UserManager.getPlayer((Player) sender);
|
||||||
|
|
||||||
if (chatMode.isEnabled(mcMMOPlayer)) {
|
if (chatMode.isEnabled(mcMMOPlayer)) {
|
||||||
disableChatMode(sender);
|
disableChatMode(sender);
|
||||||
@@ -49,7 +55,7 @@ public abstract class ChatCommand implements TabExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
mcMMOPlayer = UserManager.getPlayer((Player) sender);
|
||||||
|
|
||||||
enableChatMode(sender);
|
enableChatMode(sender);
|
||||||
return true;
|
return true;
|
||||||
@@ -60,7 +66,7 @@ public abstract class ChatCommand implements TabExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
mcMMOPlayer = UserManager.getPlayer((Player) sender);
|
||||||
|
|
||||||
disableChatMode(sender);
|
disableChatMode(sender);
|
||||||
return true;
|
return true;
|
||||||
@@ -96,6 +102,10 @@ public abstract class ChatCommand implements TabExecutor {
|
|||||||
return builder.toString();
|
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);
|
protected abstract void handleChatSending(CommandSender sender, String[] args);
|
||||||
|
|
||||||
private void enableChatMode(CommandSender sender) {
|
private void enableChatMode(CommandSender sender) {
|
||||||
|
|||||||
@@ -3,9 +3,8 @@ package com.gmail.nossr50.commands.chat;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
|
||||||
import com.gmail.nossr50.chat.ChatManager;
|
|
||||||
import com.gmail.nossr50.chat.ChatMode;
|
import com.gmail.nossr50.chat.ChatMode;
|
||||||
|
import com.gmail.nossr50.chat.PartyChatManager;
|
||||||
import com.gmail.nossr50.datatypes.party.Party;
|
import com.gmail.nossr50.datatypes.party.Party;
|
||||||
import com.gmail.nossr50.locale.LocaleLoader;
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
import com.gmail.nossr50.party.PartyManager;
|
import com.gmail.nossr50.party.PartyManager;
|
||||||
@@ -18,16 +17,18 @@ public class PartyChatCommand extends ChatCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void handleChatSending(CommandSender sender, String[] args) {
|
protected void handleChatSending(CommandSender sender, String[] args) {
|
||||||
|
Party party;
|
||||||
|
String message;
|
||||||
|
|
||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
Player player = (Player) sender;
|
party = UserManager.getPlayer((Player) sender).getParty();
|
||||||
Party party = UserManager.getPlayer(player).getParty();
|
|
||||||
|
|
||||||
if (party == null) {
|
if (party == null) {
|
||||||
sender.sendMessage(LocaleLoader.getString("Commands.Party.None"));
|
sender.sendMessage(LocaleLoader.getString("Commands.Party.None"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatManager.handlePartyChat(mcMMO.p, party, player.getName(), player.getDisplayName(), buildChatMessage(args, 0));
|
message = buildChatMessage(args, 0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
@@ -35,14 +36,17 @@ public class PartyChatCommand extends ChatCommand {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Party party = PartyManager.getParty(args[0]);
|
party = PartyManager.getParty(args[0]);
|
||||||
|
|
||||||
if (party == null) {
|
if (party == null) {
|
||||||
sender.sendMessage(LocaleLoader.getString("Party.InvalidName"));
|
sender.sendMessage(LocaleLoader.getString("Party.InvalidName"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatManager.handlePartyChat(mcMMO.p, party, LocaleLoader.getString("Commands.Chat.Console"), buildChatMessage(args, 1));
|
message = buildChatMessage(args, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
((PartyChatManager) chatManager).setParty(party);
|
||||||
|
chatManager.handleChat(sender.getName(), getDisplayName(sender), message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import org.bukkit.command.TabExecutor;
|
|||||||
import org.bukkit.util.StringUtil;
|
import org.bukkit.util.StringUtil;
|
||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
|
||||||
import com.gmail.nossr50.locale.LocaleLoader;
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
import com.gmail.nossr50.util.commands.CommandUtils;
|
import com.gmail.nossr50.util.commands.CommandUtils;
|
||||||
import com.gmail.nossr50.util.player.UserManager;
|
import com.gmail.nossr50.util.player.UserManager;
|
||||||
@@ -22,7 +21,7 @@ public class McremoveCommand implements TabExecutor {
|
|||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
switch (args.length) {
|
switch (args.length) {
|
||||||
case 1:
|
case 1:
|
||||||
if (UserManager.getPlayer(args[0]) == null && CommandUtils.unloadedProfile(sender, new PlayerProfile(args[0], false))) {
|
if (UserManager.getPlayer(args[0]) == null && CommandUtils.unloadedProfile(sender, mcMMO.getDatabaseManager().loadPlayerProfile(args[0], false))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
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,41 +9,130 @@ import org.bukkit.entity.Player;
|
|||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.config.Config;
|
import com.gmail.nossr50.config.Config;
|
||||||
|
import com.gmail.nossr50.database.DatabaseManager;
|
||||||
|
import com.gmail.nossr50.database.DatabaseManagerFactory;
|
||||||
|
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||||
import com.gmail.nossr50.locale.LocaleLoader;
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
import com.gmail.nossr50.runnables.database.SQLConversionTask;
|
import com.gmail.nossr50.runnables.database.ConversionTask;
|
||||||
import com.gmail.nossr50.util.player.UserManager;
|
import com.gmail.nossr50.util.player.UserManager;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
public class MmoupdateCommand implements TabExecutor {
|
public class MmoupdateCommand implements TabExecutor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
if (!Config.getInstance().getUseMySQL()) {
|
|
||||||
sender.sendMessage("SQL Mode is not enabled."); // TODO: Localize
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (args.length) {
|
switch (args.length) {
|
||||||
case 0:
|
case 1:
|
||||||
sender.sendMessage(LocaleLoader.getString("Commands.mmoupdate.Start"));
|
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
|
||||||
UserManager.saveAll();
|
UserManager.saveAll();
|
||||||
UserManager.clearAll();
|
UserManager.clearAll();
|
||||||
new SQLConversionTask().runTaskLaterAsynchronously(mcMMO.p, 1);
|
|
||||||
|
|
||||||
for (Player player : mcMMO.p.getServer().getOnlinePlayers()) {
|
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);
|
UserManager.addUser(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
sender.sendMessage(LocaleLoader.getString("Commands.mmoupdate.Finish"));
|
// Schedule the task for all users
|
||||||
|
new ConversionTask(oldDb, sender, oldType, newType).runTaskAsynchronously(mcMMO.p);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return false;
|
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";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||||
return ImmutableList.of();
|
Class<?> clazz = DatabaseManagerFactory.getCustomDatabaseManagerClass();
|
||||||
|
if (clazz != null) {
|
||||||
|
return ImmutableList.of("flatfile", "sql", clazz.getName());
|
||||||
|
}
|
||||||
|
return ImmutableList.of("flatfile", "sql");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import org.bukkit.command.TabExecutor;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.util.StringUtil;
|
import org.bukkit.util.StringUtil;
|
||||||
|
|
||||||
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||||
@@ -46,8 +47,8 @@ public abstract class ExperienceCommand implements TabExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
player = (Player) sender;
|
||||||
player = mcMMOPlayer.getPlayer();
|
mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
profile = mcMMOPlayer.getProfile();
|
profile = mcMMOPlayer.getProfile();
|
||||||
|
|
||||||
editValues();
|
editValues();
|
||||||
@@ -68,7 +69,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 the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
|
||||||
if (mcMMOPlayer == null) {
|
if (mcMMOPlayer == null) {
|
||||||
profile = new PlayerProfile(args[0], false);
|
profile = mcMMO.getDatabaseManager().loadPlayerProfile(args[0], false);
|
||||||
|
|
||||||
if (CommandUtils.unloadedProfile(sender, profile)) {
|
if (CommandUtils.unloadedProfile(sender, profile)) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ package com.gmail.nossr50.commands.experience;
|
|||||||
|
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
|
||||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||||
import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent;
|
import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent;
|
||||||
import com.gmail.nossr50.locale.LocaleLoader;
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
@@ -39,8 +39,8 @@ public class SkillresetCommand extends ExperienceCommand {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
player = (Player) sender;
|
||||||
player = mcMMOPlayer.getPlayer();
|
mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
profile = mcMMOPlayer.getProfile();
|
profile = mcMMOPlayer.getProfile();
|
||||||
|
|
||||||
editValues();
|
editValues();
|
||||||
@@ -60,7 +60,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 the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
|
||||||
if (mcMMOPlayer == null) {
|
if (mcMMOPlayer == null) {
|
||||||
profile = new PlayerProfile(args[0], false);
|
profile = mcMMO.getDatabaseManager().loadPlayerProfile(args[0], false);
|
||||||
|
|
||||||
if (CommandUtils.unloadedProfile(sender, profile)) {
|
if (CommandUtils.unloadedProfile(sender, profile)) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ public class PartyAcceptCommand implements CommandExecutor {
|
|||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
switch (args.length) {
|
switch (args.length) {
|
||||||
case 1:
|
case 1:
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
Player player = (Player) sender;
|
||||||
Player player = mcMMOPlayer.getPlayer();
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
|
|
||||||
if (!mcMMOPlayer.hasPartyInvite()) {
|
if (!mcMMOPlayer.hasPartyInvite()) {
|
||||||
sender.sendMessage(LocaleLoader.getString("mcMMO.NoInvites"));
|
sender.sendMessage(LocaleLoader.getString("mcMMO.NoInvites"));
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.gmail.nossr50.commands.party;
|
|||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.gmail.nossr50.datatypes.party.Party;
|
import com.gmail.nossr50.datatypes.party.Party;
|
||||||
import com.gmail.nossr50.locale.LocaleLoader;
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
@@ -14,7 +15,7 @@ public class PartyChangeOwnerCommand implements CommandExecutor {
|
|||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
switch (args.length) {
|
switch (args.length) {
|
||||||
case 2:
|
case 2:
|
||||||
Party playerParty = UserManager.getPlayer(sender.getName()).getParty();
|
Party playerParty = UserManager.getPlayer((Player) sender).getParty();
|
||||||
|
|
||||||
if (!playerParty.getMembers().contains(args[1])) {
|
if (!playerParty.getMembers().contains(args[1])) {
|
||||||
sender.sendMessage(LocaleLoader.getString("Party.NotInYourParty", args[1]));
|
sender.sendMessage(LocaleLoader.getString("Party.NotInYourParty", args[1]));
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.gmail.nossr50.commands.party;
|
|||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.gmail.nossr50.datatypes.party.Party;
|
import com.gmail.nossr50.datatypes.party.Party;
|
||||||
import com.gmail.nossr50.locale.LocaleLoader;
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
@@ -13,7 +14,7 @@ public class PartyChangePasswordCommand implements CommandExecutor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
playerParty = UserManager.getPlayer(sender.getName()).getParty();
|
playerParty = UserManager.getPlayer((Player) sender).getParty();
|
||||||
|
|
||||||
switch (args.length) {
|
switch (args.length) {
|
||||||
case 1:
|
case 1:
|
||||||
|
|||||||
@@ -70,8 +70,8 @@ public class PartyCommand implements TabExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
player = (Player) sender;
|
||||||
player = mcMMOPlayer.getPlayer();
|
mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
|
|
||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
if (!mcMMOPlayer.inParty()) {
|
if (!mcMMOPlayer.inParty()) {
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ public class PartyCreateCommand implements CommandExecutor {
|
|||||||
case 3:
|
case 3:
|
||||||
Party newParty = PartyManager.getParty(args[1]);
|
Party newParty = PartyManager.getParty(args[1]);
|
||||||
|
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
Player player = (Player) sender;
|
||||||
Player player = mcMMOPlayer.getPlayer();
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
|
|
||||||
// Check to see if the party exists, and if it does cancel creating a new party
|
// Check to see if the party exists, and if it does cancel creating a new party
|
||||||
if (PartyManager.checkPartyExistence(player, newParty, args[1])) {
|
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) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
switch (args.length) {
|
switch (args.length) {
|
||||||
case 1:
|
case 1:
|
||||||
Party playerParty = UserManager.getPlayer(sender.getName()).getParty();
|
Party playerParty = UserManager.getPlayer((Player) sender).getParty();
|
||||||
String partyName = playerParty.getName();
|
String partyName = playerParty.getName();
|
||||||
|
|
||||||
for (Player member : playerParty.getOnlineMembers()) {
|
for (Player member : playerParty.getOnlineMembers()) {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public class PartyExpShareCommand implements CommandExecutor {
|
|||||||
|
|
||||||
switch (args.length) {
|
switch (args.length) {
|
||||||
case 2:
|
case 2:
|
||||||
playerParty = UserManager.getPlayer(sender.getName()).getParty();
|
playerParty = UserManager.getPlayer((Player) sender).getParty();
|
||||||
|
|
||||||
if (args[1].equalsIgnoreCase("none") || CommandUtils.shouldDisableToggle(args[1])) {
|
if (args[1].equalsIgnoreCase("none") || CommandUtils.shouldDisableToggle(args[1])) {
|
||||||
handleChangingShareMode(ShareMode.NONE);
|
handleChangingShareMode(ShareMode.NONE);
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ public class PartyInfoCommand implements CommandExecutor {
|
|||||||
switch (args.length) {
|
switch (args.length) {
|
||||||
case 0:
|
case 0:
|
||||||
case 1:
|
case 1:
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
player = (Player) sender;
|
||||||
player = mcMMOPlayer.getPlayer();
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
playerParty = mcMMOPlayer.getParty();
|
playerParty = mcMMOPlayer.getParty();
|
||||||
|
|
||||||
displayPartyHeader();
|
displayPartyHeader();
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ public class PartyInviteCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Player target = mcMMOTarget.getPlayer();
|
Player target = mcMMOTarget.getPlayer();
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
Player player = (Player) sender;
|
||||||
Player player = mcMMOPlayer.getPlayer();
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
|
|
||||||
if (player.equals(target)) {
|
if (player.equals(target)) {
|
||||||
sender.sendMessage(LocaleLoader.getString("Party.Invite.Self"));
|
sender.sendMessage(LocaleLoader.getString("Party.Invite.Self"));
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public class PartyItemShareCommand implements CommandExecutor {
|
|||||||
|
|
||||||
switch (args.length) {
|
switch (args.length) {
|
||||||
case 2:
|
case 2:
|
||||||
playerParty = UserManager.getPlayer(sender.getName()).getParty();
|
playerParty = UserManager.getPlayer((Player) sender).getParty();
|
||||||
ShareMode mode = ShareMode.getShareMode(args[1].toUpperCase());
|
ShareMode mode = ShareMode.getShareMode(args[1].toUpperCase());
|
||||||
|
|
||||||
if (mode == null) {
|
if (mode == null) {
|
||||||
@@ -38,7 +38,7 @@ public class PartyItemShareCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
playerParty = UserManager.getPlayer(sender.getName()).getParty();
|
playerParty = UserManager.getPlayer((Player) sender).getParty();
|
||||||
boolean toggle = false;
|
boolean toggle = false;
|
||||||
|
|
||||||
if (CommandUtils.shouldEnableToggle(args[2])) {
|
if (CommandUtils.shouldEnableToggle(args[2])) {
|
||||||
|
|||||||
@@ -77,8 +77,8 @@ public class PartyJoinCommand implements CommandExecutor {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
player = (Player) sender;
|
||||||
player = mcMMOPlayer.getPlayer();
|
mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
|
|
||||||
playerParty = mcMMOPlayer.getParty();
|
playerParty = mcMMOPlayer.getParty();
|
||||||
targetParty = mcMMOTarget.getParty();
|
targetParty = mcMMOTarget.getParty();
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public class PartyKickCommand implements CommandExecutor {
|
|||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
switch (args.length) {
|
switch (args.length) {
|
||||||
case 2:
|
case 2:
|
||||||
Party playerParty = UserManager.getPlayer(sender.getName()).getParty();
|
Party playerParty = UserManager.getPlayer((Player) sender).getParty();
|
||||||
OfflinePlayer target = mcMMO.p.getServer().getOfflinePlayer(args[1]);
|
OfflinePlayer target = mcMMO.p.getServer().getOfflinePlayer(args[1]);
|
||||||
|
|
||||||
if (!playerParty.getMembers().contains(target.getName())) {
|
if (!playerParty.getMembers().contains(target.getName())) {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.gmail.nossr50.commands.party;
|
|||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.gmail.nossr50.datatypes.party.Party;
|
import com.gmail.nossr50.datatypes.party.Party;
|
||||||
import com.gmail.nossr50.locale.LocaleLoader;
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
@@ -15,7 +16,7 @@ public class PartyLockCommand implements CommandExecutor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
playerParty = UserManager.getPlayer(sender.getName()).getParty();
|
playerParty = UserManager.getPlayer((Player) sender).getParty();
|
||||||
|
|
||||||
switch (args.length) {
|
switch (args.length) {
|
||||||
case 1:
|
case 1:
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public class PartyRenameCommand implements CommandExecutor {
|
|||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
switch (args.length) {
|
switch (args.length) {
|
||||||
case 2:
|
case 2:
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer((Player) sender);
|
||||||
Party playerParty = mcMMOPlayer.getParty();
|
Party playerParty = mcMMOPlayer.getParty();
|
||||||
|
|
||||||
String oldPartyName = playerParty.getName();
|
String oldPartyName = playerParty.getName();
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ public class PtpAcceptAnyCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
Player player = (Player) sender;
|
||||||
Player player = mcMMOPlayer.getPlayer();
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
|
|
||||||
if (mcMMOPlayer.getPtpConfirmRequired()) {
|
if (mcMMOPlayer.getPtpConfirmRequired()) {
|
||||||
player.sendMessage(LocaleLoader.getString("Commands.ptp.AcceptAny.Disabled"));
|
player.sendMessage(LocaleLoader.getString("Commands.ptp.AcceptAny.Disabled"));
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ public class PtpAcceptCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
Player player = (Player) sender;
|
||||||
Player player = mcMMOPlayer.getPlayer();
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
|
|
||||||
if (!mcMMOPlayer.hasPtpRequest()) {
|
if (!mcMMOPlayer.hasPtpRequest()) {
|
||||||
player.sendMessage(LocaleLoader.getString("Commands.ptp.NoRequests"));
|
player.sendMessage(LocaleLoader.getString("Commands.ptp.NoRequests"));
|
||||||
|
|||||||
@@ -51,8 +51,8 @@ public class PtpCommand implements TabExecutor {
|
|||||||
return ptpAcceptAnyCommand.onCommand(sender, command, label, args);
|
return ptpAcceptAnyCommand.onCommand(sender, command, label, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
Player player = (Player) sender;
|
||||||
Player player = mcMMOPlayer.getPlayer();
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
|
|
||||||
long recentlyHurt = mcMMOPlayer.getRecentlyHurt();
|
long recentlyHurt = mcMMOPlayer.getRecentlyHurt();
|
||||||
int hurtCooldown = Config.getInstance().getPTPCommandRecentlyHurtCooldown();
|
int hurtCooldown = Config.getInstance().getPTPCommandRecentlyHurtCooldown();
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ public class PtpToggleCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
Player player = (Player) sender;
|
||||||
Player player = mcMMOPlayer.getPlayer();
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
|
|
||||||
if (mcMMOPlayer.getPtpEnabled()) {
|
if (mcMMOPlayer.getPtpEnabled()) {
|
||||||
player.sendMessage(LocaleLoader.getString("Commands.ptp.Disabled"));
|
player.sendMessage(LocaleLoader.getString("Commands.ptp.Disabled"));
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import org.bukkit.command.TabExecutor;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.util.StringUtil;
|
import org.bukkit.util.StringUtil;
|
||||||
|
|
||||||
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.config.Config;
|
import com.gmail.nossr50.config.Config;
|
||||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||||
@@ -35,7 +36,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 the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
|
||||||
if (mcMMOPlayer == null) {
|
if (mcMMOPlayer == null) {
|
||||||
PlayerProfile profile = new PlayerProfile(args[0], false); // Temporary Profile
|
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(args[0], false); // Temporary Profile
|
||||||
|
|
||||||
if (CommandUtils.inspectOffline(sender, profile, Permissions.inspectOffline(sender))) {
|
if (CommandUtils.inspectOffline(sender, profile, Permissions.inspectOffline(sender))) {
|
||||||
return true;
|
return true;
|
||||||
@@ -69,7 +70,13 @@ public class InspectCommand implements TabExecutor {
|
|||||||
else {
|
else {
|
||||||
Player target = mcMMOPlayer.getPlayer();
|
Player target = mcMMOPlayer.getPlayer();
|
||||||
|
|
||||||
if (CommandUtils.tooFar(sender, target, Permissions.inspectFar(sender))) {
|
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))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import org.bukkit.util.StringUtil;
|
|||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.config.Config;
|
import com.gmail.nossr50.config.Config;
|
||||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
|
||||||
import com.gmail.nossr50.runnables.commands.McrankCommandAsyncTask;
|
import com.gmail.nossr50.runnables.commands.McrankCommandAsyncTask;
|
||||||
import com.gmail.nossr50.util.Permissions;
|
import com.gmail.nossr50.util.Permissions;
|
||||||
import com.gmail.nossr50.util.commands.CommandUtils;
|
import com.gmail.nossr50.util.commands.CommandUtils;
|
||||||
@@ -61,7 +60,7 @@ public class McrankCommand implements TabExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (CommandUtils.inspectOffline(sender, new PlayerProfile(playerName, false), Permissions.mcrankOffline(sender))) {
|
else if (CommandUtils.inspectOffline(sender, mcMMO.getDatabaseManager().loadPlayerProfile(playerName, false), Permissions.mcrankOffline(sender))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ public class McstatsCommand implements TabExecutor {
|
|||||||
|
|
||||||
switch (args.length) {
|
switch (args.length) {
|
||||||
case 0:
|
case 0:
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
Player player = (Player) sender;
|
||||||
Player player = mcMMOPlayer.getPlayer();
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
|
|
||||||
if (Config.getInstance().getMcstatsScoreboardsEnabled()) {
|
if (Config.getInstance().getMcstatsScoreboardsEnabled()) {
|
||||||
ScoreboardManager.setupPlayerScoreboard(player.getName());
|
ScoreboardManager.setupPlayerScoreboard(player.getName());
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package com.gmail.nossr50.commands.player;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.TabExecutor;
|
import org.bukkit.command.TabExecutor;
|
||||||
@@ -12,10 +11,7 @@ import org.bukkit.util.StringUtil;
|
|||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.config.Config;
|
import com.gmail.nossr50.config.Config;
|
||||||
import com.gmail.nossr50.database.FlatfileDatabaseManager;
|
|
||||||
import com.gmail.nossr50.datatypes.database.PlayerStat;
|
|
||||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||||
import com.gmail.nossr50.locale.LocaleLoader;
|
|
||||||
import com.gmail.nossr50.runnables.commands.MctopCommandAsyncTask;
|
import com.gmail.nossr50.runnables.commands.MctopCommandAsyncTask;
|
||||||
import com.gmail.nossr50.util.Permissions;
|
import com.gmail.nossr50.util.Permissions;
|
||||||
import com.gmail.nossr50.util.StringUtils;
|
import com.gmail.nossr50.util.StringUtils;
|
||||||
@@ -84,39 +80,11 @@ public class MctopCommand implements TabExecutor {
|
|||||||
ScoreboardManager.enableGlobalStatsScoreboard((Player) sender, skill, page);
|
ScoreboardManager.enableGlobalStatsScoreboard((Player) sender, skill, page);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (Config.getInstance().getUseMySQL()) {
|
display(page, skill, sender);
|
||||||
sqlDisplay(page, skill, sender);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
flatfileDisplay(page, skill, sender);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void flatfileDisplay(int page, String skill, CommandSender sender) {
|
private void display(int page, String query, 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);
|
new MctopCommandAsyncTask(page, query, sender).runTaskAsynchronously(mcMMO.p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,8 +56,8 @@ public abstract class SkillCommand implements TabExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
player = (Player) sender;
|
||||||
player = mcMMOPlayer.getPlayer();
|
mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
|
|
||||||
switch (args.length) {
|
switch (args.length) {
|
||||||
case 0:
|
case 0:
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.gmail.nossr50.commands.spout;
|
|||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.TabExecutor;
|
import org.bukkit.command.TabExecutor;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.config.spout.SpoutConfig;
|
import com.gmail.nossr50.config.spout.SpoutConfig;
|
||||||
@@ -27,7 +28,7 @@ public abstract class SpoutCommand implements TabExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
playerProfile = UserManager.getPlayer(sender.getName()).getProfile();
|
playerProfile = UserManager.getPlayer((Player) sender).getProfile();
|
||||||
spoutHud = playerProfile.getSpoutHud();
|
spoutHud = playerProfile.getSpoutHud();
|
||||||
|
|
||||||
if (spoutHud == null) {
|
if (spoutHud == null) {
|
||||||
|
|||||||
@@ -46,9 +46,6 @@ public class Config extends AutoUpdateConfigLoader {
|
|||||||
public boolean getVerboseLoggingEnabled() { return config.getBoolean("General.Verbose_Logging", false); }
|
public boolean getVerboseLoggingEnabled() { return config.getBoolean("General.Verbose_Logging", false); }
|
||||||
public boolean getConfigOverwriteEnabled() { return config.getBoolean("General.Config_Update_Overwrite", true); }
|
public boolean getConfigOverwriteEnabled() { return config.getBoolean("General.Config_Update_Overwrite", true); }
|
||||||
|
|
||||||
public 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 getPartyDisplayNames() { return config.getBoolean("Commands.p.Use_Display_Names", true); }
|
||||||
public boolean getAdminDisplayNames() { return config.getBoolean("Commands.a.Use_Display_Names", true); }
|
public boolean getAdminDisplayNames() { return config.getBoolean("Commands.a.Use_Display_Names", true); }
|
||||||
|
|
||||||
@@ -293,7 +290,7 @@ public class Config extends AutoUpdateConfigLoader {
|
|||||||
public double getAnimalsXP() { return config.getDouble("Experience.Combat.Multiplier.Animals", 1.0); }
|
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 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 */
|
/* XP Formula Multiplier */
|
||||||
public int getFormulaMultiplierCurve() { return config.getInt("Experience.Formula.Curve_Modifier", 20); }
|
public int getFormulaMultiplierCurve() { return config.getInt("Experience.Formula.Curve_Modifier", 20); }
|
||||||
|
|||||||
@@ -442,13 +442,10 @@ public class TreasureConfig extends ConfigLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean noErrorsInTreasure(List<String> issues) {
|
private boolean noErrorsInTreasure(List<String> issues) {
|
||||||
if (issues.isEmpty()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (String issue : issues) {
|
for (String issue : issues) {
|
||||||
plugin.getLogger().warning(issue);
|
plugin.getLogger().warning(issue);
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
return issues.isEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,63 +1,89 @@
|
|||||||
package com.gmail.nossr50.database;
|
package com.gmail.nossr50.database;
|
||||||
|
|
||||||
import java.io.File;
|
import java.util.List;
|
||||||
import java.io.IOException;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.config.Config;
|
||||||
import com.gmail.nossr50.util.Misc;
|
import com.gmail.nossr50.datatypes.database.PlayerStat;
|
||||||
|
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||||
|
|
||||||
public class DatabaseManager {
|
public interface DatabaseManager {
|
||||||
private final mcMMO plugin;
|
// One month in milliseconds
|
||||||
private final boolean isUsingSQL;
|
public final long PURGE_TIME = 2630000000L * Config.getInstance().getOldUsersCutoff();
|
||||||
private File usersFile;
|
|
||||||
|
|
||||||
public DatabaseManager(final mcMMO plugin, final boolean isUsingSQL) {
|
/**
|
||||||
this.plugin = plugin;
|
* Purge users with 0 power level from the database.
|
||||||
this.isUsingSQL = isUsingSQL;
|
*/
|
||||||
|
public void purgePowerlessUsers();
|
||||||
|
|
||||||
if (isUsingSQL) {
|
/**
|
||||||
SQLDatabaseManager.checkConnected();
|
* Purge users who haven't logged on in over a certain time frame from the database.
|
||||||
SQLDatabaseManager.createStructure();
|
*/
|
||||||
}
|
public void purgeOldUsers();
|
||||||
else {
|
|
||||||
usersFile = new File(mcMMO.getUsersFilePath());
|
|
||||||
createFlatfileDatabase();
|
|
||||||
FlatfileDatabaseManager.updateLeaderboards();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void purgePowerlessUsers() {
|
/**
|
||||||
plugin.getLogger().info("Purging powerless users...");
|
* Remove a user from the database.
|
||||||
plugin.getLogger().info("Purged " + (isUsingSQL ? SQLDatabaseManager.purgePowerlessSQL() : FlatfileDatabaseManager.purgePowerlessFlatfile()) + " users 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 purgeOldUsers() {
|
/**
|
||||||
plugin.getLogger().info("Purging old users...");
|
* Save a user to the database.
|
||||||
plugin.getLogger().info("Purged " + (isUsingSQL ? SQLDatabaseManager.purgeOldSQL() : FlatfileDatabaseManager.removeOldFlatfileUsers()) + " users from the database.");
|
*
|
||||||
}
|
* @param profile The profile of the player to save
|
||||||
|
*/
|
||||||
|
public void saveUser(PlayerProfile profile);
|
||||||
|
|
||||||
public boolean removeUser(String playerName) {
|
/**
|
||||||
if (isUsingSQL ? SQLDatabaseManager.removeUserSQL(playerName) : FlatfileDatabaseManager.removeFlatFileUser(playerName)) {
|
* Retrieve leaderboard info.
|
||||||
Misc.profileCleanup(playerName);
|
*
|
||||||
return true;
|
* @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);
|
||||||
|
|
||||||
return false;
|
/**
|
||||||
}
|
* 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);
|
||||||
|
|
||||||
private void createFlatfileDatabase() {
|
/**
|
||||||
if (usersFile.exists()) {
|
* Add a new user to the database.
|
||||||
return;
|
*
|
||||||
}
|
* @param playerName The name of the player to be added to the database
|
||||||
|
*/
|
||||||
|
public void newUser(String playerName);
|
||||||
|
|
||||||
usersFile.getParentFile().mkdir();
|
/**
|
||||||
|
* 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);
|
||||||
|
|
||||||
try {
|
/**
|
||||||
plugin.debug("Creating mcmmo.users file...");
|
* Get all users currently stored in the database.
|
||||||
new File(mcMMO.getUsersFilePath()).createNewFile();
|
*
|
||||||
}
|
* @return list of playernames
|
||||||
catch (IOException e) {
|
*/
|
||||||
e.printStackTrace();
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
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,6 +1,9 @@
|
|||||||
package com.gmail.nossr50.database;
|
package com.gmail.nossr50.database;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.Closeable;
|
||||||
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -11,26 +14,448 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.config.Config;
|
import com.gmail.nossr50.config.Config;
|
||||||
|
import com.gmail.nossr50.datatypes.MobHealthbarType;
|
||||||
import com.gmail.nossr50.datatypes.database.PlayerStat;
|
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.skills.SkillType;
|
||||||
import com.gmail.nossr50.util.StringUtils;
|
import com.gmail.nossr50.datatypes.spout.huds.HudType;
|
||||||
|
import com.gmail.nossr50.util.Misc;
|
||||||
|
|
||||||
public final class FlatfileDatabaseManager {
|
public final class FlatfileDatabaseManager implements DatabaseManager {
|
||||||
private static HashMap<SkillType, List<PlayerStat>> playerStatHash = new HashMap<SkillType, List<PlayerStat>>();
|
private final HashMap<SkillType, List<PlayerStat>> playerStatHash = new HashMap<SkillType, List<PlayerStat>>();
|
||||||
private static List<PlayerStat> powerLevels = new ArrayList<PlayerStat>();
|
private final List<PlayerStat> powerLevels = new ArrayList<PlayerStat>();
|
||||||
private static long lastUpdate = 0;
|
private long lastUpdate = 0;
|
||||||
|
|
||||||
private static final long UPDATE_WAIT_TIME = 600000L; // 10 minutes
|
private final long UPDATE_WAIT_TIME = 600000L; // 10 minutes
|
||||||
private static final long ONE_MONTH = 2630000000L;
|
private final File usersFile;
|
||||||
|
private static final Object fileWritingLock = new Object();
|
||||||
|
|
||||||
private FlatfileDatabaseManager() {}
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the leader boards.
|
* Update the leader boards.
|
||||||
*/
|
*/
|
||||||
public static void updateLeaderboards() {
|
private 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
|
// 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) {
|
if (System.currentTimeMillis() < lastUpdate + UPDATE_WAIT_TIME) {
|
||||||
return;
|
return;
|
||||||
@@ -41,57 +466,63 @@ public final class FlatfileDatabaseManager {
|
|||||||
powerLevels.clear(); // Clear old values from the power levels
|
powerLevels.clear(); // Clear old values from the power levels
|
||||||
|
|
||||||
// Initialize lists
|
// Initialize lists
|
||||||
List<PlayerStat> mining = new ArrayList<PlayerStat>();
|
List<PlayerStat> mining = new ArrayList<PlayerStat>();
|
||||||
List<PlayerStat> woodcutting = new ArrayList<PlayerStat>();
|
List<PlayerStat> woodcutting = new ArrayList<PlayerStat>();
|
||||||
List<PlayerStat> herbalism = new ArrayList<PlayerStat>();
|
List<PlayerStat> herbalism = new ArrayList<PlayerStat>();
|
||||||
List<PlayerStat> excavation = new ArrayList<PlayerStat>();
|
List<PlayerStat> excavation = new ArrayList<PlayerStat>();
|
||||||
List<PlayerStat> acrobatics = new ArrayList<PlayerStat>();
|
List<PlayerStat> acrobatics = new ArrayList<PlayerStat>();
|
||||||
List<PlayerStat> repair = new ArrayList<PlayerStat>();
|
List<PlayerStat> repair = new ArrayList<PlayerStat>();
|
||||||
List<PlayerStat> swords = new ArrayList<PlayerStat>();
|
List<PlayerStat> swords = new ArrayList<PlayerStat>();
|
||||||
List<PlayerStat> axes = new ArrayList<PlayerStat>();
|
List<PlayerStat> axes = new ArrayList<PlayerStat>();
|
||||||
List<PlayerStat> archery = new ArrayList<PlayerStat>();
|
List<PlayerStat> archery = new ArrayList<PlayerStat>();
|
||||||
List<PlayerStat> unarmed = new ArrayList<PlayerStat>();
|
List<PlayerStat> unarmed = new ArrayList<PlayerStat>();
|
||||||
List<PlayerStat> taming = new ArrayList<PlayerStat>();
|
List<PlayerStat> taming = new ArrayList<PlayerStat>();
|
||||||
List<PlayerStat> fishing = new ArrayList<PlayerStat>();
|
List<PlayerStat> fishing = new ArrayList<PlayerStat>();
|
||||||
|
|
||||||
|
BufferedReader in = null;
|
||||||
// Read from the FlatFile database and fill our arrays with information
|
// Read from the FlatFile database and fill our arrays with information
|
||||||
try {
|
synchronized (fileWritingLock) {
|
||||||
BufferedReader in = new BufferedReader(new FileReader(usersFilePath));
|
try {
|
||||||
String line = "";
|
in = new BufferedReader(new FileReader(usersFilePath));
|
||||||
ArrayList<String> players = new ArrayList<String>();
|
String line = "";
|
||||||
|
ArrayList<String> players = new ArrayList<String>();
|
||||||
|
|
||||||
while ((line = in.readLine()) != null) {
|
while ((line = in.readLine()) != null) {
|
||||||
String[] data = line.split(":");
|
String[] data = line.split(":");
|
||||||
|
String playerName = data[0];
|
||||||
|
int powerLevel = 0;
|
||||||
|
|
||||||
String playerName = data[0];
|
// Prevent the same player from being added multiple times (I'd like to note that this shouldn't happen...)
|
||||||
int powerLevel = 0;
|
if (players.contains(playerName)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Prevent the same player from being added multiple times (I'd like to note that this shouldn't happen...)
|
players.add(playerName);
|
||||||
if (players.contains(playerName)) {
|
|
||||||
continue;
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
in.close();
|
catch (Exception e) {
|
||||||
}
|
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
|
||||||
catch (Exception e) {
|
}
|
||||||
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
|
finally {
|
||||||
|
tryClose(in);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SkillComparator c = new SkillComparator();
|
SkillComparator c = new SkillComparator();
|
||||||
@@ -125,159 +556,73 @@ public final class FlatfileDatabaseManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve leaderboard info.
|
* Checks that the file is present and valid
|
||||||
*
|
|
||||||
* @param skillType Skill to retrieve info on.
|
|
||||||
* @param pageNumber Which page in the leaderboards to retrieve
|
|
||||||
* @return the requested leaderboard information
|
|
||||||
*/
|
*/
|
||||||
public static List<PlayerStat> retrieveInfo(String skillType, int pageNumber, int statsPerPage) {
|
private void checkStructure() {
|
||||||
List<PlayerStat> statsList = skillType.equalsIgnoreCase("all") ? powerLevels : playerStatHash.get(SkillType.getSkill(skillType));
|
if (usersFile.exists()) {
|
||||||
int fromIndex = (Math.max(pageNumber, 1) - 1) * statsPerPage;
|
BufferedReader in = null;
|
||||||
|
FileWriter out = null;
|
||||||
|
String usersFilePath = mcMMO.getUsersFilePath();
|
||||||
|
|
||||||
return statsList.subList(Math.min(fromIndex, statsList.size()), Math.min(fromIndex + statsPerPage, statsList.size()));
|
synchronized (fileWritingLock) {
|
||||||
}
|
try {
|
||||||
|
in = new BufferedReader(new FileReader(usersFilePath));
|
||||||
|
StringBuilder writer = new StringBuilder();
|
||||||
|
String line = "";
|
||||||
|
|
||||||
public static boolean removeFlatFileUser(String playerName) {
|
while ((line = in.readLine()) != null) {
|
||||||
boolean worked = false;
|
String[] character = line.split(":");
|
||||||
|
|
||||||
BufferedReader in = null;
|
// If they're valid, rewrite them to the file.
|
||||||
FileWriter out = null;
|
if (character.length >= 37) {
|
||||||
String usersFilePath = mcMMO.getUsersFilePath();
|
writer.append(line).append("\r\n");
|
||||||
|
} else {
|
||||||
|
// Placeholder, repair row if needed (I.E. when new skills are added and such)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
usersFile.getParentFile().mkdir();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
FileReader file = new FileReader(usersFilePath);
|
mcMMO.p.debug("Creating mcmmo.users file...");
|
||||||
in = new BufferedReader(file);
|
new File(mcMMO.getUsersFilePath()).createNewFile();
|
||||||
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");
|
|
||||||
}
|
|
||||||
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) {
|
catch (IOException e) {
|
||||||
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
if (in != null) {
|
|
||||||
try {
|
|
||||||
in.close();
|
|
||||||
}
|
|
||||||
catch (IOException ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (out != null) {
|
|
||||||
try {
|
|
||||||
out.close();
|
|
||||||
}
|
|
||||||
catch (IOException ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return worked;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int purgePowerlessFlatfile() {
|
private void tryClose(Closeable c) {
|
||||||
mcMMO.p.getLogger().info("Purging powerless users...");
|
if (c == null) return;
|
||||||
|
|
||||||
int purgedUsers = 0;
|
|
||||||
|
|
||||||
for (PlayerStat stat : powerLevels) {
|
|
||||||
if (stat.statVal == 0 && !mcMMO.p.getServer().getOfflinePlayer(stat.name).isOnline() && removeFlatFileUser(stat.name)) {
|
|
||||||
purgedUsers++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return purgedUsers;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
try {
|
||||||
FileReader file = new FileReader(usersFilePath);
|
c.close();
|
||||||
in = new BufferedReader(file);
|
} catch (IOException e) {
|
||||||
StringBuilder writer = new StringBuilder();
|
e.printStackTrace();
|
||||||
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) {
|
private Integer getPlayerRank(String playerName, List<PlayerStat> statsList) {
|
||||||
int currentPos = 1;
|
|
||||||
|
|
||||||
if (statsList == null) {
|
if (statsList == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int currentPos = 1;
|
||||||
|
|
||||||
for (PlayerStat stat : statsList) {
|
for (PlayerStat stat : statsList) {
|
||||||
if (stat.name.equalsIgnoreCase(playerName)) {
|
if (stat.name.equalsIgnoreCase(playerName)) {
|
||||||
return currentPos;
|
return currentPos;
|
||||||
@@ -289,39 +634,86 @@ public final class FlatfileDatabaseManager {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String, Integer> getPlayerRanks(String playerName) {
|
private int putStat(List<PlayerStat> statList, String playerName, int statValue) {
|
||||||
updateLeaderboards();
|
statList.add(new PlayerStat(playerName, statValue));
|
||||||
|
return statValue;
|
||||||
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 static List<PlayerStat> getPlayerStats(String skillName) {
|
private class SkillComparator implements Comparator<PlayerStat> {
|
||||||
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
|
@Override
|
||||||
public int compare(PlayerStat o1, PlayerStat o2) {
|
public int compare(PlayerStat o1, PlayerStat o2) {
|
||||||
return (o2.statVal - o1.statVal);
|
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,7 +4,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
@@ -12,7 +11,8 @@ import com.gmail.nossr50.locale.LocaleLoader;
|
|||||||
import com.gmail.nossr50.party.ShareHandler.ShareMode;
|
import com.gmail.nossr50.party.ShareHandler.ShareMode;
|
||||||
|
|
||||||
public class Party {
|
public class Party {
|
||||||
private LinkedHashSet<String> members = new LinkedHashSet<String>();
|
private final LinkedHashSet<String> members = new LinkedHashSet<String>();
|
||||||
|
|
||||||
private String leader;
|
private String leader;
|
||||||
private String name;
|
private String name;
|
||||||
private String password;
|
private String password;
|
||||||
@@ -27,6 +27,30 @@ public class Party {
|
|||||||
private boolean shareWoodcuttingDrops = true;
|
private boolean shareWoodcuttingDrops = true;
|
||||||
private boolean shareMiscDrops = 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() {
|
public LinkedHashSet<String> getMembers() {
|
||||||
return members;
|
return members;
|
||||||
}
|
}
|
||||||
@@ -35,9 +59,10 @@ public class Party {
|
|||||||
List<Player> onlineMembers = new ArrayList<Player>();
|
List<Player> onlineMembers = new ArrayList<Player>();
|
||||||
|
|
||||||
for (String memberName : members) {
|
for (String memberName : members) {
|
||||||
OfflinePlayer member = mcMMO.p.getServer().getOfflinePlayer(memberName);
|
Player member = mcMMO.p.getServer().getPlayerExact(memberName);
|
||||||
if (member.isOnline()) {
|
|
||||||
onlineMembers.add(member.getPlayer());
|
if (member != null) {
|
||||||
|
onlineMembers.add(member);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,4 +191,28 @@ public class Party {
|
|||||||
return;
|
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,7 +7,6 @@ import java.util.Set;
|
|||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.config.Config;
|
import com.gmail.nossr50.config.Config;
|
||||||
@@ -54,7 +53,7 @@ public class McMMOPlayer {
|
|||||||
* we make sure that all class inheriting from SkillManager are instanced.
|
* we make sure that all class inheriting from SkillManager are instanced.
|
||||||
* Which solution is better, I let you decide. - bm01
|
* Which solution is better, I let you decide. - bm01
|
||||||
*/
|
*/
|
||||||
private Map<SkillType, SkillManager> skillManagers = new HashMap<SkillType, SkillManager>();
|
private final Map<SkillType, SkillManager> skillManagers = new HashMap<SkillType, SkillManager>();
|
||||||
|
|
||||||
private Party party;
|
private Party party;
|
||||||
private Party invite;
|
private Party invite;
|
||||||
@@ -76,11 +75,11 @@ public class McMMOPlayer {
|
|||||||
private int lastSalvageClick;
|
private int lastSalvageClick;
|
||||||
private boolean godMode;
|
private boolean godMode;
|
||||||
|
|
||||||
private Map<AbilityType, Boolean> abilityMode = new HashMap<AbilityType, Boolean>();
|
private final Map<AbilityType, Boolean> abilityMode = new HashMap<AbilityType, Boolean>();
|
||||||
private Map<AbilityType, Boolean> abilityInformed = new HashMap<AbilityType, Boolean>();
|
private final Map<AbilityType, Boolean> abilityInformed = new HashMap<AbilityType, Boolean>();
|
||||||
|
|
||||||
private Map<ToolType, Boolean> toolMode = new HashMap<ToolType, Boolean>();
|
private final Map<ToolType, Boolean> toolMode = new HashMap<ToolType, Boolean>();
|
||||||
private Map<ToolType, Integer> toolATS = new HashMap<ToolType, Integer>();
|
private final Map<ToolType, Integer> toolATS = new HashMap<ToolType, Integer>();
|
||||||
|
|
||||||
private int recentlyHurt;
|
private int recentlyHurt;
|
||||||
private int respawnATS;
|
private int respawnATS;
|
||||||
@@ -90,10 +89,14 @@ public class McMMOPlayer {
|
|||||||
private boolean isUsingUnarmed;
|
private boolean isUsingUnarmed;
|
||||||
|
|
||||||
public McMMOPlayer(Player player) {
|
public McMMOPlayer(Player player) {
|
||||||
|
this(player, mcMMO.getDatabaseManager().loadPlayerProfile(player.getName(), true));
|
||||||
|
}
|
||||||
|
|
||||||
|
public McMMOPlayer(Player player, PlayerProfile profile) {
|
||||||
String playerName = player.getName();
|
String playerName = player.getName();
|
||||||
|
|
||||||
this.player = player;
|
this.player = player;
|
||||||
profile = new PlayerProfile(playerName, true);
|
this.profile = profile;
|
||||||
party = PartyManager.getPlayerParty(playerName);
|
party = PartyManager.getPlayerParty(playerName);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -202,10 +205,10 @@ public class McMMOPlayer {
|
|||||||
* Set the mode of an ability.
|
* Set the mode of an ability.
|
||||||
*
|
*
|
||||||
* @param ability The ability to check
|
* @param ability The ability to check
|
||||||
* @param bool True if the ability is active, false otherwise
|
* @param isActive True if the ability is active, false otherwise
|
||||||
*/
|
*/
|
||||||
public void setAbilityMode(AbilityType ability, boolean bool) {
|
public void setAbilityMode(AbilityType ability, boolean isActive) {
|
||||||
abilityMode.put(ability, bool);
|
abilityMode.put(ability, isActive);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -222,10 +225,10 @@ public class McMMOPlayer {
|
|||||||
* Set the informed state of an ability.
|
* Set the informed state of an ability.
|
||||||
*
|
*
|
||||||
* @param ability The ability to check
|
* @param ability The ability to check
|
||||||
* @param bool True if the ability is informed, false otherwise
|
* @param isInformed True if the ability is informed, false otherwise
|
||||||
*/
|
*/
|
||||||
public void setAbilityInformed(AbilityType ability, boolean bool) {
|
public void setAbilityInformed(AbilityType ability, boolean isInformed) {
|
||||||
abilityInformed.put(ability, bool);
|
abilityInformed.put(ability, isInformed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -263,10 +266,10 @@ public class McMMOPlayer {
|
|||||||
* Set the current prep mode of a tool.
|
* Set the current prep mode of a tool.
|
||||||
*
|
*
|
||||||
* @param tool Tool to set the mode for
|
* @param tool Tool to set the mode for
|
||||||
* @param bool true if the tool should be prepped, false otherwise
|
* @param isPrepared true if the tool should be prepped, false otherwise
|
||||||
*/
|
*/
|
||||||
public void setToolPreparationMode(ToolType tool, boolean bool) {
|
public void setToolPreparationMode(ToolType tool, boolean isPrepared) {
|
||||||
toolMode.put(tool, bool);
|
toolMode.put(tool, isPrepared);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -332,7 +335,7 @@ public class McMMOPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void actualizeTeleportCommenceLocation(Player player) {
|
public void actualizeTeleportCommenceLocation(Player player) {
|
||||||
setTeleportCommenceLocation(player.getLocation());
|
teleportCommence = player.getLocation();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -500,6 +503,10 @@ public class McMMOPlayer {
|
|||||||
* @param xp Experience amount to add
|
* @param xp Experience amount to add
|
||||||
*/
|
*/
|
||||||
public void applyXpGain(SkillType skillType, float xp) {
|
public void applyXpGain(SkillType skillType, float xp) {
|
||||||
|
if (!Permissions.skillEnabled(player, skillType)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (skillType.isChildSkill()) {
|
if (skillType.isChildSkill()) {
|
||||||
Set<SkillType> parentSkills = FamilyTree.getParents(skillType);
|
Set<SkillType> parentSkills = FamilyTree.getParents(skillType);
|
||||||
|
|
||||||
@@ -510,10 +517,6 @@ public class McMMOPlayer {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Permissions.skillEnabled(player, skillType)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
McMMOPlayerXpGainEvent event = new McMMOPlayerXpGainEvent(player, skillType, xp);
|
McMMOPlayerXpGainEvent event = new McMMOPlayerXpGainEvent(player, skillType, xp);
|
||||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
||||||
|
|
||||||
@@ -529,7 +532,7 @@ public class McMMOPlayer {
|
|||||||
spoutHud.setLastGained(skillType);
|
spoutHud.setLastGained(skillType);
|
||||||
}
|
}
|
||||||
|
|
||||||
isUsingUnarmed = skillType == SkillType.UNARMED;
|
isUsingUnarmed = (skillType == SkillType.UNARMED);
|
||||||
SkillUtils.xpCheckSkill(skillType, player, profile);
|
SkillUtils.xpCheckSkill(skillType, player, profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -562,11 +565,7 @@ public class McMMOPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasPartyInvite() {
|
public boolean hasPartyInvite() {
|
||||||
if (invite != null) {
|
return (invite != null);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setParty(Party party) {
|
public void setParty(Party party) {
|
||||||
@@ -578,11 +577,7 @@ public class McMMOPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean inParty() {
|
public boolean inParty() {
|
||||||
if (party != null) {
|
return (party != null);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeParty() {
|
public void removeParty() {
|
||||||
@@ -610,11 +605,7 @@ public class McMMOPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasPtpRequest() {
|
public boolean hasPtpRequest() {
|
||||||
if (ptpRequest != null) {
|
return (ptpRequest != null);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removePtpRequest() {
|
public void removePtpRequest() {
|
||||||
@@ -646,11 +637,7 @@ public class McMMOPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setItemShareModifier(int modifier) {
|
public void setItemShareModifier(int modifier) {
|
||||||
if (modifier < 10) {
|
itemShareModifier = Math.max(10, modifier);
|
||||||
modifier = 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
itemShareModifier = modifier;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -693,15 +680,14 @@ public class McMMOPlayer {
|
|||||||
* @return Modified experience
|
* @return Modified experience
|
||||||
*/
|
*/
|
||||||
private float modifyXpGain(SkillType skillType, float xp) {
|
private float modifyXpGain(SkillType skillType, float xp) {
|
||||||
if (player.getGameMode() == GameMode.CREATIVE || (skillType.getMaxLevel() < profile.getSkillLevel(skillType) + 1) || (Config.getInstance().getPowerLevelCap() < getPowerLevel() + 1)) {
|
if (player.getGameMode() == GameMode.CREATIVE || (skillType.getMaxLevel() <= profile.getSkillLevel(skillType)) || (Config.getInstance().getPowerLevelCap() <= getPowerLevel())) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
xp = (float) (xp / skillType.getXpModifier() * Config.getInstance().getExperienceGainsGlobalMultiplier());
|
xp = (float) (xp / skillType.getXpModifier() * Config.getInstance().getExperienceGainsGlobalMultiplier());
|
||||||
|
|
||||||
if (Config.getInstance().getToolModsEnabled()) {
|
if (Config.getInstance().getToolModsEnabled()) {
|
||||||
ItemStack item = player.getItemInHand();
|
CustomTool tool = ModUtils.getToolFromItemStack(player.getItemInHand());
|
||||||
CustomTool tool = ModUtils.getToolFromItemStack(item);
|
|
||||||
|
|
||||||
if (tool != null) {
|
if (tool != null) {
|
||||||
xp *= tool.getXpMultiplier();
|
xp *= tool.getXpMultiplier();
|
||||||
|
|||||||
@@ -1,10 +1,5 @@
|
|||||||
package com.gmail.nossr50.datatypes.player;
|
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.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -14,18 +9,15 @@ import org.bukkit.scoreboard.Scoreboard;
|
|||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.config.Config;
|
import com.gmail.nossr50.config.Config;
|
||||||
import com.gmail.nossr50.config.spout.SpoutConfig;
|
import com.gmail.nossr50.config.spout.SpoutConfig;
|
||||||
import com.gmail.nossr50.database.SQLDatabaseManager;
|
|
||||||
import com.gmail.nossr50.datatypes.MobHealthbarType;
|
import com.gmail.nossr50.datatypes.MobHealthbarType;
|
||||||
import com.gmail.nossr50.datatypes.skills.AbilityType;
|
import com.gmail.nossr50.datatypes.skills.AbilityType;
|
||||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||||
import com.gmail.nossr50.datatypes.spout.huds.HudType;
|
import com.gmail.nossr50.datatypes.spout.huds.HudType;
|
||||||
import com.gmail.nossr50.datatypes.spout.huds.McMMOHud;
|
import com.gmail.nossr50.datatypes.spout.huds.McMMOHud;
|
||||||
import com.gmail.nossr50.skills.child.FamilyTree;
|
import com.gmail.nossr50.skills.child.FamilyTree;
|
||||||
import com.gmail.nossr50.util.Misc;
|
|
||||||
|
|
||||||
public class PlayerProfile {
|
public class PlayerProfile {
|
||||||
private final String playerName;
|
private final String playerName;
|
||||||
private int userId;
|
|
||||||
private boolean loaded;
|
private boolean loaded;
|
||||||
|
|
||||||
/* HUDs */
|
/* HUDs */
|
||||||
@@ -36,10 +28,10 @@ public class PlayerProfile {
|
|||||||
|
|
||||||
/* Skill Data */
|
/* Skill Data */
|
||||||
private final Map<SkillType, Integer> skills = new HashMap<SkillType, Integer>(); // Skill & Level
|
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
|
private final Map<AbilityType, Integer> skillsDATS = new HashMap<AbilityType, Integer>(); // Ability & Cooldown
|
||||||
|
|
||||||
public PlayerProfile(String playerName, boolean addNew) {
|
public PlayerProfile(String playerName) {
|
||||||
this.playerName = playerName;
|
this.playerName = playerName;
|
||||||
|
|
||||||
hudType = mcMMO.isSpoutEnabled() ? SpoutConfig.getInstance().getDefaultHudType() : HudType.DISABLED;
|
hudType = mcMMO.isSpoutEnabled() ? SpoutConfig.getInstance().getDefaultHudType() : HudType.DISABLED;
|
||||||
@@ -53,20 +45,31 @@ public class PlayerProfile {
|
|||||||
skills.put(skillType, 0);
|
skills.put(skillType, 0);
|
||||||
skillsXp.put(skillType, 0F);
|
skillsXp.put(skillType, 0F);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!loadPlayer() && addNew) {
|
public PlayerProfile(String playerName, boolean isLoaded) {
|
||||||
addPlayer();
|
this(playerName);
|
||||||
loaded = true;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
if (Config.getInstance().getUseMySQL()) {
|
mcMMO.getDatabaseManager().saveUser(this);
|
||||||
saveMySQL();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
saveFlatfile();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPlayerName() {
|
public String getPlayerName() {
|
||||||
@@ -138,7 +141,7 @@ public class PlayerProfile {
|
|||||||
/**
|
/**
|
||||||
* Set the current DATS of a skill.
|
* 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
|
* @param DATS the DATS of the ability
|
||||||
*/
|
*/
|
||||||
public void setSkillDATS(AbilityType abilityType, long DATS) {
|
public void setSkillDATS(AbilityType abilityType, long DATS) {
|
||||||
@@ -266,404 +269,4 @@ public class PlayerProfile {
|
|||||||
|
|
||||||
return sum / parents.size();
|
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]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,11 +56,7 @@ public class McMMOHud {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isMenuOpened() {
|
public boolean isMenuOpened() {
|
||||||
if (menu != null) {
|
return (menu != null);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void openMenu() {
|
public void openMenu() {
|
||||||
|
|||||||
@@ -338,7 +338,7 @@ public class BlockListener implements Listener {
|
|||||||
event.setInstaBreak(true);
|
event.setInstaBreak(true);
|
||||||
player.playSound(block.getLocation(), Sound.ITEM_PICKUP, Misc.POP_VOLUME, Misc.getPopPitch());
|
player.playSound(block.getLocation(), Sound.ITEM_PICKUP, Misc.POP_VOLUME, Misc.getPopPitch());
|
||||||
}
|
}
|
||||||
else if (Permissions.blockCracker(player) && SkillUtils.triggerCheck(player, block, AbilityType.BLOCK_CRACKER)) {
|
else if (mcMMOPlayer.getUnarmedManager().canUseBlockCracker() && SkillUtils.triggerCheck(player, block, AbilityType.BLOCK_CRACKER)) {
|
||||||
if (mcMMOPlayer.getUnarmedManager().blockCrackerCheck(blockState)) {
|
if (mcMMOPlayer.getUnarmedManager().blockCrackerCheck(blockState)) {
|
||||||
blockState.update();
|
blockState.update();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import org.bukkit.event.entity.EntityTameEvent;
|
|||||||
import org.bukkit.event.entity.EntityTargetEvent;
|
import org.bukkit.event.entity.EntityTargetEvent;
|
||||||
import org.bukkit.event.entity.ExplosionPrimeEvent;
|
import org.bukkit.event.entity.ExplosionPrimeEvent;
|
||||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||||
|
import org.bukkit.event.entity.ProjectileLaunchEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.metadata.FixedMetadataValue;
|
import org.bukkit.metadata.FixedMetadataValue;
|
||||||
|
|
||||||
@@ -59,19 +60,15 @@ public class EntityListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onEntityShootBow(EntityShootBowEvent event) {
|
public void onEntityShootBow(EntityShootBowEvent event) {
|
||||||
ItemStack bow = event.getBow();
|
|
||||||
|
|
||||||
if (bow == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Entity projectile = event.getProjectile();
|
Entity projectile = event.getProjectile();
|
||||||
|
|
||||||
if (!(projectile instanceof Arrow)) {
|
if (!(projectile instanceof Arrow)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bow.containsEnchantment(Enchantment.ARROW_INFINITE)) {
|
ItemStack bow = event.getBow();
|
||||||
|
|
||||||
|
if (bow != null && bow.containsEnchantment(Enchantment.ARROW_INFINITE)) {
|
||||||
projectile.setMetadata(mcMMO.infiniteArrowKey, mcMMO.metadataValue);
|
projectile.setMetadata(mcMMO.infiniteArrowKey, mcMMO.metadataValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,6 +76,18 @@ public class EntityListener implements Listener {
|
|||||||
projectile.setMetadata(mcMMO.arrowDistanceKey, new FixedMetadataValue(plugin, Archery.locationToString(projectile.getLocation())));
|
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())));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Monitor EntityChangeBlock events.
|
* Monitor EntityChangeBlock events.
|
||||||
*
|
*
|
||||||
@@ -161,7 +170,7 @@ public class EntityListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CombatUtils.combatChecks(event, attacker, target);
|
CombatUtils.processCombatAttack(event, attacker, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -314,6 +323,30 @@ 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.
|
* Monitor EntityDeath events.
|
||||||
*
|
*
|
||||||
@@ -509,20 +542,21 @@ public class EntityListener implements Listener {
|
|||||||
Entity entity = event.getEntity();
|
Entity entity = event.getEntity();
|
||||||
Entity target = event.getTarget();
|
Entity target = event.getTarget();
|
||||||
|
|
||||||
if (entity instanceof Tameable && target instanceof Player) {
|
if (!(entity instanceof Tameable) || !(target instanceof Player)) {
|
||||||
Player player = (Player) target;
|
return;
|
||||||
Tameable tameable = (Tameable) entity;
|
}
|
||||||
|
|
||||||
if (!CombatUtils.isFriendlyPet(player, tameable)) {
|
Player player = (Player) target;
|
||||||
return;
|
Tameable tameable = (Tameable) entity;
|
||||||
}
|
|
||||||
|
|
||||||
// isFriendlyPet ensures that the Tameable is: Tamed, owned by a player, and the owner is in the same party
|
if (!CombatUtils.isFriendlyPet(player, tameable)) {
|
||||||
// So we can make some assumptions here, about our casting and our check
|
return;
|
||||||
if (!(Permissions.friendlyFire(player) && Permissions.friendlyFire((Player) tameable.getOwner()))) {
|
}
|
||||||
event.setCancelled(true);
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,6 @@
|
|||||||
package com.gmail.nossr50.listeners;
|
package com.gmail.nossr50.listeners;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockState;
|
|
||||||
import org.bukkit.block.Furnace;
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@@ -18,16 +13,12 @@ import org.bukkit.event.inventory.FurnaceSmeltEvent;
|
|||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||||
import org.bukkit.inventory.FurnaceInventory;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.metadata.FixedMetadataValue;
|
import org.bukkit.metadata.FixedMetadataValue;
|
||||||
import org.bukkit.metadata.MetadataValue;
|
|
||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.config.Config;
|
|
||||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||||
import com.gmail.nossr50.skills.smelting.SmeltingManager;
|
import com.gmail.nossr50.runnables.PlayerUpdateInventoryTask;
|
||||||
import com.gmail.nossr50.util.ItemUtils;
|
import com.gmail.nossr50.util.ItemUtils;
|
||||||
import com.gmail.nossr50.util.Misc;
|
import com.gmail.nossr50.util.Misc;
|
||||||
import com.gmail.nossr50.util.Permissions;
|
import com.gmail.nossr50.util.Permissions;
|
||||||
@@ -41,7 +32,7 @@ public class InventoryListener implements Listener {
|
|||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onInventoryOpen(InventoryOpenEvent event) {
|
public void onInventoryOpen(InventoryOpenEvent event) {
|
||||||
HumanEntity player = event.getPlayer();
|
HumanEntity player = event.getPlayer();
|
||||||
|
|
||||||
@@ -49,25 +40,14 @@ public class InventoryListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Inventory inventory = event.getInventory();
|
Block furnaceBlock = Misc.processInventoryOpenorCloseEvent(event);
|
||||||
|
|
||||||
if (inventory instanceof FurnaceInventory) {
|
if (furnaceBlock != null && !furnaceBlock.hasMetadata(mcMMO.furnaceMetadataKey)) {
|
||||||
Furnace furnace = (Furnace) inventory.getHolder();
|
furnaceBlock.setMetadata(mcMMO.furnaceMetadataKey, new FixedMetadataValue(plugin, player.getName()));
|
||||||
|
|
||||||
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)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onInventoryClose(InventoryCloseEvent event) {
|
public void onInventoryClose(InventoryCloseEvent event) {
|
||||||
HumanEntity player = event.getPlayer();
|
HumanEntity player = event.getPlayer();
|
||||||
|
|
||||||
@@ -75,101 +55,65 @@ public class InventoryListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Inventory inventory = event.getInventory();
|
Block furnaceBlock = Misc.processInventoryOpenorCloseEvent(event);
|
||||||
|
|
||||||
if (inventory instanceof FurnaceInventory) {
|
if (furnaceBlock != null && furnaceBlock.hasMetadata(mcMMO.furnaceMetadataKey)) {
|
||||||
Furnace furnace = (Furnace) inventory.getHolder();
|
furnaceBlock.removeMetadata(mcMMO.furnaceMetadataKey, plugin);
|
||||||
|
|
||||||
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)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onFurnaceBurnEvent(FurnaceBurnEvent event) {
|
public void onFurnaceBurnEvent(FurnaceBurnEvent event) {
|
||||||
Block furnaceBlock = event.getBlock();
|
Block furnaceBlock = event.getBlock();
|
||||||
BlockState furnaceState = furnaceBlock.getState();
|
ItemStack smelting = Misc.getSmeltingFromFurnace(furnaceBlock);
|
||||||
|
|
||||||
if (furnaceState instanceof Furnace) {
|
if (!ItemUtils.isSmeltable(smelting)) {
|
||||||
ItemStack smelting = ((Furnace) furnaceState).getInventory().getSmelting();
|
return;
|
||||||
List<MetadataValue> metadata = furnaceBlock.getMetadata(mcMMO.furnaceMetadataKey);
|
|
||||||
|
|
||||||
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()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Player player = Misc.getPlayerFromFurnace(furnaceBlock);
|
||||||
|
|
||||||
|
if (Misc.isNPCEntity(player) || !Permissions.fuelEfficiency(player)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.setBurnTime(UserManager.getPlayer(player).getSmeltingManager().fuelEfficiency(event.getBurnTime()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onFurnaceSmeltEvent(FurnaceSmeltEvent event) {
|
public void onFurnaceSmeltEvent(FurnaceSmeltEvent event) {
|
||||||
Block furnaceBlock = event.getBlock();
|
Block furnaceBlock = event.getBlock();
|
||||||
BlockState furnaceState = furnaceBlock.getState();
|
ItemStack smelting = Misc.getSmeltingFromFurnace(furnaceBlock);
|
||||||
|
|
||||||
if (furnaceState instanceof Furnace) {
|
if (!ItemUtils.isSmeltable(smelting)) {
|
||||||
ItemStack smelting = ((Furnace) furnaceState).getInventory().getSmelting();
|
return;
|
||||||
List<MetadataValue> metadata = furnaceBlock.getMetadata(mcMMO.furnaceMetadataKey);
|
|
||||||
|
|
||||||
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()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Player player = Misc.getPlayerFromFurnace(furnaceBlock);
|
||||||
|
|
||||||
|
if (Misc.isNPCEntity(player) || !Permissions.skillEnabled(player, SkillType.SMELTING)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.setResult(UserManager.getPlayer(player).getSmeltingManager().smeltProcessing(smelting.getType(), event.getResult()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onFurnaceExtractEvent(FurnaceExtractEvent event) {
|
public void onFurnaceExtractEvent(FurnaceExtractEvent event) {
|
||||||
Block furnaceBlock = event.getBlock();
|
Block furnaceBlock = event.getBlock();
|
||||||
BlockState furnaceState = furnaceBlock.getState();
|
ItemStack result = Misc.getResultFromFurnace(furnaceBlock);
|
||||||
|
|
||||||
if (furnaceState instanceof Furnace) {
|
if (!ItemUtils.isSmelted(result)) {
|
||||||
ItemStack result = ((Furnace) furnaceState).getInventory().getResult();
|
return;
|
||||||
List<MetadataValue> metadata = furnaceBlock.getMetadata(mcMMO.furnaceMetadataKey);
|
|
||||||
|
|
||||||
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()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Player player = Misc.getPlayerFromFurnace(furnaceBlock);
|
||||||
|
|
||||||
|
if (Misc.isNPCEntity(player) || !Permissions.vanillaXpBoost(player, SkillType.SMELTING)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.setExpToDrop(UserManager.getPlayer(player).getSmeltingManager().vanillaXPBoost(event.getExpToDrop()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
@@ -179,18 +123,18 @@ public class InventoryListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onCraftItem(CraftItemEvent event) {
|
public void onCraftItem(CraftItemEvent event) {
|
||||||
ItemStack result = event.getRecipe().getResult();
|
|
||||||
final HumanEntity whoClicked = event.getWhoClicked();
|
final HumanEntity whoClicked = event.getWhoClicked();
|
||||||
|
|
||||||
if (!ItemUtils.isMcMMOItem(result) || Misc.isNPCEntity(whoClicked) || !(whoClicked instanceof Player)) {
|
if (Misc.isNPCEntity(whoClicked) || !(whoClicked instanceof Player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mcMMO.p.getServer().getScheduler().runTaskLater(mcMMO.p, new Runnable() {
|
ItemStack result = event.getRecipe().getResult();
|
||||||
@Override
|
|
||||||
public void run() {
|
if (!ItemUtils.isMcMMOItem(result)) {
|
||||||
((Player) whoClicked).updateInventory();
|
return;
|
||||||
}
|
}
|
||||||
}, 0);
|
|
||||||
|
new PlayerUpdateInventoryTask((Player) whoClicked).runTaskLater(plugin, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import org.bukkit.event.EventPriority;
|
|||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
|
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||||
@@ -22,7 +23,6 @@ import org.bukkit.event.player.PlayerFishEvent;
|
|||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerLoginEvent;
|
import org.bukkit.event.player.PlayerLoginEvent;
|
||||||
import org.bukkit.event.player.PlayerLoginEvent.Result;
|
|
||||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||||
@@ -30,11 +30,15 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.chat.ChatManager;
|
import com.gmail.nossr50.chat.ChatManager;
|
||||||
|
import com.gmail.nossr50.chat.ChatManagerFactory;
|
||||||
|
import com.gmail.nossr50.chat.ChatMode;
|
||||||
|
import com.gmail.nossr50.chat.PartyChatManager;
|
||||||
import com.gmail.nossr50.config.Config;
|
import com.gmail.nossr50.config.Config;
|
||||||
import com.gmail.nossr50.datatypes.party.Party;
|
import com.gmail.nossr50.datatypes.party.Party;
|
||||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||||
import com.gmail.nossr50.datatypes.skills.AbilityType;
|
import com.gmail.nossr50.datatypes.skills.AbilityType;
|
||||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||||
|
import com.gmail.nossr50.events.fake.FakeBlockBreakEvent;
|
||||||
import com.gmail.nossr50.locale.LocaleLoader;
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
import com.gmail.nossr50.party.ShareHandler;
|
import com.gmail.nossr50.party.ShareHandler;
|
||||||
import com.gmail.nossr50.runnables.skills.BleedTimerTask;
|
import com.gmail.nossr50.runnables.skills.BleedTimerTask;
|
||||||
@@ -127,27 +131,6 @@ public class PlayerListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle PlayerDropItem events that involve modifying the event.
|
* Handle PlayerDropItem events that involve modifying the event.
|
||||||
*
|
*
|
||||||
@@ -212,6 +195,13 @@ public class PlayerListener implements Listener {
|
|||||||
Block block = event.getPlayer().getTargetBlock(null, 100);
|
Block block = event.getPlayer().getTargetBlock(null, 100);
|
||||||
|
|
||||||
if (fishingManager.canIceFish(block)) {
|
if (fishingManager.canIceFish(block)) {
|
||||||
|
FakeBlockBreakEvent blockBreakEvent = new FakeBlockBreakEvent(block, player);
|
||||||
|
mcMMO.p.getServer().getPluginManager().callEvent(blockBreakEvent);
|
||||||
|
|
||||||
|
if (blockBreakEvent.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
fishingManager.iceFishing(hook, block);
|
fishingManager.iceFishing(hook, block);
|
||||||
}
|
}
|
||||||
@@ -276,6 +266,24 @@ public class PlayerListener implements Listener {
|
|||||||
BleedTimerTask.bleedOut(player); // Bleed it out
|
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.
|
* Monitor PlayerJoin events.
|
||||||
*
|
*
|
||||||
@@ -285,6 +293,13 @@ public class PlayerListener implements Listener {
|
|||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
|
if (Misc.isNPCEntity(player)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
UserManager.addUser(player).actualizeRespawnATS();
|
||||||
|
ScoreboardManager.enablePowerLevelDisplay(player);
|
||||||
|
|
||||||
if (Config.getInstance().getMOTDEnabled() && Permissions.motd(player)) {
|
if (Config.getInstance().getMOTDEnabled() && Permissions.motd(player)) {
|
||||||
Motd.displayAll(player);
|
Motd.displayAll(player);
|
||||||
}
|
}
|
||||||
@@ -343,26 +358,28 @@ public class PlayerListener implements Listener {
|
|||||||
case RIGHT_CLICK_BLOCK:
|
case RIGHT_CLICK_BLOCK:
|
||||||
int blockID = block.getTypeId();
|
int blockID = block.getTypeId();
|
||||||
|
|
||||||
/* REPAIR CHECKS */
|
if ((Config.getInstance().getAbilitiesOnlyActivateWhenSneaking() && player.isSneaking()) || !Config.getInstance().getAbilitiesOnlyActivateWhenSneaking()) {
|
||||||
if (blockID == Repair.repairAnvilId && Permissions.skillEnabled(player, SkillType.REPAIR) && mcMMO.getRepairableManager().isRepairable(heldItem)) {
|
/* REPAIR CHECKS */
|
||||||
RepairManager repairManager = mcMMOPlayer.getRepairManager();
|
if (blockID == Repair.repairAnvilId && Permissions.skillEnabled(player, SkillType.REPAIR) && mcMMO.getRepairableManager().isRepairable(heldItem)) {
|
||||||
event.setCancelled(true);
|
RepairManager repairManager = mcMMOPlayer.getRepairManager();
|
||||||
|
event.setCancelled(true);
|
||||||
|
|
||||||
// Make sure the player knows what he's doing when trying to repair an enchanted item
|
// 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)) {
|
if (!(heldItem.getEnchantments().size() > 0) || repairManager.checkConfirmation(blockID, true)) {
|
||||||
repairManager.handleRepair(heldItem);
|
repairManager.handleRepair(heldItem);
|
||||||
player.updateInventory();
|
player.updateInventory();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
/* SALVAGE CHECKS */
|
||||||
/* SALVAGE CHECKS */
|
else if (blockID == Repair.salvageAnvilId && Permissions.salvage(player) && Repair.isSalvageable(heldItem)) {
|
||||||
else if (blockID == Repair.salvageAnvilId && Permissions.salvage(player) && Repair.isSalvageable(heldItem) && !ItemUtils.isChainmailArmor(heldItem)) {
|
RepairManager repairManager = mcMMOPlayer.getRepairManager();
|
||||||
RepairManager repairManager = mcMMOPlayer.getRepairManager();
|
event.setCancelled(true);
|
||||||
event.setCancelled(true);
|
|
||||||
|
|
||||||
// Make sure the player knows what he's doing when trying to salvage an enchanted item
|
// 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)) {
|
if (!(heldItem.getEnchantments().size() > 0) || repairManager.checkConfirmation(blockID, true)) {
|
||||||
repairManager.handleSalvage(block.getLocation(), heldItem);
|
repairManager.handleSalvage(block.getLocation(), heldItem);
|
||||||
player.updateInventory();
|
player.updateInventory();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* BLAST MINING CHECK */
|
/* BLAST MINING CHECK */
|
||||||
@@ -380,24 +397,26 @@ public class PlayerListener implements Listener {
|
|||||||
case LEFT_CLICK_BLOCK:
|
case LEFT_CLICK_BLOCK:
|
||||||
blockID = block.getTypeId();
|
blockID = block.getTypeId();
|
||||||
|
|
||||||
/* REPAIR CHECKS */
|
if ((Config.getInstance().getAbilitiesOnlyActivateWhenSneaking() && player.isSneaking()) || !Config.getInstance().getAbilitiesOnlyActivateWhenSneaking()) {
|
||||||
if (blockID == Repair.repairAnvilId && Permissions.skillEnabled(player, SkillType.REPAIR) && mcMMO.getRepairableManager().isRepairable(heldItem)) {
|
/* REPAIR CHECKS */
|
||||||
RepairManager repairManager = mcMMOPlayer.getRepairManager();
|
if (blockID == Repair.repairAnvilId && Permissions.skillEnabled(player, SkillType.REPAIR) && mcMMO.getRepairableManager().isRepairable(heldItem)) {
|
||||||
|
RepairManager repairManager = mcMMOPlayer.getRepairManager();
|
||||||
|
|
||||||
// Cancel repairing an enchanted item
|
// Cancel repairing an enchanted item
|
||||||
if (repairManager.checkConfirmation(blockID, false) && Config.getInstance().getRepairConfirmRequired()) {
|
if (repairManager.checkConfirmation(blockID, false) && Config.getInstance().getRepairConfirmRequired()) {
|
||||||
mcMMOPlayer.setLastAnvilUse(Repair.repairAnvilId, 0);
|
mcMMOPlayer.setLastAnvilUse(Repair.repairAnvilId, 0);
|
||||||
player.sendMessage(LocaleLoader.getString("Skills.Cancelled", LocaleLoader.getString("Repair.Pretty.Name")));
|
player.sendMessage(LocaleLoader.getString("Skills.Cancelled", LocaleLoader.getString("Repair.Pretty.Name")));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
/* SALVAGE CHECKS */
|
||||||
/* SALVAGE CHECKS */
|
else if (blockID == Repair.salvageAnvilId && Permissions.salvage(player) && Repair.isSalvageable(heldItem)) {
|
||||||
else if (blockID == Repair.salvageAnvilId && Permissions.salvage(player) && Repair.isSalvageable(heldItem)) {
|
RepairManager repairManager = mcMMOPlayer.getRepairManager();
|
||||||
RepairManager repairManager = mcMMOPlayer.getRepairManager();
|
|
||||||
|
|
||||||
// Cancel salvaging an enchanted item
|
// Cancel salvaging an enchanted item
|
||||||
if (repairManager.checkConfirmation(blockID, false) && Config.getInstance().getRepairConfirmRequired()) {
|
if (repairManager.checkConfirmation(blockID, false) && Config.getInstance().getRepairConfirmRequired()) {
|
||||||
mcMMOPlayer.setLastAnvilUse(Repair.salvageAnvilId, 0);
|
mcMMOPlayer.setLastAnvilUse(Repair.salvageAnvilId, 0);
|
||||||
player.sendMessage(LocaleLoader.getString("Skills.Cancelled", LocaleLoader.getString("Salvage.Pretty.Name")));
|
player.sendMessage(LocaleLoader.getString("Skills.Cancelled", LocaleLoader.getString("Salvage.Pretty.Name")));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -540,6 +559,8 @@ public class PlayerListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ChatManager chatManager = null;
|
||||||
|
|
||||||
if (mcMMOPlayer.getPartyChatMode()) {
|
if (mcMMOPlayer.getPartyChatMode()) {
|
||||||
Party party = mcMMOPlayer.getParty();
|
Party party = mcMMOPlayer.getParty();
|
||||||
|
|
||||||
@@ -549,11 +570,15 @@ public class PlayerListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatManager.handlePartyChat(plugin, party, player.getName(), player.getDisplayName(), event.getMessage(), event.isAsynchronous());
|
chatManager = ChatManagerFactory.getChatManager(plugin, ChatMode.PARTY);
|
||||||
event.setCancelled(true);
|
((PartyChatManager) chatManager).setParty(party);
|
||||||
}
|
}
|
||||||
else if (mcMMOPlayer.getAdminChatMode()) {
|
else if (mcMMOPlayer.getAdminChatMode()) {
|
||||||
ChatManager.handleAdminChat(plugin, player.getName(), player.getDisplayName(), event.getMessage(), event.isAsynchronous());
|
chatManager = ChatManagerFactory.getChatManager(plugin, ChatMode.ADMIN);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (chatManager != null) {
|
||||||
|
chatManager.handleChat(player, event.getMessage(), event.isAsynchronous());
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import com.gmail.nossr50.config.mods.CustomToolConfig;
|
|||||||
import com.gmail.nossr50.config.spout.SpoutConfig;
|
import com.gmail.nossr50.config.spout.SpoutConfig;
|
||||||
import com.gmail.nossr50.config.treasure.TreasureConfig;
|
import com.gmail.nossr50.config.treasure.TreasureConfig;
|
||||||
import com.gmail.nossr50.database.DatabaseManager;
|
import com.gmail.nossr50.database.DatabaseManager;
|
||||||
|
import com.gmail.nossr50.database.DatabaseManagerFactory;
|
||||||
import com.gmail.nossr50.listeners.BlockListener;
|
import com.gmail.nossr50.listeners.BlockListener;
|
||||||
import com.gmail.nossr50.listeners.EntityListener;
|
import com.gmail.nossr50.listeners.EntityListener;
|
||||||
import com.gmail.nossr50.listeners.InventoryListener;
|
import com.gmail.nossr50.listeners.InventoryListener;
|
||||||
@@ -34,6 +35,7 @@ import com.gmail.nossr50.locale.LocaleLoader;
|
|||||||
import com.gmail.nossr50.metrics.MetricsManager;
|
import com.gmail.nossr50.metrics.MetricsManager;
|
||||||
import com.gmail.nossr50.party.PartyManager;
|
import com.gmail.nossr50.party.PartyManager;
|
||||||
import com.gmail.nossr50.runnables.SaveTimerTask;
|
import com.gmail.nossr50.runnables.SaveTimerTask;
|
||||||
|
import com.gmail.nossr50.runnables.UpdateCheckerTask;
|
||||||
import com.gmail.nossr50.runnables.database.UserPurgeTask;
|
import com.gmail.nossr50.runnables.database.UserPurgeTask;
|
||||||
import com.gmail.nossr50.runnables.party.PartyAutoKickTask;
|
import com.gmail.nossr50.runnables.party.PartyAutoKickTask;
|
||||||
import com.gmail.nossr50.runnables.skills.BleedTimerTask;
|
import com.gmail.nossr50.runnables.skills.BleedTimerTask;
|
||||||
@@ -44,8 +46,8 @@ import com.gmail.nossr50.skills.repair.RepairableManagerFactory;
|
|||||||
import com.gmail.nossr50.skills.repair.config.RepairConfigManager;
|
import com.gmail.nossr50.skills.repair.config.RepairConfigManager;
|
||||||
import com.gmail.nossr50.util.ChimaeraWing;
|
import com.gmail.nossr50.util.ChimaeraWing;
|
||||||
import com.gmail.nossr50.util.LogFilter;
|
import com.gmail.nossr50.util.LogFilter;
|
||||||
|
import com.gmail.nossr50.util.Misc;
|
||||||
import com.gmail.nossr50.util.Permissions;
|
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.ChunkManager;
|
||||||
import com.gmail.nossr50.util.blockmeta.chunkmeta.ChunkManagerFactory;
|
import com.gmail.nossr50.util.blockmeta.chunkmeta.ChunkManagerFactory;
|
||||||
import com.gmail.nossr50.util.commands.CommandRegistrationManager;
|
import com.gmail.nossr50.util.commands.CommandRegistrationManager;
|
||||||
@@ -109,7 +111,7 @@ public class mcMMO extends JavaPlugin {
|
|||||||
|
|
||||||
combatTagEnabled = getServer().getPluginManager().getPlugin("CombatTag") != null;
|
combatTagEnabled = getServer().getPluginManager().getPlugin("CombatTag") != null;
|
||||||
|
|
||||||
databaseManager = new DatabaseManager(this, Config.getInstance().getUseMySQL());
|
databaseManager = DatabaseManagerFactory.getDatabaseManager();
|
||||||
|
|
||||||
registerEvents();
|
registerEvents();
|
||||||
registerCustomRecipes();
|
registerCustomRecipes();
|
||||||
@@ -227,12 +229,17 @@ public class mcMMO extends JavaPlugin {
|
|||||||
return placeStore;
|
return placeStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static RepairableManager getRepairableManager() {
|
||||||
|
return repairableManager;
|
||||||
|
}
|
||||||
|
|
||||||
public static DatabaseManager getDatabaseManager() {
|
public static DatabaseManager getDatabaseManager() {
|
||||||
return databaseManager;
|
return databaseManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RepairableManager getRepairableManager() {
|
@Deprecated
|
||||||
return repairableManager;
|
public static void setDatabaseManager(DatabaseManager databaseManager) {
|
||||||
|
mcMMO.databaseManager = databaseManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isSpoutEnabled() {
|
public static boolean isSpoutEnabled() {
|
||||||
@@ -255,24 +262,23 @@ public class mcMMO extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void checkForUpdates() {
|
private void checkForUpdates() {
|
||||||
if (Config.getInstance().getUpdateCheckEnabled()) {
|
if (!Config.getInstance().getUpdateCheckEnabled()) {
|
||||||
try {
|
return;
|
||||||
updateAvailable = UpdateChecker.updateAvailable();
|
}
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
updateAvailable = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (updateAvailable) {
|
getServer().getScheduler().runTaskAsynchronously(this, new UpdateCheckerTask());
|
||||||
getLogger().info(LocaleLoader.getString("UpdateChecker.outdated"));
|
}
|
||||||
getLogger().info(LocaleLoader.getString("UpdateChecker.newavailable"));
|
|
||||||
}
|
public void updateCheckerCallback(boolean updateAvailable) {
|
||||||
|
this.updateAvailable = updateAvailable;
|
||||||
|
if (updateAvailable) {
|
||||||
|
getLogger().info(LocaleLoader.getString("UpdateChecker.outdated"));
|
||||||
|
getLogger().info(LocaleLoader.getString("UpdateChecker.newavailable"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadConfigFiles() {
|
private void loadConfigFiles() {
|
||||||
// Force the loading of config files
|
// Force the loading of config files
|
||||||
Config configInstance = Config.getInstance();
|
|
||||||
TreasureConfig.getInstance();
|
TreasureConfig.getInstance();
|
||||||
HiddenConfig.getInstance();
|
HiddenConfig.getInstance();
|
||||||
AdvancedConfig.getInstance();
|
AdvancedConfig.getInstance();
|
||||||
@@ -280,19 +286,19 @@ public class mcMMO extends JavaPlugin {
|
|||||||
|
|
||||||
List<Repairable> repairables = new ArrayList<Repairable>();
|
List<Repairable> repairables = new ArrayList<Repairable>();
|
||||||
|
|
||||||
if (configInstance.getToolModsEnabled()) {
|
if (Config.getInstance().getToolModsEnabled()) {
|
||||||
repairables.addAll(CustomToolConfig.getInstance().getLoadedRepairables());
|
repairables.addAll(CustomToolConfig.getInstance().getLoadedRepairables());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configInstance.getArmorModsEnabled()) {
|
if (Config.getInstance().getArmorModsEnabled()) {
|
||||||
repairables.addAll(CustomArmorConfig.getInstance().getLoadedRepairables());
|
repairables.addAll(CustomArmorConfig.getInstance().getLoadedRepairables());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configInstance.getBlockModsEnabled()) {
|
if (Config.getInstance().getBlockModsEnabled()) {
|
||||||
CustomBlockConfig.getInstance();
|
CustomBlockConfig.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configInstance.getEntityModsEnabled()) {
|
if (Config.getInstance().getEntityModsEnabled()) {
|
||||||
CustomEntityConfig.getInstance();
|
CustomEntityConfig.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -303,21 +309,22 @@ public class mcMMO extends JavaPlugin {
|
|||||||
repairableManager.registerRepairables(repairables);
|
repairableManager.registerRepairables(repairables);
|
||||||
|
|
||||||
// Check if Repair Anvil and Salvage Anvil have different itemID's
|
// Check if Repair Anvil and Salvage Anvil have different itemID's
|
||||||
if (configInstance.getSalvageAnvilId() == configInstance.getRepairAnvilId()) {
|
if (Config.getInstance().getSalvageAnvilId() == Config.getInstance().getRepairAnvilId()) {
|
||||||
getLogger().warning("Can't use the same itemID for Repair/Salvage Anvils!");
|
getLogger().warning("Can't use the same itemID for Repair/Salvage Anvils!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupSpout() {
|
private void setupSpout() {
|
||||||
// Check for Spout
|
if (!getServer().getPluginManager().isPluginEnabled("Spout")) {
|
||||||
if (getServer().getPluginManager().isPluginEnabled("Spout")) {
|
return;
|
||||||
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() {
|
private void registerEvents() {
|
||||||
@@ -344,23 +351,23 @@ public class mcMMO extends JavaPlugin {
|
|||||||
new SaveTimerTask().runTaskTimer(this, saveIntervalTicks, saveIntervalTicks);
|
new SaveTimerTask().runTaskTimer(this, saveIntervalTicks, saveIntervalTicks);
|
||||||
|
|
||||||
// Bleed timer (Runs every two seconds)
|
// Bleed timer (Runs every two seconds)
|
||||||
new BleedTimerTask().runTaskTimer(this, 40, 40);
|
new BleedTimerTask().runTaskTimer(this, 2 * Misc.TICK_CONVERSION_FACTOR, 2 * Misc.TICK_CONVERSION_FACTOR);
|
||||||
|
|
||||||
// Old & Powerless User remover
|
// Old & Powerless User remover
|
||||||
long purgeIntervalTicks = Config.getInstance().getPurgeInterval() * 60 * 60 * 20;
|
long purgeIntervalTicks = Config.getInstance().getPurgeInterval() * 60 * 60 * Misc.TICK_CONVERSION_FACTOR;
|
||||||
|
|
||||||
if (purgeIntervalTicks == 0) {
|
if (purgeIntervalTicks == 0) {
|
||||||
new UserPurgeTask().runTaskLater(this, 40); // Start 2 seconds after startup.
|
new UserPurgeTask().runTaskLater(this, 2 * Misc.TICK_CONVERSION_FACTOR); // Start 2 seconds after startup.
|
||||||
}
|
}
|
||||||
else if (purgeIntervalTicks > 0) {
|
else if (purgeIntervalTicks > 0) {
|
||||||
new UserPurgeTask().runTaskTimer(this, purgeIntervalTicks, purgeIntervalTicks);
|
new UserPurgeTask().runTaskTimer(this, purgeIntervalTicks, purgeIntervalTicks);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Automatically remove old members from parties
|
// Automatically remove old members from parties
|
||||||
long kickIntervalTicks = Config.getInstance().getAutoPartyKickInterval() * 60 * 60 * 20;
|
long kickIntervalTicks = Config.getInstance().getAutoPartyKickInterval() * 60 * 60 * Misc.TICK_CONVERSION_FACTOR;
|
||||||
|
|
||||||
if (kickIntervalTicks == 0) {
|
if (kickIntervalTicks == 0) {
|
||||||
new PartyAutoKickTask().runTaskLater(this, 40); // Start 2 seconds after startup.
|
new PartyAutoKickTask().runTaskLater(this, 2 * Misc.TICK_CONVERSION_FACTOR); // Start 2 seconds after startup.
|
||||||
}
|
}
|
||||||
else if (kickIntervalTicks > 0) {
|
else if (kickIntervalTicks > 0) {
|
||||||
new PartyAutoKickTask().runTaskTimer(this, kickIntervalTicks, kickIntervalTicks);
|
new PartyAutoKickTask().runTaskTimer(this, kickIntervalTicks, kickIntervalTicks);
|
||||||
|
|||||||
@@ -64,14 +64,11 @@ public final class PartyManager {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Party firstParty = firstMcMMOPlayer.getParty();
|
if (firstMcMMOPlayer.getParty() == null || secondMcMMOPlayer.getParty() == null) {
|
||||||
Party secondParty = secondMcMMOPlayer.getParty();
|
|
||||||
|
|
||||||
if (firstParty == null || secondParty == null || firstParty != secondParty) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return firstMcMMOPlayer.getParty().equals(secondMcMMOPlayer.getParty());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -83,13 +80,15 @@ public final class PartyManager {
|
|||||||
*/
|
*/
|
||||||
public static List<Player> getNearMembers(Player player, Party party, double range) {
|
public static List<Player> getNearMembers(Player player, Party party, double range) {
|
||||||
List<Player> nearMembers = new ArrayList<Player>();
|
List<Player> nearMembers = new ArrayList<Player>();
|
||||||
|
|
||||||
if (party != null) {
|
if (party != null) {
|
||||||
for (Player member : party.getOnlineMembers()) {
|
for (Player member : party.getOnlineMembers()) {
|
||||||
if (!player.getName().equalsIgnoreCase(member.getName()) && !member.isDead() && Misc.isNear(player.getLocation(), member.getLocation(), range)) {
|
if (!player.equals(member) && member.isValid() && Misc.isNear(player.getLocation(), member.getLocation(), range)) {
|
||||||
nearMembers.add(member);
|
nearMembers.add(member);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nearMembers;
|
return nearMembers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,13 +99,9 @@ public final class PartyManager {
|
|||||||
* @return all the players in the player's party
|
* @return all the players in the player's party
|
||||||
*/
|
*/
|
||||||
public static LinkedHashSet<String> getAllMembers(Player player) {
|
public static LinkedHashSet<String> getAllMembers(Player player) {
|
||||||
Party party = UserManager.getPlayer(player).getParty();
|
Party party = getPlayerParty(player.getName());
|
||||||
|
|
||||||
if (party == null) {
|
return party == null ? null : party.getMembers();
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return party.getMembers();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -116,13 +111,7 @@ public final class PartyManager {
|
|||||||
* @return all online players in this party
|
* @return all online players in this party
|
||||||
*/
|
*/
|
||||||
public static List<Player> getOnlineMembers(String partyName) {
|
public static List<Player> getOnlineMembers(String partyName) {
|
||||||
Party party = getParty(partyName);
|
return getOnlineMembers(getParty(partyName));
|
||||||
|
|
||||||
if (party == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return party.getOnlineMembers();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -132,13 +121,11 @@ public final class PartyManager {
|
|||||||
* @return all online players in this party
|
* @return all online players in this party
|
||||||
*/
|
*/
|
||||||
public static List<Player> getOnlineMembers(Player player) {
|
public static List<Player> getOnlineMembers(Player player) {
|
||||||
Party party = getPlayerParty(player.getName());
|
return getOnlineMembers(getPlayerParty(player.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
if (party == null) {
|
private static List<Player> getOnlineMembers(Party party) {
|
||||||
return null;
|
return party == null ? null : party.getOnlineMembers();
|
||||||
}
|
|
||||||
|
|
||||||
return getOnlineMembers(party.getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -192,29 +179,24 @@ public final class PartyManager {
|
|||||||
*/
|
*/
|
||||||
public static void removeFromParty(OfflinePlayer player, Party party) {
|
public static void removeFromParty(OfflinePlayer player, Party party) {
|
||||||
LinkedHashSet<String> members = party.getMembers();
|
LinkedHashSet<String> members = party.getMembers();
|
||||||
|
String playerName = player.getName();
|
||||||
|
|
||||||
members.remove(player.getName());
|
members.remove(playerName);
|
||||||
|
|
||||||
if (members.isEmpty()) {
|
if (members.isEmpty()) {
|
||||||
parties.remove(party);
|
parties.remove(party);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// If the leaving player was the party leader, appoint a new leader from the party members
|
// If the leaving player was the party leader, appoint a new leader from the party members
|
||||||
if (party.getLeader().equalsIgnoreCase(player.getName())) {
|
if (party.getLeader().equalsIgnoreCase(playerName)) {
|
||||||
String newLeader = members.iterator().next();
|
String newLeader = members.iterator().next();
|
||||||
party.setLeader(newLeader);
|
party.setLeader(newLeader);
|
||||||
}
|
}
|
||||||
|
|
||||||
informPartyMembersQuit(player, party);
|
informPartyMembersQuit(party, playerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player.getName());
|
processPartyLeaving(UserManager.getPlayer(player));
|
||||||
|
|
||||||
if (mcMMOPlayer != null) {
|
|
||||||
mcMMOPlayer.removeParty();
|
|
||||||
mcMMOPlayer.setPartyChat(false);
|
|
||||||
mcMMOPlayer.setItemShareModifier(10);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -223,19 +205,10 @@ public final class PartyManager {
|
|||||||
* @param party The party to remove
|
* @param party The party to remove
|
||||||
*/
|
*/
|
||||||
public static void disbandParty(Party party) {
|
public static void disbandParty(Party party) {
|
||||||
LinkedHashSet<String> members = party.getMembers();
|
for (String memberName : party.getMembers()) {
|
||||||
|
processPartyLeaving(UserManager.getPlayer(memberName));
|
||||||
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);
|
parties.remove(party);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,29 +222,25 @@ public final class PartyManager {
|
|||||||
*/
|
*/
|
||||||
public static void createParty(Player player, McMMOPlayer mcMMOPlayer, String partyName, String password) {
|
public static void createParty(Player player, McMMOPlayer mcMMOPlayer, String partyName, String password) {
|
||||||
partyName = partyName.replace(".", "");
|
partyName = partyName.replace(".", "");
|
||||||
|
|
||||||
Party party = getParty(partyName);
|
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"));
|
player.sendMessage(LocaleLoader.getString("Commands.Party.AlreadyExists"));
|
||||||
return;
|
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()));
|
player.sendMessage(LocaleLoader.getString("Commands.Party.Create", party.getName()));
|
||||||
addToParty(player, mcMMOPlayer, party);
|
addToParty(playerName, mcMMOPlayer, party);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -283,16 +252,12 @@ public final class PartyManager {
|
|||||||
* @param password the password for this party, null if there was no password
|
* @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) {
|
public static void joinParty(Player player, McMMOPlayer mcMMOPlayer, Party party, String password) {
|
||||||
if (!checkPartyPassword(player, party, password)) {
|
if (!checkPartyPassword(player, party, password) || mcMMOPlayer.getParty() == party) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mcMMOPlayer.getParty() == party) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
player.sendMessage(LocaleLoader.getString("Commands.Party.Join", party.getName()));
|
player.sendMessage(LocaleLoader.getString("Commands.Party.Join", party.getName()));
|
||||||
addToParty(player, mcMMOPlayer, party);
|
addToParty(player.getName(), mcMMOPlayer, party);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -304,27 +269,28 @@ public final class PartyManager {
|
|||||||
* @return true if the player can join the party
|
* @return true if the player can join the party
|
||||||
*/
|
*/
|
||||||
public static boolean checkPartyPassword(Player player, Party party, String password) {
|
public static boolean checkPartyPassword(Player player, Party party, String password) {
|
||||||
// Don't care about passwords if it isn't locked
|
if (!party.isLocked()) {
|
||||||
if (party.isLocked()) {
|
return true;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -346,7 +312,7 @@ public final class PartyManager {
|
|||||||
|
|
||||||
player.sendMessage(LocaleLoader.getString("Commands.Invite.Accepted", invite.getName()));
|
player.sendMessage(LocaleLoader.getString("Commands.Invite.Accepted", invite.getName()));
|
||||||
mcMMOPlayer.removePartyInvite();
|
mcMMOPlayer.removePartyInvite();
|
||||||
addToParty(player, mcMMOPlayer, invite);
|
addToParty(player.getName(), mcMMOPlayer, invite);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -356,15 +322,15 @@ public final class PartyManager {
|
|||||||
* @param mcMMOPlayer The player to add to the party
|
* @param mcMMOPlayer The player to add to the party
|
||||||
* @param party The party
|
* @param party The party
|
||||||
*/
|
*/
|
||||||
public static void addToParty(OfflinePlayer player, McMMOPlayer mcMMOPlayer, Party party) {
|
public static void addToParty(String playerName, McMMOPlayer mcMMOPlayer, Party party) {
|
||||||
if (mcMMOPlayer.getParty() == party) {
|
if (mcMMOPlayer.getParty() == party) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
informPartyMembersJoin(player, party);
|
informPartyMembersJoin(party, playerName);
|
||||||
mcMMOPlayer.setParty(party);
|
mcMMOPlayer.setParty(party);
|
||||||
|
|
||||||
party.getMembers().add(player.getName());
|
party.getMembers().add(playerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -415,11 +381,7 @@ public final class PartyManager {
|
|||||||
* @return true if the player can invite
|
* @return true if the player can invite
|
||||||
*/
|
*/
|
||||||
public static boolean canInvite(Player player, Party party) {
|
public static boolean canInvite(Player player, Party party) {
|
||||||
if (party.isLocked() && !party.getLeader().equalsIgnoreCase(player.getName())) {
|
return !(party.isLocked() && !party.getLeader().equalsIgnoreCase(player.getName()));
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -429,13 +391,7 @@ public final class PartyManager {
|
|||||||
* @return true if this is a valid party, false otherwise
|
* @return true if this is a valid party, false otherwise
|
||||||
*/
|
*/
|
||||||
public static boolean isParty(String partyName) {
|
public static boolean isParty(String partyName) {
|
||||||
for (Party party : parties) {
|
return getParty(partyName) != null;
|
||||||
if (party.getName().equals(partyName)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -449,9 +405,8 @@ public final class PartyManager {
|
|||||||
YamlConfiguration partiesFile = YamlConfiguration.loadConfiguration(partyFile);
|
YamlConfiguration partiesFile = YamlConfiguration.loadConfiguration(partyFile);
|
||||||
|
|
||||||
for (String partyName : partiesFile.getConfigurationSection("").getKeys(false)) {
|
for (String partyName : partiesFile.getConfigurationSection("").getKeys(false)) {
|
||||||
Party party = new Party();
|
Party party = new Party(partyName);
|
||||||
|
|
||||||
party.setName(partyName);
|
|
||||||
party.setLeader(partiesFile.getString(partyName + ".Leader"));
|
party.setLeader(partiesFile.getString(partyName + ".Leader"));
|
||||||
party.setPassword(partiesFile.getString(partyName + ".Password"));
|
party.setPassword(partiesFile.getString(partyName + ".Password"));
|
||||||
party.setLocked(partiesFile.getBoolean(partyName + ".Locked"));
|
party.setLocked(partiesFile.getBoolean(partyName + ".Locked"));
|
||||||
@@ -524,30 +479,36 @@ 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 party The concerned party
|
||||||
|
* @param playerName The name of the player that joined
|
||||||
*/
|
*/
|
||||||
private static void informPartyMembersJoin(OfflinePlayer player, Party party) {
|
private static void informPartyMembersJoin(Party party, String playerName) {
|
||||||
for (Player member : party.getOnlineMembers()) {
|
for (Player member : party.getOnlineMembers()) {
|
||||||
if (!member.equals(player)) {
|
member.sendMessage(LocaleLoader.getString("Party.InformedOnJoin", playerName));
|
||||||
member.sendMessage(LocaleLoader.getString("Party.InformedOnJoin", player.getName()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify party members when a party member quits.
|
* Notify party members when a party member quits.
|
||||||
*
|
*
|
||||||
* @param player The player that quits
|
|
||||||
* @param party The concerned party
|
* @param party The concerned party
|
||||||
|
* @param playerName The name of the player that left
|
||||||
*/
|
*/
|
||||||
private static void informPartyMembersQuit(OfflinePlayer player, Party party) {
|
private static void informPartyMembersQuit(Party party, String playerName) {
|
||||||
for (Player member : party.getOnlineMembers()) {
|
for (Player member : party.getOnlineMembers()) {
|
||||||
if (!member.equals(player)) {
|
member.sendMessage(LocaleLoader.getString("Party.InformedOnQuit", playerName));
|
||||||
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,12 +65,7 @@ public final class ShareHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
double partySize = nearMembers.size() + 1;
|
double partySize = nearMembers.size() + 1;
|
||||||
double shareBonus = Config.getInstance().getPartyShareBonusBase() + partySize * Config.getInstance().getPartyShareBonusIncrease();
|
double shareBonus = Math.min(Config.getInstance().getPartyShareBonusBase() + partySize * Config.getInstance().getPartyShareBonusIncrease(), Config.getInstance().getPartyShareBonusCap());
|
||||||
|
|
||||||
if (shareBonus > Config.getInstance().getPartyShareBonusCap()) {
|
|
||||||
shareBonus = Config.getInstance().getPartyShareBonusCap();
|
|
||||||
}
|
|
||||||
|
|
||||||
float splitXp = (float) (xp / partySize * shareBonus);
|
float splitXp = (float) (xp / partySize * shareBonus);
|
||||||
|
|
||||||
for (Player member : nearMembers) {
|
for (Player member : nearMembers) {
|
||||||
@@ -78,7 +73,6 @@ public final class ShareHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mcMMOPlayer.beginUnsharedXpGain(skillType, splitXp);
|
mcMMOPlayer.beginUnsharedXpGain(skillType, splitXp);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case NONE:
|
case NONE:
|
||||||
@@ -96,32 +90,43 @@ public final class ShareHandler {
|
|||||||
*/
|
*/
|
||||||
public static boolean handleItemShare(Item drop, McMMOPlayer mcMMOPlayer) {
|
public static boolean handleItemShare(Item drop, McMMOPlayer mcMMOPlayer) {
|
||||||
ItemStack itemStack = drop.getItemStack();
|
ItemStack itemStack = drop.getItemStack();
|
||||||
Party party = mcMMOPlayer.getParty();
|
|
||||||
Player player = mcMMOPlayer.getPlayer();
|
|
||||||
Player winningPlayer = null;
|
|
||||||
|
|
||||||
ItemStack newStack = itemStack.clone();
|
|
||||||
newStack.setAmount(1);
|
|
||||||
|
|
||||||
ItemShareType dropType = ItemShareType.getShareType(itemStack);
|
ItemShareType dropType = ItemShareType.getShareType(itemStack);
|
||||||
|
|
||||||
if (dropType == null || !party.sharingDrops(dropType)) {
|
if (dropType == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (party.getItemShareMode()) {
|
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) {
|
||||||
case EQUAL:
|
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());
|
int itemWeight = ItemWeightConfig.getInstance().getItemWeight(itemStack.getType());
|
||||||
|
|
||||||
for (int i = 0; i < itemStack.getAmount(); i++) {
|
for (int i = 0; i < itemStack.getAmount(); i++) {
|
||||||
@@ -132,64 +137,46 @@ public final class ShareHandler {
|
|||||||
int itemShareModifier = mcMMOMember.getItemShareModifier();
|
int itemShareModifier = mcMMOMember.getItemShareModifier();
|
||||||
int diceRoll = Misc.getRandom().nextInt(itemShareModifier);
|
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);
|
mcMMOMember.setItemShareModifier(itemShareModifier + itemWeight);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
highestRoll = diceRoll;
|
||||||
|
|
||||||
|
if (winningPlayer != null) {
|
||||||
|
McMMOPlayer mcMMOWinning = UserManager.getPlayer(winningPlayer);
|
||||||
|
mcMMOWinning.setItemShareModifier(mcMMOWinning.getItemShareModifier() + itemWeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
winningPlayer = member;
|
||||||
}
|
}
|
||||||
|
|
||||||
mcMMOTarget = UserManager.getPlayer(winningPlayer);
|
McMMOPlayer mcMMOTarget = UserManager.getPlayer(winningPlayer);
|
||||||
mcMMOTarget.setItemShareModifier(mcMMOTarget.getItemShareModifier() - itemWeight);
|
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;
|
return true;
|
||||||
|
|
||||||
case RANDOM:
|
case RANDOM:
|
||||||
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++) {
|
for (int i = 0; i < itemStack.getAmount(); i++) {
|
||||||
int randomMember = Misc.getRandom().nextInt(partySize);
|
winningPlayer = nearMembers.get(Misc.getRandom().nextInt(partySize));
|
||||||
|
awardDrop(winningPlayer, newStack);
|
||||||
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;
|
return true;
|
||||||
|
|
||||||
case NONE:
|
|
||||||
default:
|
default:
|
||||||
return false;
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
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,9 +6,6 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
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 {
|
public class McrankCommandAsyncTask extends BukkitRunnable {
|
||||||
private final String playerName;
|
private final String playerName;
|
||||||
@@ -21,8 +18,9 @@ public class McrankCommandAsyncTask extends BukkitRunnable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Map<String, Integer> skills = Config.getInstance().getUseMySQL() ? SQLDatabaseManager.readSQLRank(playerName) : FlatfileDatabaseManager.getPlayerRanks(playerName);
|
Map<String, Integer> skills = mcMMO.getDatabaseManager().readRank(playerName);
|
||||||
|
|
||||||
new McrankCommandDisplayTask(skills, sender, playerName).runTaskLater(mcMMO.p, 1);
|
new McrankCommandDisplayTask(skills, sender, playerName).runTaskLater(mcMMO.p, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,31 +1,28 @@
|
|||||||
package com.gmail.nossr50.runnables.commands;
|
package com.gmail.nossr50.runnables.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.List;
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.config.Config;
|
import com.gmail.nossr50.datatypes.database.PlayerStat;
|
||||||
import com.gmail.nossr50.database.SQLDatabaseManager;
|
|
||||||
|
|
||||||
public class MctopCommandAsyncTask extends BukkitRunnable {
|
public class MctopCommandAsyncTask extends BukkitRunnable {
|
||||||
private CommandSender sender;
|
private CommandSender sender;
|
||||||
private String query;
|
private String skill;
|
||||||
private int page;
|
private int page;
|
||||||
|
|
||||||
public MctopCommandAsyncTask(int page, String query, CommandSender sender) {
|
public MctopCommandAsyncTask(int page, String skill, CommandSender sender) {
|
||||||
this.page = page;
|
this.page = page;
|
||||||
this.query = query.equalsIgnoreCase("ALL") ? "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing" : query;
|
this.skill = skill;
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
String tablePrefix = Config.getInstance().getMySQLTablePrefix();
|
final List<PlayerStat> userStats = mcMMO.getDatabaseManager().readLeaderboard(skill, page, 10);
|
||||||
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, tablePrefix, sender).runTaskLater(mcMMO.p, 1);
|
new MctopCommandDisplayTask(userStats, page, skill, sender).runTaskLater(mcMMO.p, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,44 +1,44 @@
|
|||||||
package com.gmail.nossr50.runnables.commands;
|
package com.gmail.nossr50.runnables.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.List;
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import com.gmail.nossr50.datatypes.database.PlayerStat;
|
||||||
import com.gmail.nossr50.locale.LocaleLoader;
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
import com.gmail.nossr50.util.StringUtils;
|
import com.gmail.nossr50.util.StringUtils;
|
||||||
|
|
||||||
public class MctopCommandDisplayTask extends BukkitRunnable {
|
public class MctopCommandDisplayTask extends BukkitRunnable {
|
||||||
private Collection<ArrayList<String>> userStats;
|
private List<PlayerStat> userStats;
|
||||||
private CommandSender sender;
|
private CommandSender sender;
|
||||||
private String query;
|
private String skill;
|
||||||
private int page;
|
private int page;
|
||||||
|
|
||||||
public MctopCommandDisplayTask(Collection<ArrayList<String>> userStats, int page, String query, CommandSender sender) {
|
public MctopCommandDisplayTask(List<PlayerStat> userStats, int page, String skill, CommandSender sender) {
|
||||||
this.userStats = userStats;
|
this.userStats = userStats;
|
||||||
this.page = page;
|
this.page = page;
|
||||||
this.query = query;
|
this.skill = skill;
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (query.equalsIgnoreCase("taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing")) {
|
if (skill.equalsIgnoreCase("all")) {
|
||||||
sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Leaderboard"));
|
sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Leaderboard"));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Leaderboard", StringUtils.getCapitalized(query)));
|
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Leaderboard", StringUtils.getCapitalized(skill)));
|
||||||
}
|
}
|
||||||
|
|
||||||
int place = (page * 10) - 9;
|
int place = (page * 10) - 9;
|
||||||
|
|
||||||
for (ArrayList<String> stat : userStats) {
|
for (PlayerStat stat : userStats) {
|
||||||
String digit = (place < 10) ? "0" : "" + String.valueOf(place);
|
String digit = ((place < 10) ? "0" : "") + String.valueOf(place);
|
||||||
|
|
||||||
// Format: 1. Playername - skill value
|
// Format: 1. Playername - skill value
|
||||||
sender.sendMessage(digit + ". " + ChatColor.GREEN + stat.get(1) + " - " + ChatColor.WHITE + stat.get(0));
|
sender.sendMessage(digit + ". " + ChatColor.GREEN + stat.name + " - " + ChatColor.WHITE + stat.statVal);
|
||||||
place++;
|
place++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,279 +0,0 @@
|
|||||||
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 {
|
public class SQLReconnectTask extends BukkitRunnable {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (SQLDatabaseManager.checkConnected()) {
|
if (((SQLDatabaseManager) mcMMO.getDatabaseManager()).checkConnected()) {
|
||||||
UserManager.saveAll(); // Save all profiles
|
UserManager.saveAll(); // Save all profiles
|
||||||
UserManager.clearAll(); // Clear the profiles
|
UserManager.clearAll(); // Clear the profiles
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package com.gmail.nossr50.runnables.party;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
@@ -15,29 +14,25 @@ import com.gmail.nossr50.datatypes.party.Party;
|
|||||||
import com.gmail.nossr50.party.PartyManager;
|
import com.gmail.nossr50.party.PartyManager;
|
||||||
|
|
||||||
public class PartyAutoKickTask extends BukkitRunnable {
|
public class PartyAutoKickTask extends BukkitRunnable {
|
||||||
|
private final static long KICK_TIME = 24L * 60L * 60L * 1000L * Config.getInstance().getAutoPartyKickTime();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
updatePartyMembers();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updatePartyMembers() {
|
|
||||||
HashMap<OfflinePlayer, Party> toRemove = new HashMap<OfflinePlayer, Party>();
|
HashMap<OfflinePlayer, Party> toRemove = new HashMap<OfflinePlayer, Party>();
|
||||||
List<String> processedPlayers = new ArrayList<String>();
|
List<String> processedPlayers = new ArrayList<String>();
|
||||||
|
|
||||||
long currentTime = System.currentTimeMillis();
|
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()) {
|
for (String memberName : party.getMembers()) {
|
||||||
OfflinePlayer member = mcMMO.p.getServer().getOfflinePlayer(memberName);
|
OfflinePlayer member = mcMMO.p.getServer().getOfflinePlayer(memberName);
|
||||||
|
boolean isProcessed = processedPlayers.contains(memberName);
|
||||||
|
|
||||||
if ((currentTime - member.getLastPlayed() > kickTime) || processedPlayers.contains(memberName)) {
|
if ((!member.isOnline() && (currentTime - member.getLastPlayed() > KICK_TIME)) || isProcessed) {
|
||||||
toRemove.put(member, party);
|
toRemove.put(member, party);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!processedPlayers.contains(memberName)) {
|
if (!isProcessed) {
|
||||||
processedPlayers.add(memberName);
|
processedPlayers.add(memberName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -60,6 +60,6 @@ public class AbilityDisableTask extends BukkitRunnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SkillUtils.sendSkillMessage(player, ability.getAbilityPlayerOff(player));
|
SkillUtils.sendSkillMessage(player, ability.getAbilityPlayerOff(player));
|
||||||
new AbilityCooldownTask(mcMMOPlayer, ability).runTaskLaterAsynchronously(mcMMO.p, PerksUtils.handleCooldownPerks(player, ability.getCooldown()) * 20);
|
new AbilityCooldownTask(mcMMOPlayer, ability).runTaskLaterAsynchronously(mcMMO.p, PerksUtils.handleCooldownPerks(player, ability.getCooldown()) * Misc.TICK_CONVERSION_FACTOR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ public class FishingManager extends SkillManager {
|
|||||||
|
|
||||||
private int fishingTries = 0;
|
private int fishingTries = 0;
|
||||||
private long fishingTimestamp = 0L;
|
private long fishingTimestamp = 0L;
|
||||||
|
private Location fishingTarget;
|
||||||
|
|
||||||
public FishingManager(McMMOPlayer mcMMOPlayer) {
|
public FishingManager(McMMOPlayer mcMMOPlayer) {
|
||||||
super(mcMMOPlayer, SkillType.FISHING);
|
super(mcMMOPlayer, SkillType.FISHING);
|
||||||
@@ -113,13 +114,15 @@ public class FishingManager extends SkillManager {
|
|||||||
mcMMO.p.getServer().broadcastMessage(ChatColor.RED + AdvancedConfig.getInstance().getServerUnleashMessage().replace("(PLAYER)", player.getDisplayName()));
|
mcMMO.p.getServer().broadcastMessage(ChatColor.RED + AdvancedConfig.getInstance().getServerUnleashMessage().replace("(PLAYER)", player.getDisplayName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
player.setItemInHand(null);
|
if (player.getItemInHand().getType() == Material.FISHING_ROD) {
|
||||||
|
player.setItemInHand(null);
|
||||||
|
}
|
||||||
|
|
||||||
Creature kraken = (Creature) world.spawnEntity(player.getEyeLocation(), (Misc.getRandom().nextInt(100) == 0 ? EntityType.CHICKEN : EntityType.SQUID));
|
Creature kraken = (Creature) world.spawnEntity(player.getEyeLocation(), (Misc.getRandom().nextInt(100) == 0 ? EntityType.CHICKEN : EntityType.SQUID));
|
||||||
kraken.setCustomName(AdvancedConfig.getInstance().getKrakenName());
|
kraken.setCustomName(AdvancedConfig.getInstance().getKrakenName());
|
||||||
|
|
||||||
if (!kraken.isValid()) {
|
if (!kraken.isValid()) {
|
||||||
int attackInterval = AdvancedConfig.getInstance().getKrakenAttackInterval() * 20;
|
int attackInterval = AdvancedConfig.getInstance().getKrakenAttackInterval() * Misc.TICK_CONVERSION_FACTOR;
|
||||||
new KrakenAttackTask(kraken, player, player.getLocation()).runTaskTimer(mcMMO.p, attackInterval, attackInterval);
|
new KrakenAttackTask(kraken, player, player.getLocation()).runTaskTimer(mcMMO.p, attackInterval, attackInterval);
|
||||||
|
|
||||||
if (!forceSpawn) {
|
if (!forceSpawn) {
|
||||||
@@ -132,7 +135,7 @@ public class FishingManager extends SkillManager {
|
|||||||
kraken.setMaxHealth(AdvancedConfig.getInstance().getKrakenHealth());
|
kraken.setMaxHealth(AdvancedConfig.getInstance().getKrakenHealth());
|
||||||
kraken.setHealth(kraken.getMaxHealth());
|
kraken.setHealth(kraken.getMaxHealth());
|
||||||
|
|
||||||
int attackInterval = AdvancedConfig.getInstance().getKrakenAttackInterval() * 20;
|
int attackInterval = AdvancedConfig.getInstance().getKrakenAttackInterval() * Misc.TICK_CONVERSION_FACTOR;
|
||||||
new KrakenAttackTask(kraken, player).runTaskTimer(mcMMO.p, attackInterval, attackInterval);
|
new KrakenAttackTask(kraken, player).runTaskTimer(mcMMO.p, attackInterval, attackInterval);
|
||||||
|
|
||||||
if (!forceSpawn) {
|
if (!forceSpawn) {
|
||||||
@@ -143,7 +146,13 @@ public class FishingManager extends SkillManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean exploitPrevention() {
|
public boolean exploitPrevention() {
|
||||||
if (!AdvancedConfig.getInstance().getKrakenEnabled() || !getPlayer().getTargetBlock(null, 100).isLiquid()) {
|
if (!AdvancedConfig.getInstance().getKrakenEnabled()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Block targetBlock = getPlayer().getTargetBlock(null, 100);
|
||||||
|
|
||||||
|
if (!targetBlock.isLiquid()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,6 +161,13 @@ public class FishingManager extends SkillManager {
|
|||||||
|
|
||||||
fishingTries = hasFished ? fishingTries + 1 : Math.max(fishingTries - 1, 0);
|
fishingTries = hasFished ? fishingTries + 1 : Math.max(fishingTries - 1, 0);
|
||||||
fishingTimestamp = currentTime;
|
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);
|
return unleashTheKraken(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,9 +182,9 @@ public class FishingManager extends SkillManager {
|
|||||||
|
|
||||||
// Make sure this is a body of water, not just a block of ice.
|
// Make sure this is a body of water, not just a block of ice.
|
||||||
Biome biome = block.getBiome();
|
Biome biome = block.getBiome();
|
||||||
boolean isFrozenBiome = (biome == Biome.FROZEN_OCEAN || biome == Biome.FROZEN_RIVER);
|
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);
|
||||||
|
|
||||||
if (!isFrozenBiome && block.getRelative(BlockFace.DOWN, 3).getType() == (Material.STATIONARY_WATER)) {
|
if (!isFrozenBiome && (block.getRelative(BlockFace.DOWN, 3).getType() != Material.STATIONARY_WATER)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ public class MiningManager extends SkillManager {
|
|||||||
|
|
||||||
getProfile().setSkillDATS(AbilityType.BLAST_MINING, System.currentTimeMillis());
|
getProfile().setSkillDATS(AbilityType.BLAST_MINING, System.currentTimeMillis());
|
||||||
mcMMOPlayer.setAbilityInformed(AbilityType.BLAST_MINING, false);
|
mcMMOPlayer.setAbilityInformed(AbilityType.BLAST_MINING, false);
|
||||||
new AbilityCooldownTask(mcMMOPlayer, AbilityType.BLAST_MINING).runTaskLaterAsynchronously(mcMMO.p, AbilityType.BLAST_MINING.getCooldown() * 20);
|
new AbilityCooldownTask(mcMMOPlayer, AbilityType.BLAST_MINING).runTaskLaterAsynchronously(mcMMO.p, AbilityType.BLAST_MINING.getCooldown() * Misc.TICK_CONVERSION_FACTOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -284,10 +284,7 @@ public class MiningManager extends SkillManager {
|
|||||||
private boolean blastMiningCooldownOver() {
|
private boolean blastMiningCooldownOver() {
|
||||||
Player player = getPlayer();
|
Player player = getPlayer();
|
||||||
PlayerProfile profile = getProfile();
|
PlayerProfile profile = getProfile();
|
||||||
|
int timeRemaining = SkillUtils.calculateTimeLeft(profile.getSkillDATS(AbilityType.BLAST_MINING) * Misc.TIME_CONVERSION_FACTOR, AbilityType.BLAST_MINING.getCooldown(), player);
|
||||||
long oldTime = profile.getSkillDATS(AbilityType.BLAST_MINING) * Misc.TIME_CONVERSION_FACTOR;
|
|
||||||
int cooldown = AbilityType.BLAST_MINING.getCooldown();
|
|
||||||
int timeRemaining = SkillUtils.calculateTimeLeft(oldTime, cooldown, player);
|
|
||||||
|
|
||||||
if (timeRemaining > 0) {
|
if (timeRemaining > 0) {
|
||||||
player.sendMessage(LocaleLoader.getString("Skills.TooTired", timeRemaining));
|
player.sendMessage(LocaleLoader.getString("Skills.TooTired", timeRemaining));
|
||||||
|
|||||||
@@ -29,11 +29,11 @@ public class Repair {
|
|||||||
* @return true if the item is salvageable, false otherwise
|
* @return true if the item is salvageable, false otherwise
|
||||||
*/
|
*/
|
||||||
public static boolean isSalvageable(ItemStack item) {
|
public static boolean isSalvageable(ItemStack item) {
|
||||||
if (Config.getInstance().getSalvageTools() && (ItemUtils.isMinecraftTool(item) || ItemUtils.isStringTool(item) || item.getType() == Material.BUCKET)) {
|
if (Config.getInstance().getSalvageTools() && ItemUtils.isMinecraftTool(item)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Config.getInstance().getSalvageArmor() && ItemUtils.isMinecraftArmor(item)) {
|
if (Config.getInstance().getSalvageArmor() && !ItemUtils.isChainmailArmor(item) && ItemUtils.isMinecraftArmor(item)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -88,21 +88,14 @@ public class RepairConfig extends ConfigLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected List<Repairable> getLoadedRepairables() {
|
protected List<Repairable> getLoadedRepairables() {
|
||||||
if (repairables == null) {
|
return repairables == null ? new ArrayList<Repairable>() : repairables;
|
||||||
return new ArrayList<Repairable>();
|
|
||||||
}
|
|
||||||
|
|
||||||
return repairables;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean noErrorsInRepairable(List<String> issues) {
|
private boolean noErrorsInRepairable(List<String> issues) {
|
||||||
if (issues.isEmpty()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (String issue : issues) {
|
for (String issue : issues) {
|
||||||
plugin.getLogger().warning(issue);
|
plugin.getLogger().warning(issue);
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
return issues.isEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,10 +28,6 @@ public class SmeltingManager extends SkillManager {
|
|||||||
return getSkillLevel() >= Smelting.fluxMiningUnlockLevel && BlockUtils.affectedByFluxMining(blockState) && Permissions.fluxMining(getPlayer()) && !mcMMO.getPlaceStore().isTrue(blockState);
|
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.
|
* Process the Flux Mining ability.
|
||||||
*
|
*
|
||||||
@@ -122,6 +118,6 @@ public class SmeltingManager extends SkillManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -230,14 +230,10 @@ public final class Woodcutting {
|
|||||||
|
|
||||||
short finalDurability = (short) (inHand.getDurability() + durabilityLoss);
|
short finalDurability = (short) (inHand.getDurability() + durabilityLoss);
|
||||||
short maxDurability = ModUtils.isCustomTool(inHand) ? ModUtils.getToolFromItemStack(inHand).getDurability() : inHandMaterial.getMaxDurability();
|
short maxDurability = ModUtils.isCustomTool(inHand) ? ModUtils.getToolFromItemStack(inHand).getDurability() : inHandMaterial.getMaxDurability();
|
||||||
|
boolean overMax = (finalDurability >= maxDurability);
|
||||||
|
|
||||||
if (finalDurability >= maxDurability) {
|
inHand.setDurability(overMax ? maxDurability : finalDurability);
|
||||||
inHand.setDurability(maxDurability);
|
return !overMax;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
inHand.setDurability(finalDurability);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -461,6 +461,10 @@ public class ItemUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isSmeltable(ItemStack item) {
|
public static boolean isSmeltable(ItemStack item) {
|
||||||
|
if (item == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
switch (item.getType()) {
|
switch (item.getType()) {
|
||||||
case COAL_ORE:
|
case COAL_ORE:
|
||||||
case DIAMOND_ORE:
|
case DIAMOND_ORE:
|
||||||
@@ -479,6 +483,10 @@ public class ItemUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isSmelted(ItemStack item) {
|
public static boolean isSmelted(ItemStack item) {
|
||||||
|
if (item == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
switch (item.getType()) {
|
switch (item.getType()) {
|
||||||
case COAL:
|
case COAL:
|
||||||
case DIAMOND:
|
case DIAMOND:
|
||||||
|
|||||||
@@ -1,15 +1,23 @@
|
|||||||
package com.gmail.nossr50.util;
|
package com.gmail.nossr50.util;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
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.Entity;
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
import org.bukkit.entity.Player;
|
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.inventory.ItemStack;
|
||||||
|
import org.bukkit.metadata.MetadataValue;
|
||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||||
@@ -20,8 +28,11 @@ import com.gmail.nossr50.util.spout.SpoutUtils;
|
|||||||
|
|
||||||
public final class Misc {
|
public final class Misc {
|
||||||
private static Random random = new Random();
|
private static Random random = new Random();
|
||||||
public static final int PLAYER_RESPAWN_COOLDOWN_SECONDS = 5;
|
|
||||||
public static final int TIME_CONVERSION_FACTOR = 1000;
|
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 double SKILL_MESSAGE_MAX_SENDING_DISTANCE = 10.0;
|
public static final double SKILL_MESSAGE_MAX_SENDING_DISTANCE = 10.0;
|
||||||
|
|
||||||
// Sound Pitches & Volumes from CB
|
// Sound Pitches & Volumes from CB
|
||||||
@@ -204,6 +215,52 @@ 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() {
|
public static Random getRandom() {
|
||||||
return random;
|
return random;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,10 @@ public final class MobHealthbarUtils {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isBoss(target)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
PlayerProfile profile = UserManager.getPlayer(player).getProfile();
|
PlayerProfile profile = UserManager.getPlayer(player).getProfile();
|
||||||
|
|
||||||
if (profile.getMobHealthbarType() == null) {
|
if (profile.getMobHealthbarType() == null) {
|
||||||
@@ -83,7 +87,7 @@ public final class MobHealthbarUtils {
|
|||||||
target.setMetadata(mcMMO.customVisibleKey, new FixedMetadataValue(mcMMO.p, false));
|
target.setMetadata(mcMMO.customVisibleKey, new FixedMetadataValue(mcMMO.p, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
new MobHealthDisplayUpdaterTask(target).runTaskLater(mcMMO.p, displayTime * 20); // Clear health display after 3 seconds
|
new MobHealthDisplayUpdaterTask(target).runTaskLater(mcMMO.p, displayTime * Misc.TICK_CONVERSION_FACTOR); // Clear health display after 3 seconds
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,4 +153,21 @@ public final class MobHealthbarUtils {
|
|||||||
|
|
||||||
return healthbar;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -291,4 +291,15 @@ public final class ModUtils {
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a custom entity is a boss.
|
||||||
|
*
|
||||||
|
* @param entity The entity to check
|
||||||
|
* @return true if the entity represents a boss, false otherwise
|
||||||
|
*/
|
||||||
|
public static boolean isCustomBossEntity(Entity entity) {
|
||||||
|
//TODO: Finish this method
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ public final class Permissions {
|
|||||||
|
|
||||||
public static boolean inspect(Permissible permissible) { return (permissible.hasPermission("mcmmo.commands.inspect")); }
|
public static boolean inspect(Permissible permissible) { return (permissible.hasPermission("mcmmo.commands.inspect")); }
|
||||||
public static boolean inspectFar(Permissible permissible) { return (permissible.hasPermission("mcmmo.commands.inspect.far")); }
|
public static boolean inspectFar(Permissible permissible) { return (permissible.hasPermission("mcmmo.commands.inspect.far")); }
|
||||||
|
public static boolean inspectHidden(Permissible permissible) { return (permissible.hasPermission("mcmmo.commands.inspect.hidden")); }
|
||||||
public static boolean inspectOffline(Permissible permissible) { return (permissible.hasPermission("mcmmo.commands.inspect.offline")); }
|
public static boolean inspectOffline(Permissible permissible) { return (permissible.hasPermission("mcmmo.commands.inspect.offline")); }
|
||||||
|
|
||||||
public static boolean kraken(Permissible permissible) { return permissible.hasPermission("mcmmo.commands.kraken"); }
|
public static boolean kraken(Permissible permissible) { return permissible.hasPermission("mcmmo.commands.kraken"); }
|
||||||
|
|||||||
@@ -15,33 +15,26 @@ public class UpdateChecker {
|
|||||||
private UpdateChecker() {}
|
private UpdateChecker() {}
|
||||||
|
|
||||||
public static boolean updateAvailable() throws Exception {
|
public static boolean updateAvailable() throws Exception {
|
||||||
String checkType = "release";
|
String checkType = Config.getInstance().getPreferBeta() ? "latest" : "release";
|
||||||
if (Config.getInstance().getPreferBeta()) {
|
|
||||||
checkType = "latest";
|
|
||||||
}
|
|
||||||
String version = mcMMO.p.getDescription().getVersion();
|
String version = mcMMO.p.getDescription().getVersion();
|
||||||
URL url = new URL("http://api.bukget.org/api2/bukkit/plugin/mcmmo/" + checkType);
|
|
||||||
InputStreamReader isr;
|
InputStreamReader isr;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
isr = new InputStreamReader(url.openStream());
|
isr = new InputStreamReader(new URL("http://api.bukget.org/api2/bukkit/plugin/mcmmo/" + checkType).openStream());
|
||||||
}
|
}
|
||||||
catch (UnknownHostException e) {
|
catch (UnknownHostException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String newVersion;
|
|
||||||
try {
|
try {
|
||||||
JSONParser jp = new JSONParser();
|
Object o = new JSONParser().parse(isr);
|
||||||
Object o = jp.parse(isr);
|
|
||||||
|
|
||||||
if (!(o instanceof JSONObject)) {
|
if (!(o instanceof JSONObject)) {
|
||||||
isr.close();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONObject jo = (JSONObject) o;
|
JSONObject versions = (JSONObject) ((JSONObject) o).get("versions");
|
||||||
jo = (JSONObject) jo.get("versions");
|
String newVersion = (String) versions.get("version");
|
||||||
newVersion = (String) jo.get("version");
|
|
||||||
|
|
||||||
String[] oldTokens = version.replaceAll("(?i)(-)(.+?)(-)", "-").split("[.]|-b");
|
String[] oldTokens = version.replaceAll("(?i)(-)(.+?)(-)", "-").split("[.]|-b");
|
||||||
String[] newTokens = newVersion.replaceAll("(?i)(-)(.+?)(-)", "-").split("[.]|-b");
|
String[] newTokens = newVersion.replaceAll("(?i)(-)(.+?)(-)", "-").split("[.]|-b");
|
||||||
@@ -49,22 +42,26 @@ public class UpdateChecker {
|
|||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
Integer newVer = Integer.parseInt(newTokens[i]);
|
Integer newVer = Integer.parseInt(newTokens[i]);
|
||||||
Integer oldVer;
|
Integer oldVer;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
oldVer = Integer.parseInt(oldTokens[i]);
|
oldVer = Integer.parseInt(oldTokens[i]);
|
||||||
}
|
}
|
||||||
catch (NumberFormatException e) {
|
catch (NumberFormatException e) {
|
||||||
oldVer = 0;
|
oldVer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oldVer < newVer) {
|
if (oldVer < newVer) {
|
||||||
isr.close();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
catch (ParseException e) {
|
catch (ParseException e) {
|
||||||
isr.close();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
finally {
|
||||||
|
isr.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import com.gmail.nossr50.commands.chat.AdminChatCommand;
|
|||||||
import com.gmail.nossr50.commands.chat.PartyChatCommand;
|
import com.gmail.nossr50.commands.chat.PartyChatCommand;
|
||||||
import com.gmail.nossr50.commands.database.McpurgeCommand;
|
import com.gmail.nossr50.commands.database.McpurgeCommand;
|
||||||
import com.gmail.nossr50.commands.database.McremoveCommand;
|
import com.gmail.nossr50.commands.database.McremoveCommand;
|
||||||
|
import com.gmail.nossr50.commands.database.MmoshowdbCommand;
|
||||||
import com.gmail.nossr50.commands.database.MmoupdateCommand;
|
import com.gmail.nossr50.commands.database.MmoupdateCommand;
|
||||||
import com.gmail.nossr50.commands.experience.AddlevelsCommand;
|
import com.gmail.nossr50.commands.experience.AddlevelsCommand;
|
||||||
import com.gmail.nossr50.commands.experience.AddxpCommand;
|
import com.gmail.nossr50.commands.experience.AddxpCommand;
|
||||||
@@ -276,11 +277,20 @@ public final class CommandRegistrationManager {
|
|||||||
PluginCommand command = mcMMO.p.getCommand("mmoupdate");
|
PluginCommand command = mcMMO.p.getCommand("mmoupdate");
|
||||||
command.setDescription(LocaleLoader.getString("Commands.Description.mmoupdate"));
|
command.setDescription(LocaleLoader.getString("Commands.Description.mmoupdate"));
|
||||||
command.setPermission("mcmmo.commands.mmoupdate");
|
command.setPermission("mcmmo.commands.mmoupdate");
|
||||||
command.setPermissionMessage(permissionsMessage);
|
command.setPermissionMessage(LocaleLoader.getString("Commands.mmoupdate.OpOnly"));
|
||||||
command.setUsage(LocaleLoader.getString("Commands.Usage.0", "mmoupdate"));
|
command.setUsage(LocaleLoader.getString("Commands.Usage.1", "mmoupdate", "<confirm|flatfile|sql|" + LocaleLoader.getString("Commands.Usage.FullClassName") + ">"));
|
||||||
command.setExecutor(new MmoupdateCommand());
|
command.setExecutor(new MmoupdateCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void registerMmoshowdbCommand() {
|
||||||
|
PluginCommand command = mcMMO.p.getCommand("mmoshowdb");
|
||||||
|
command.setDescription(LocaleLoader.getString("Commands.Description.mmoshowdb"));
|
||||||
|
command.setPermission("mcmmo.commands.mmoshowdb");
|
||||||
|
command.setPermissionMessage(permissionsMessage);
|
||||||
|
command.setUsage(LocaleLoader.getString("Commands.Usage.0", "mmoshowdb"));
|
||||||
|
command.setExecutor(new MmoshowdbCommand());
|
||||||
|
}
|
||||||
|
|
||||||
private static void registerAdminChatCommand() {
|
private static void registerAdminChatCommand() {
|
||||||
PluginCommand command = mcMMO.p.getCommand("adminchat");
|
PluginCommand command = mcMMO.p.getCommand("adminchat");
|
||||||
command.setDescription(LocaleLoader.getString("Commands.Description.adminchat"));
|
command.setDescription(LocaleLoader.getString("Commands.Description.adminchat"));
|
||||||
@@ -421,6 +431,7 @@ public final class CommandRegistrationManager {
|
|||||||
registerMcpurgeCommand();
|
registerMcpurgeCommand();
|
||||||
registerMcremoveCommand();
|
registerMcremoveCommand();
|
||||||
registerMmoupdateCommand();
|
registerMmoupdateCommand();
|
||||||
|
registerMmoshowdbCommand();
|
||||||
|
|
||||||
// Experience Commands
|
// Experience Commands
|
||||||
registerAddlevelsCommand();
|
registerAddlevelsCommand();
|
||||||
|
|||||||
@@ -55,6 +55,14 @@ public final class CommandUtils {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean hidden(CommandSender sender, Player target, boolean hasPermission) {
|
||||||
|
if (sender instanceof Player && !((Player)sender).canSee(target) && !hasPermission) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean noConsoleUsage(CommandSender sender) {
|
public static boolean noConsoleUsage(CommandSender sender) {
|
||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -1,22 +1,55 @@
|
|||||||
package com.gmail.nossr50.util.player;
|
package com.gmail.nossr50.util.player;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||||
|
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||||
|
import com.gmail.nossr50.runnables.player.PlayerProfileLoader;
|
||||||
|
|
||||||
public final class UserManager {
|
public final class UserManager {
|
||||||
private final static Map<String, McMMOPlayer> players = new HashMap<String, McMMOPlayer>();
|
private final static Map<String, McMMOPlayer> players = new HashMap<String, McMMOPlayer>();
|
||||||
|
private final static Map<String, Future<PlayerProfile>> loadTasks = new HashMap<String, Future<PlayerProfile>>();
|
||||||
|
private final static ExecutorService loadExecutor = Executors.newCachedThreadPool();
|
||||||
|
|
||||||
private UserManager() {};
|
private UserManager() {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new user.
|
* Asynchronously pre-fetch information about the player. This is intended
|
||||||
|
* to expedite the PlayerJoinEvent.
|
||||||
|
*
|
||||||
|
* @param playerName The player name
|
||||||
|
*/
|
||||||
|
public static void prefetchUserData(String playerName) {
|
||||||
|
loadTasks.put(playerName, loadExecutor.submit(new PlayerProfileLoader(playerName)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Discard the information from the prefetch - for example, due to the
|
||||||
|
* user being banned.
|
||||||
|
*
|
||||||
|
* @param playerName The player name
|
||||||
|
*/
|
||||||
|
public static void discardPrefetch(String playerName) {
|
||||||
|
Future<PlayerProfile> oldTask = loadTasks.remove(playerName);
|
||||||
|
if (oldTask != null) {
|
||||||
|
oldTask.cancel(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a new user. If the prefetched player information is available, it
|
||||||
|
* will be used.
|
||||||
*
|
*
|
||||||
* @param player The player to create a user record for
|
* @param player The player to create a user record for
|
||||||
* @return the player's {@link McMMOPlayer} object
|
* @return the player's {@link McMMOPlayer} object
|
||||||
@@ -29,7 +62,22 @@ public final class UserManager {
|
|||||||
mcMMOPlayer.setPlayer(player); // The player object is different on each reconnection and must be updated
|
mcMMOPlayer.setPlayer(player); // The player object is different on each reconnection and must be updated
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Future<PlayerProfile> task = loadTasks.remove(playerName);
|
||||||
|
if (task != null && !task.isCancelled()) {
|
||||||
|
try {
|
||||||
|
mcMMOPlayer = new McMMOPlayer(player, task.get());
|
||||||
|
// TODO copy any additional post-processing here
|
||||||
|
players.put(playerName, mcMMOPlayer);
|
||||||
|
return mcMMOPlayer;
|
||||||
|
}
|
||||||
|
catch (ExecutionException e) {
|
||||||
|
}
|
||||||
|
catch (InterruptedException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Did not return - load on main thread
|
||||||
mcMMOPlayer = new McMMOPlayer(player);
|
mcMMOPlayer = new McMMOPlayer(player);
|
||||||
|
// (start post-processing that must be copied above)
|
||||||
players.put(playerName, mcMMOPlayer);
|
players.put(playerName, mcMMOPlayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,12 +91,14 @@ public final class UserManager {
|
|||||||
*/
|
*/
|
||||||
public static void remove(String playerName) {
|
public static void remove(String playerName) {
|
||||||
players.remove(playerName);
|
players.remove(playerName);
|
||||||
|
discardPrefetch(playerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear all users.
|
* Clear all users.
|
||||||
*/
|
*/
|
||||||
public static void clearAll() {
|
public static void clearAll() {
|
||||||
|
discardAllPrefetch();
|
||||||
players.clear();
|
players.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,11 +106,23 @@ public final class UserManager {
|
|||||||
* Save all users.
|
* Save all users.
|
||||||
*/
|
*/
|
||||||
public static void saveAll() {
|
public static void saveAll() {
|
||||||
|
discardAllPrefetch();
|
||||||
for (McMMOPlayer mcMMOPlayer : players.values()) {
|
for (McMMOPlayer mcMMOPlayer : players.values()) {
|
||||||
mcMMOPlayer.getProfile().save();
|
mcMMOPlayer.getProfile().save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Discard / cancel all data prefetching.
|
||||||
|
*/
|
||||||
|
public static void discardAllPrefetch() {
|
||||||
|
Iterator<Future<PlayerProfile>> taskIter = loadTasks.values().iterator();
|
||||||
|
while (taskIter.hasNext()) {
|
||||||
|
taskIter.next().cancel(false);
|
||||||
|
taskIter.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static Map<String, McMMOPlayer> getPlayers() {
|
public static Map<String, McMMOPlayer> getPlayers() {
|
||||||
return players;
|
return players;
|
||||||
}
|
}
|
||||||
@@ -73,9 +135,11 @@ public final class UserManager {
|
|||||||
*/
|
*/
|
||||||
public static McMMOPlayer getPlayer(String playerName) {
|
public static McMMOPlayer getPlayer(String playerName) {
|
||||||
List<Player> matches = mcMMO.p.getServer().matchPlayer(playerName);
|
List<Player> matches = mcMMO.p.getServer().matchPlayer(playerName);
|
||||||
|
|
||||||
if (matches.size() == 1) {
|
if (matches.size() == 1) {
|
||||||
playerName = matches.get(0).getName();
|
playerName = matches.get(0).getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
return players.get(playerName);
|
return players.get(playerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.gmail.nossr50.util.scoreboards;
|
package com.gmail.nossr50.util.scoreboards;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -15,13 +14,13 @@ import org.bukkit.scoreboard.Scoreboard;
|
|||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.config.Config;
|
import com.gmail.nossr50.config.Config;
|
||||||
import com.gmail.nossr50.database.FlatfileDatabaseManager;
|
|
||||||
import com.gmail.nossr50.database.SQLDatabaseManager;
|
|
||||||
import com.gmail.nossr50.datatypes.database.PlayerStat;
|
import com.gmail.nossr50.datatypes.database.PlayerStat;
|
||||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||||
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
import com.gmail.nossr50.runnables.scoreboards.ScoreboardChangeTask;
|
import com.gmail.nossr50.runnables.scoreboards.ScoreboardChangeTask;
|
||||||
|
import com.gmail.nossr50.util.Misc;
|
||||||
import com.gmail.nossr50.util.Permissions;
|
import com.gmail.nossr50.util.Permissions;
|
||||||
import com.gmail.nossr50.util.player.UserManager;
|
import com.gmail.nossr50.util.player.UserManager;
|
||||||
import com.gmail.nossr50.util.skills.SkillUtils;
|
import com.gmail.nossr50.util.skills.SkillUtils;
|
||||||
@@ -30,10 +29,16 @@ public class ScoreboardManager {
|
|||||||
private static final Map<String, Scoreboard> PLAYER_SCOREBOARDS = new HashMap<String, Scoreboard>();
|
private static final Map<String, Scoreboard> PLAYER_SCOREBOARDS = new HashMap<String, Scoreboard>();
|
||||||
private static final Scoreboard GLOBAL_STATS_SCOREBOARD = mcMMO.p.getServer().getScoreboardManager().getNewScoreboard();
|
private static final Scoreboard GLOBAL_STATS_SCOREBOARD = mcMMO.p.getServer().getScoreboardManager().getNewScoreboard();
|
||||||
|
|
||||||
private final static String PLAYER_STATS_HEADER = "mcMMO Stats";
|
private final static String PLAYER_STATS_HEADER = LocaleLoader.getString("Scoreboard.Header.PlayerStats");
|
||||||
private final static String PLAYER_RANK_HEADER = "mcMMO Rankings";
|
private final static String PLAYER_RANK_HEADER = LocaleLoader.getString("Scoreboard.Header.PlayerRank");
|
||||||
private final static String PLAYER_INSPECT_HEADER = "mcMMO Stats: ";
|
private final static String PLAYER_INSPECT_HEADER = LocaleLoader.getString("Scoreboard.Header.PlayerInspect");
|
||||||
private final static String POWER_LEVEL_HEADER = "Power Level";
|
private final static String POWER_LEVEL_HEADER = LocaleLoader.getString("Scoreboard.Header.PowerLevel");
|
||||||
|
|
||||||
|
private final static String POWER_LEVEL = LocaleLoader.getString("Scoreboard.Misc.PowerLevel");
|
||||||
|
private final static String LEVEL = LocaleLoader.getString("Scoreboard.Misc.Level");
|
||||||
|
private final static String CURRENT_XP = LocaleLoader.getString("Scoreboard.Misc.CurrentXP");
|
||||||
|
private final static String REMAINING_XP = LocaleLoader.getString("Scoreboard.Misc.RemainingXP");
|
||||||
|
private final static String OVERALL = LocaleLoader.getString("Scoreboard.Misc.Overall");
|
||||||
|
|
||||||
private final static List<String> SCOREBOARD_TASKS = new ArrayList<String>();
|
private final static List<String> SCOREBOARD_TASKS = new ArrayList<String>();
|
||||||
|
|
||||||
@@ -160,7 +165,7 @@ public class ScoreboardManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Objective newObjective = GLOBAL_STATS_SCOREBOARD.registerNewObjective(skillName, "dummy");
|
Objective newObjective = GLOBAL_STATS_SCOREBOARD.registerNewObjective(skillName, "dummy");
|
||||||
newObjective.setDisplayName(ChatColor.GOLD + (skillName.equalsIgnoreCase("all") ? "Power Level" : SkillUtils.getSkillName(SkillType.getSkill(skillName))));
|
newObjective.setDisplayName(ChatColor.GOLD + (skillName.equalsIgnoreCase("all") ? POWER_LEVEL : SkillUtils.getSkillName(SkillType.getSkill(skillName))));
|
||||||
|
|
||||||
updateGlobalStatsScores(player, newObjective, skillName, pageNumber);
|
updateGlobalStatsScores(player, newObjective, skillName, pageNumber);
|
||||||
changeScoreboard(player, oldScoreboard, GLOBAL_STATS_SCOREBOARD, Config.getInstance().getMctopScoreboardTime());
|
changeScoreboard(player, oldScoreboard, GLOBAL_STATS_SCOREBOARD, Config.getInstance().getMctopScoreboardTime());
|
||||||
@@ -170,9 +175,9 @@ public class ScoreboardManager {
|
|||||||
Server server = mcMMO.p.getServer();
|
Server server = mcMMO.p.getServer();
|
||||||
int currentXP = profile.getSkillXpLevel(skill);
|
int currentXP = profile.getSkillXpLevel(skill);
|
||||||
|
|
||||||
objective.getScore(server.getOfflinePlayer("Level")).setScore(profile.getSkillLevel(skill));
|
objective.getScore(server.getOfflinePlayer(LEVEL)).setScore(profile.getSkillLevel(skill));
|
||||||
objective.getScore(server.getOfflinePlayer("Current XP")).setScore(currentXP);
|
objective.getScore(server.getOfflinePlayer(CURRENT_XP)).setScore(currentXP);
|
||||||
objective.getScore(server.getOfflinePlayer("Remaining XP")).setScore(profile.getXpToLevel(skill) - currentXP);
|
objective.getScore(server.getOfflinePlayer(REMAINING_XP)).setScore(profile.getXpToLevel(skill) - currentXP);
|
||||||
|
|
||||||
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
|
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
|
||||||
}
|
}
|
||||||
@@ -190,7 +195,7 @@ public class ScoreboardManager {
|
|||||||
objective.getScore(server.getOfflinePlayer(SkillUtils.getSkillName(skill))).setScore(profile.getSkillLevel(skill));
|
objective.getScore(server.getOfflinePlayer(SkillUtils.getSkillName(skill))).setScore(profile.getSkillLevel(skill));
|
||||||
}
|
}
|
||||||
|
|
||||||
objective.getScore(server.getOfflinePlayer(ChatColor.GOLD + "Power Level")).setScore(mcMMOPlayer.getPowerLevel());
|
objective.getScore(server.getOfflinePlayer(ChatColor.GOLD + POWER_LEVEL)).setScore(mcMMOPlayer.getPowerLevel());
|
||||||
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
|
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,7 +204,7 @@ public class ScoreboardManager {
|
|||||||
Server server = mcMMO.p.getServer();
|
Server server = mcMMO.p.getServer();
|
||||||
Integer rank;
|
Integer rank;
|
||||||
|
|
||||||
Map<String, Integer> skills = Config.getInstance().getUseMySQL() ? SQLDatabaseManager.readSQLRank(playerName) : FlatfileDatabaseManager.getPlayerRanks(playerName);
|
Map<String, Integer> skills = mcMMO.getDatabaseManager().readRank(playerName);
|
||||||
|
|
||||||
for (SkillType skill : SkillType.nonChildSkills()) {
|
for (SkillType skill : SkillType.nonChildSkills()) {
|
||||||
if (!Permissions.skillEnabled(player, skill)) {
|
if (!Permissions.skillEnabled(player, skill)) {
|
||||||
@@ -216,7 +221,7 @@ public class ScoreboardManager {
|
|||||||
rank = skills.get("ALL");
|
rank = skills.get("ALL");
|
||||||
|
|
||||||
if (rank != null) {
|
if (rank != null) {
|
||||||
objective.getScore(server.getOfflinePlayer(ChatColor.GOLD + "Overall")).setScore(rank);
|
objective.getScore(server.getOfflinePlayer(ChatColor.GOLD + OVERALL)).setScore(rank);
|
||||||
}
|
}
|
||||||
|
|
||||||
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
|
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
|
||||||
@@ -226,7 +231,7 @@ public class ScoreboardManager {
|
|||||||
Server server = mcMMO.p.getServer();
|
Server server = mcMMO.p.getServer();
|
||||||
Integer rank;
|
Integer rank;
|
||||||
|
|
||||||
Map<String, Integer> skills = Config.getInstance().getUseMySQL() ? SQLDatabaseManager.readSQLRank(targetName) : FlatfileDatabaseManager.getPlayerRanks(targetName);
|
Map<String, Integer> skills = mcMMO.getDatabaseManager().readRank(targetName);
|
||||||
|
|
||||||
for (SkillType skill : SkillType.nonChildSkills()) {
|
for (SkillType skill : SkillType.nonChildSkills()) {
|
||||||
rank = skills.get(skill.name());
|
rank = skills.get(skill.name());
|
||||||
@@ -239,7 +244,7 @@ public class ScoreboardManager {
|
|||||||
rank = skills.get("ALL");
|
rank = skills.get("ALL");
|
||||||
|
|
||||||
if (rank != null) {
|
if (rank != null) {
|
||||||
objective.getScore(server.getOfflinePlayer(ChatColor.GOLD + "Overall")).setScore(rank);
|
objective.getScore(server.getOfflinePlayer(ChatColor.GOLD + OVERALL)).setScore(rank);
|
||||||
}
|
}
|
||||||
|
|
||||||
objective.setDisplayName(PLAYER_RANK_HEADER + ": " + targetName);
|
objective.setDisplayName(PLAYER_RANK_HEADER + ": " + targetName);
|
||||||
@@ -263,7 +268,7 @@ public class ScoreboardManager {
|
|||||||
powerLevel += skillLevel;
|
powerLevel += skillLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
objective.getScore(server.getOfflinePlayer(ChatColor.GOLD + "Power Level")).setScore(powerLevel);
|
objective.getScore(server.getOfflinePlayer(ChatColor.GOLD + POWER_LEVEL)).setScore(powerLevel);
|
||||||
objective.setDisplayName(PLAYER_INSPECT_HEADER + target.getName());
|
objective.setDisplayName(PLAYER_INSPECT_HEADER + target.getName());
|
||||||
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
|
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
|
||||||
}
|
}
|
||||||
@@ -279,7 +284,7 @@ public class ScoreboardManager {
|
|||||||
powerLevel += skillLevel;
|
powerLevel += skillLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
objective.getScore(server.getOfflinePlayer(ChatColor.GOLD + "Power Level")).setScore(powerLevel);
|
objective.getScore(server.getOfflinePlayer(ChatColor.GOLD + POWER_LEVEL)).setScore(powerLevel);
|
||||||
objective.setDisplayName(PLAYER_INSPECT_HEADER + targetProfile.getPlayerName());
|
objective.setDisplayName(PLAYER_INSPECT_HEADER + targetProfile.getPlayerName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,33 +294,15 @@ public class ScoreboardManager {
|
|||||||
String endPosition = String.valueOf(position + 14);
|
String endPosition = String.valueOf(position + 14);
|
||||||
Server server = mcMMO.p.getServer();
|
Server server = mcMMO.p.getServer();
|
||||||
|
|
||||||
if (Config.getInstance().getUseMySQL()) {
|
for (PlayerStat stat : mcMMO.getDatabaseManager().readLeaderboard(skillName, pageNumber, 15)) {
|
||||||
String tablePrefix = Config.getInstance().getMySQLTablePrefix();
|
String playerName = stat.name;
|
||||||
String query = (skillName.equalsIgnoreCase("all") ? "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing" : skillName);
|
playerName = (playerName.equals(player.getName()) ? ChatColor.GOLD : "") + playerName;
|
||||||
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 " + ((pageNumber * 15) - 15) + ",15").values();
|
|
||||||
|
|
||||||
for (ArrayList<String> stat : userStats) {
|
if (playerName.length() > 16) {
|
||||||
String playerName = stat.get(1);
|
playerName = playerName.substring(0, 16);
|
||||||
playerName = (playerName.equals(player.getName()) ? ChatColor.GOLD : "") + playerName;
|
|
||||||
|
|
||||||
if (playerName.length() > 16) {
|
|
||||||
playerName = playerName.substring(0, 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
objective.getScore(server.getOfflinePlayer(playerName)).setScore(Integer.valueOf(stat.get(0)));
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else {
|
|
||||||
for (PlayerStat stat : FlatfileDatabaseManager.retrieveInfo(skillName, pageNumber, 15)) {
|
|
||||||
String playerName = stat.name;
|
|
||||||
playerName = (playerName.equals(player.getName()) ? ChatColor.GOLD : "") + playerName;
|
|
||||||
|
|
||||||
if (playerName.length() > 16) {
|
objective.getScore(server.getOfflinePlayer(playerName)).setScore(stat.statVal);
|
||||||
playerName = playerName.substring(0, 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
objective.getScore(server.getOfflinePlayer(playerName)).setScore(stat.statVal);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
objective.setDisplayName(objective.getDisplayName() + " (" + startPosition + " - " + endPosition + ")");
|
objective.setDisplayName(objective.getDisplayName() + " (" + startPosition + " - " + endPosition + ")");
|
||||||
@@ -330,7 +317,7 @@ public class ScoreboardManager {
|
|||||||
enablePowerLevelDisplay(player);
|
enablePowerLevelDisplay(player);
|
||||||
|
|
||||||
if (displayTime != -1 && !SCOREBOARD_TASKS.contains(playerName)) {
|
if (displayTime != -1 && !SCOREBOARD_TASKS.contains(playerName)) {
|
||||||
new ScoreboardChangeTask(player, oldScoreboard).runTaskLater(mcMMO.p, displayTime * 20);
|
new ScoreboardChangeTask(player, oldScoreboard).runTaskLater(mcMMO.p, displayTime * Misc.TICK_CONVERSION_FACTOR);
|
||||||
SCOREBOARD_TASKS.add(playerName);
|
SCOREBOARD_TASKS.add(playerName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,12 +46,136 @@ import com.gmail.nossr50.util.player.UserManager;
|
|||||||
public final class CombatUtils {
|
public final class CombatUtils {
|
||||||
private CombatUtils() {}
|
private CombatUtils() {}
|
||||||
|
|
||||||
|
private static void processSwordCombat(LivingEntity target, Player player, int damage) {
|
||||||
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
|
SwordsManager swordsManager = mcMMOPlayer.getSwordsManager();
|
||||||
|
|
||||||
|
if (swordsManager.canActivateAbility()) {
|
||||||
|
SkillUtils.abilityCheck(mcMMOPlayer, SkillType.SWORDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (swordsManager.canUseBleed()) {
|
||||||
|
swordsManager.bleedCheck(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (swordsManager.canUseSerratedStrike()) {
|
||||||
|
swordsManager.serratedStrikes(target, damage);
|
||||||
|
}
|
||||||
|
|
||||||
|
startGainXp(mcMMOPlayer, target, SkillType.SWORDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void processAxeCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event) {
|
||||||
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
|
AxesManager axesManager = mcMMOPlayer.getAxesManager();
|
||||||
|
|
||||||
|
if (axesManager.canActivateAbility()) {
|
||||||
|
SkillUtils.abilityCheck(mcMMOPlayer, SkillType.AXES);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (axesManager.canUseAxeMastery()) {
|
||||||
|
event.setDamage(axesManager.axeMasteryCheck(event.getDamage()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (axesManager.canCriticalHit(target)) {
|
||||||
|
event.setDamage(axesManager.criticalHitCheck(target, event.getDamage()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (axesManager.canImpact(target)) {
|
||||||
|
axesManager.impactCheck(target);
|
||||||
|
}
|
||||||
|
else if (axesManager.canGreaterImpact(target)) {
|
||||||
|
event.setDamage(axesManager.greaterImpactCheck(target, event.getDamage()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (axesManager.canUseSkullSplitter(target)) {
|
||||||
|
axesManager.skullSplitterCheck(target, event.getDamage());
|
||||||
|
}
|
||||||
|
|
||||||
|
startGainXp(mcMMOPlayer, target, SkillType.AXES);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void processUnarmedCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event) {
|
||||||
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
|
UnarmedManager unarmedManager = mcMMOPlayer.getUnarmedManager();
|
||||||
|
|
||||||
|
if (unarmedManager.canActivateAbility()) {
|
||||||
|
SkillUtils.abilityCheck(mcMMOPlayer, SkillType.UNARMED);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unarmedManager.canUseIronArm()) {
|
||||||
|
event.setDamage(unarmedManager.ironArmCheck(event.getDamage()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unarmedManager.canUseBerserk()) {
|
||||||
|
event.setDamage(unarmedManager.berserkDamage(event.getDamage()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unarmedManager.canDisarm(target)) {
|
||||||
|
unarmedManager.disarmCheck((Player) target);
|
||||||
|
}
|
||||||
|
|
||||||
|
startGainXp(mcMMOPlayer, target, SkillType.UNARMED);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void processTamingCombat(LivingEntity target, Player master, Wolf wolf, EntityDamageByEntityEvent event) {
|
||||||
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(master);
|
||||||
|
TamingManager tamingManager = mcMMOPlayer.getTamingManager();
|
||||||
|
|
||||||
|
if (tamingManager.canUseFastFoodService()) {
|
||||||
|
tamingManager.fastFoodService(wolf, event.getDamage());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tamingManager.canUseSharpenedClaws()) {
|
||||||
|
event.setDamage(Taming.sharpenedClaws(event.getDamage()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tamingManager.canUseGore()) {
|
||||||
|
event.setDamage(tamingManager.gore(target, event.getDamage()));
|
||||||
|
}
|
||||||
|
|
||||||
|
startGainXp(mcMMOPlayer, target, SkillType.TAMING);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void processArcheryCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event, Entity arrow) {
|
||||||
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
|
ArcheryManager archeryManager = mcMMOPlayer.getArcheryManager();
|
||||||
|
|
||||||
|
if (archeryManager.canSkillShot()) {
|
||||||
|
event.setDamage(archeryManager.skillShotCheck(event.getDamage()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (target instanceof Player && SkillType.UNARMED.getPVPEnabled()) {
|
||||||
|
UnarmedManager unarmedManager = UserManager.getPlayer((Player) target).getUnarmedManager();
|
||||||
|
|
||||||
|
if (unarmedManager.canDeflect()) {
|
||||||
|
event.setCancelled(unarmedManager.deflectCheck());
|
||||||
|
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (archeryManager.canDaze(target)) {
|
||||||
|
event.setDamage(archeryManager.dazeCheck((Player) target, event.getDamage()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!arrow.hasMetadata(mcMMO.infiniteArrowKey) && archeryManager.canTrackArrows()) {
|
||||||
|
archeryManager.trackArrows(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
archeryManager.distanceXpBonus(target, arrow);
|
||||||
|
|
||||||
|
startGainXp(mcMMOPlayer, target, SkillType.ARCHERY, arrow.getMetadata(mcMMO.bowForceKey).get(0).asDouble());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply combat modifiers and process and XP gain.
|
* Apply combat modifiers and process and XP gain.
|
||||||
*
|
*
|
||||||
* @param event The event to run the combat checks on.
|
* @param event The event to run the combat checks on.
|
||||||
*/
|
*/
|
||||||
public static void combatChecks(EntityDamageByEntityEvent event, Entity attacker, LivingEntity target) {
|
public static void processCombatAttack(EntityDamageByEntityEvent event, Entity attacker, LivingEntity target) {
|
||||||
Entity damager = event.getDamager();
|
Entity damager = event.getDamager();
|
||||||
|
|
||||||
if (attacker instanceof Player && damager.getType() == EntityType.PLAYER) {
|
if (attacker instanceof Player && damager.getType() == EntityType.PLAYER) {
|
||||||
@@ -61,12 +185,11 @@ public final class CombatUtils {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
|
||||||
ItemStack heldItem = player.getItemInHand();
|
ItemStack heldItem = player.getItemInHand();
|
||||||
|
|
||||||
if (target instanceof Tameable) {
|
if (target instanceof Tameable) {
|
||||||
if (heldItem.getType() == Material.BONE) {
|
if (heldItem.getType() == Material.BONE) {
|
||||||
TamingManager tamingManager = mcMMOPlayer.getTamingManager();
|
TamingManager tamingManager = UserManager.getPlayer(player).getTamingManager();
|
||||||
|
|
||||||
if (tamingManager.canUseBeastLore()) {
|
if (tamingManager.canUseBeastLore()) {
|
||||||
tamingManager.beastLore(target);
|
tamingManager.beastLore(target);
|
||||||
@@ -86,21 +209,7 @@ public final class CombatUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Permissions.skillEnabled(player, SkillType.SWORDS)) {
|
if (Permissions.skillEnabled(player, SkillType.SWORDS)) {
|
||||||
SwordsManager swordsManager = mcMMOPlayer.getSwordsManager();
|
processSwordCombat(target, player, event.getDamage());
|
||||||
|
|
||||||
if (swordsManager.canActivateAbility()) {
|
|
||||||
SkillUtils.abilityCheck(mcMMOPlayer, SkillType.SWORDS);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (swordsManager.canUseBleed()) {
|
|
||||||
swordsManager.bleedCheck(target);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (swordsManager.canUseSerratedStrike()) {
|
|
||||||
swordsManager.serratedStrikes(target, event.getDamage());
|
|
||||||
}
|
|
||||||
|
|
||||||
startGainXp(mcMMOPlayer, target, SkillType.SWORDS);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (ItemUtils.isAxe(heldItem)) {
|
else if (ItemUtils.isAxe(heldItem)) {
|
||||||
@@ -109,32 +218,7 @@ public final class CombatUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Permissions.skillEnabled(player, SkillType.AXES)) {
|
if (Permissions.skillEnabled(player, SkillType.AXES)) {
|
||||||
AxesManager axesManager = mcMMOPlayer.getAxesManager();
|
processAxeCombat(target, player, event);
|
||||||
|
|
||||||
if (axesManager.canActivateAbility()) {
|
|
||||||
SkillUtils.abilityCheck(mcMMOPlayer, SkillType.AXES);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (axesManager.canUseAxeMastery()) {
|
|
||||||
event.setDamage(axesManager.axeMasteryCheck(event.getDamage()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (axesManager.canCriticalHit(target)) {
|
|
||||||
event.setDamage(axesManager.criticalHitCheck(target, event.getDamage()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (axesManager.canImpact(target)) {
|
|
||||||
axesManager.impactCheck(target);
|
|
||||||
}
|
|
||||||
else if (axesManager.canGreaterImpact(target)) {
|
|
||||||
event.setDamage(axesManager.greaterImpactCheck(target, event.getDamage()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (axesManager.canUseSkullSplitter(target)) {
|
|
||||||
axesManager.skullSplitterCheck(target, event.getDamage());
|
|
||||||
}
|
|
||||||
|
|
||||||
startGainXp(mcMMOPlayer, target, SkillType.AXES);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (heldItem.getType() == Material.AIR) {
|
else if (heldItem.getType() == Material.AIR) {
|
||||||
@@ -143,25 +227,7 @@ public final class CombatUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Permissions.skillEnabled(player, SkillType.UNARMED)) {
|
if (Permissions.skillEnabled(player, SkillType.UNARMED)) {
|
||||||
UnarmedManager unarmedManager = mcMMOPlayer.getUnarmedManager();
|
processUnarmedCombat(target, player, event);
|
||||||
|
|
||||||
if (unarmedManager.canActivateAbility()) {
|
|
||||||
SkillUtils.abilityCheck(mcMMOPlayer, SkillType.UNARMED);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unarmedManager.canUseIronArm()) {
|
|
||||||
event.setDamage(unarmedManager.ironArmCheck(event.getDamage()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unarmedManager.canUseBerserk()) {
|
|
||||||
event.setDamage(unarmedManager.berserkDamage(event.getDamage()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unarmedManager.canDisarm(target)) {
|
|
||||||
unarmedManager.disarmCheck((Player) target);
|
|
||||||
}
|
|
||||||
|
|
||||||
startGainXp(mcMMOPlayer, target, SkillType.UNARMED);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -169,36 +235,20 @@ public final class CombatUtils {
|
|||||||
switch (damager.getType()) {
|
switch (damager.getType()) {
|
||||||
case WOLF:
|
case WOLF:
|
||||||
Wolf wolf = (Wolf) damager;
|
Wolf wolf = (Wolf) damager;
|
||||||
|
AnimalTamer tamer = wolf.getOwner();
|
||||||
|
|
||||||
if (wolf.isTamed() && wolf.getOwner() instanceof Player) {
|
if (tamer == null || !(tamer instanceof Player) || !shouldProcessSkill(target, SkillType.TAMING)) {
|
||||||
Player master = (Player) wolf.getOwner();
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (Misc.isNPCEntity(master)) {
|
Player master = (Player) tamer;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!shouldProcessSkill(target, SkillType.TAMING)) {
|
if (Misc.isNPCEntity(master)) {
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Permissions.skillEnabled(master, SkillType.TAMING)) {
|
if (Permissions.skillEnabled(master, SkillType.TAMING)) {
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(master);
|
processTamingCombat(target, master, wolf, event);
|
||||||
TamingManager tamingManager = mcMMOPlayer.getTamingManager();
|
|
||||||
|
|
||||||
if (tamingManager.canUseFastFoodService()) {
|
|
||||||
tamingManager.fastFoodService(wolf, event.getDamage());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tamingManager.canUseSharpenedClaws()) {
|
|
||||||
event.setDamage(Taming.sharpenedClaws(event.getDamage()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tamingManager.canUseGore()) {
|
|
||||||
event.setDamage(tamingManager.gore(target, event.getDamage()));
|
|
||||||
}
|
|
||||||
|
|
||||||
startGainXp(mcMMOPlayer, target, SkillType.TAMING);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -206,12 +256,7 @@ public final class CombatUtils {
|
|||||||
case ARROW:
|
case ARROW:
|
||||||
LivingEntity shooter = ((Arrow) damager).getShooter();
|
LivingEntity shooter = ((Arrow) damager).getShooter();
|
||||||
|
|
||||||
/* Break instead of return due to Dodge/Counter/Deflect abilities */
|
if (shooter == null || !(shooter instanceof Player) || !shouldProcessSkill(target, SkillType.ARCHERY)) {
|
||||||
if (shooter == null || !(shooter instanceof Player)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!shouldProcessSkill(target, SkillType.ARCHERY)) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,38 +267,8 @@ public final class CombatUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Permissions.skillEnabled(player, SkillType.ARCHERY)) {
|
if (Permissions.skillEnabled(player, SkillType.ARCHERY)) {
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
processArcheryCombat(target, player, event, damager);
|
||||||
ArcheryManager archeryManager = mcMMOPlayer.getArcheryManager();
|
|
||||||
|
|
||||||
if (archeryManager.canSkillShot()) {
|
|
||||||
event.setDamage(archeryManager.skillShotCheck(event.getDamage()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (target instanceof Player && SkillType.UNARMED.getPVPEnabled()) {
|
|
||||||
UnarmedManager unarmedManager = UserManager.getPlayer((Player) target).getUnarmedManager();
|
|
||||||
|
|
||||||
if (unarmedManager.canDeflect()) {
|
|
||||||
event.setCancelled(unarmedManager.deflectCheck());
|
|
||||||
|
|
||||||
if (event.isCancelled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (archeryManager.canDaze(target)) {
|
|
||||||
event.setDamage(archeryManager.dazeCheck((Player) target, event.getDamage()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!damager.hasMetadata(mcMMO.infiniteArrowKey) && archeryManager.canTrackArrows()) {
|
|
||||||
archeryManager.trackArrows(target);
|
|
||||||
}
|
|
||||||
|
|
||||||
archeryManager.distanceXpBonus(target, damager);
|
|
||||||
|
|
||||||
startGainXp(mcMMOPlayer, target, SkillType.ARCHERY, damager.getMetadata(mcMMO.bowForceKey).get(0).asDouble());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -261,12 +276,11 @@ public final class CombatUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (target instanceof Player) {
|
if (target instanceof Player) {
|
||||||
Player player = (Player) target;
|
if (Misc.isNPCEntity(target)) {
|
||||||
|
|
||||||
if (Misc.isNPCEntity(player)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Player player = (Player) target;
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
AcrobaticsManager acrobaticsManager = mcMMOPlayer.getAcrobaticsManager();
|
AcrobaticsManager acrobaticsManager = mcMMOPlayer.getAcrobaticsManager();
|
||||||
|
|
||||||
@@ -285,24 +299,6 @@ public final class CombatUtils {
|
|||||||
swordsManager.counterAttackChecks((LivingEntity) damager, event.getDamage());
|
swordsManager.counterAttackChecks((LivingEntity) damager, event.getDamage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (damager.getType() == EntityType.ARROW) {
|
|
||||||
LivingEntity shooter = ((Arrow) damager).getShooter();
|
|
||||||
|
|
||||||
if (shooter instanceof Player || !SkillType.UNARMED.getPVEEnabled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
UnarmedManager unarmedManager = mcMMOPlayer.getUnarmedManager();
|
|
||||||
|
|
||||||
if (unarmedManager.canDeflect()) {
|
|
||||||
event.setCancelled(unarmedManager.deflectCheck());
|
|
||||||
|
|
||||||
if (event.isCancelled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (attacker instanceof Player) {
|
else if (attacker instanceof Player) {
|
||||||
Player player = (Player) attacker;
|
Player player = (Player) attacker;
|
||||||
@@ -383,38 +379,40 @@ public final class CombatUtils {
|
|||||||
int numberOfTargets = Misc.getTier(attacker.getItemInHand()); // The higher the weapon tier, the more targets you hit
|
int numberOfTargets = Misc.getTier(attacker.getItemInHand()); // The higher the weapon tier, the more targets you hit
|
||||||
int damageAmount = Math.max(damage, 1);
|
int damageAmount = Math.max(damage, 1);
|
||||||
|
|
||||||
while (numberOfTargets > 0) {
|
for (Entity entity : target.getNearbyEntities(2.5, 2.5, 2.5)) {
|
||||||
for (Entity entity : target.getNearbyEntities(2.5, 2.5, 2.5)) {
|
if (numberOfTargets <= 0) {
|
||||||
if (Misc.isNPCEntity(entity) || !(entity instanceof LivingEntity) || !shouldBeAffected(attacker, entity)) {
|
break;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
LivingEntity livingEntity = (LivingEntity) entity;
|
|
||||||
mcMMO.p.getServer().getPluginManager().callEvent(new FakePlayerAnimationEvent(attacker));
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case SWORDS:
|
|
||||||
if (entity instanceof Player) {
|
|
||||||
((Player) entity).sendMessage(LocaleLoader.getString("Swords.Combat.SS.Struck"));
|
|
||||||
}
|
|
||||||
|
|
||||||
BleedTimerTask.add(livingEntity, Swords.serratedStrikesBleedTicks);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case AXES:
|
|
||||||
if (entity instanceof Player) {
|
|
||||||
((Player) entity).sendMessage(LocaleLoader.getString("Axes.Combat.Cleave.Struck"));
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
dealDamage(livingEntity, damageAmount, attacker);
|
|
||||||
numberOfTargets--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Misc.isNPCEntity(entity) || !(entity instanceof LivingEntity) || !shouldBeAffected(attacker, entity)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
LivingEntity livingEntity = (LivingEntity) entity;
|
||||||
|
mcMMO.p.getServer().getPluginManager().callEvent(new FakePlayerAnimationEvent(attacker));
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case SWORDS:
|
||||||
|
if (entity instanceof Player) {
|
||||||
|
((Player) entity).sendMessage(LocaleLoader.getString("Swords.Combat.SS.Struck"));
|
||||||
|
}
|
||||||
|
|
||||||
|
BleedTimerTask.add(livingEntity, Swords.serratedStrikesBleedTicks);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AXES:
|
||||||
|
if (entity instanceof Player) {
|
||||||
|
((Player) entity).sendMessage(LocaleLoader.getString("Axes.Combat.Cleave.Struck"));
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
dealDamage(livingEntity, damageAmount, attacker);
|
||||||
|
numberOfTargets--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -503,10 +501,10 @@ public final class CombatUtils {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (target.hasMetadata(mcMMO.entityMetadataKey)) {
|
if (target.hasMetadata(mcMMO.entityMetadataKey)) {
|
||||||
baseXP *= Config.getInstance().getSpawnedMobXpMultiplier();
|
baseXP *= Config.getInstance().getSpawnedMobXpMultiplier();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
baseXP *= 10;
|
baseXP *= 10;
|
||||||
@@ -589,9 +587,7 @@ public final class CombatUtils {
|
|||||||
if (tamer instanceof Player) {
|
if (tamer instanceof Player) {
|
||||||
Player owner = (Player) tamer;
|
Player owner = (Player) tamer;
|
||||||
|
|
||||||
if (owner == attacker || PartyManager.inSameParty(attacker, owner)) {
|
return (owner == attacker || PartyManager.inSameParty(attacker, owner));
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ public class SkillUtils {
|
|||||||
|
|
||||||
mcMMOPlayer.setToolPreparationATS(tool, System.currentTimeMillis());
|
mcMMOPlayer.setToolPreparationATS(tool, System.currentTimeMillis());
|
||||||
mcMMOPlayer.setToolPreparationMode(tool, true);
|
mcMMOPlayer.setToolPreparationMode(tool, true);
|
||||||
new ToolLowerTask(mcMMOPlayer, tool).runTaskLaterAsynchronously(mcMMO.p, 4 * 20);
|
new ToolLowerTask(mcMMOPlayer, tool).runTaskLaterAsynchronously(mcMMO.p, 4 * Misc.TICK_CONVERSION_FACTOR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -300,7 +300,7 @@ public class SkillUtils {
|
|||||||
handleAbilitySpeedIncrease(player);
|
handleAbilitySpeedIncrease(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
new AbilityDisableTask(mcMMOPlayer, ability).runTaskLater(mcMMO.p, ticks * 20);
|
new AbilityDisableTask(mcMMOPlayer, ability).runTaskLater(mcMMO.p, ticks * Misc.TICK_CONVERSION_FACTOR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -392,14 +392,8 @@ public class SkillUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
int ticks = 0;
|
SkillType skill = mcMMOPlayer.getAbilityMode(AbilityType.SUPER_BREAKER) ? SkillType.MINING : SkillType.EXCAVATION;
|
||||||
|
int ticks = PerksUtils.handleActivationPerks(player, 2 + (mcMMOPlayer.getProfile().getSkillLevel(skill) / AdvancedConfig.getInstance().getAbilityLength()), skill.getAbility().getMaxTicks()) * Misc.TICK_CONVERSION_FACTOR;
|
||||||
if (mcMMOPlayer.getAbilityMode(AbilityType.SUPER_BREAKER)) {
|
|
||||||
ticks = ((int) (mcMMOPlayer.getProfile().getSkillDATS(AbilityType.SUPER_BREAKER) - (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR))) * 20;
|
|
||||||
}
|
|
||||||
else if (mcMMOPlayer.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER)) {
|
|
||||||
ticks = ((int) (mcMMOPlayer.getProfile().getSkillDATS(AbilityType.GIGA_DRILL_BREAKER) - (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR))) * 20;
|
|
||||||
}
|
|
||||||
|
|
||||||
PotionEffect abilityBuff = new PotionEffect(PotionEffectType.FAST_DIGGING, duration + ticks, amplifier + 10);
|
PotionEffect abilityBuff = new PotionEffect(PotionEffectType.FAST_DIGGING, duration + ticks, amplifier + 10);
|
||||||
player.addPotionEffect(abilityBuff, true);
|
player.addPotionEffect(abilityBuff, true);
|
||||||
@@ -415,9 +409,6 @@ public class SkillUtils {
|
|||||||
playerInventory.setItem(i, removeAbilityBuff(item));
|
playerInventory.setItem(i, removeAbilityBuff(item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
player.removePotionEffect(PotionEffectType.FAST_DIGGING);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack removeAbilityBuff(ItemStack item) {
|
public static ItemStack removeAbilityBuff(ItemStack item) {
|
||||||
@@ -462,7 +453,7 @@ public class SkillUtils {
|
|||||||
* @param shouldArmSwing true if an armswing event should be fired, false otherwise
|
* @param shouldArmSwing true if an armswing event should be fired, false otherwise
|
||||||
* @return true if the event wasn't cancelled, false otherwise
|
* @return true if the event wasn't cancelled, false otherwise
|
||||||
*/
|
*/
|
||||||
public static boolean blockBreakSimulate(Block block, Player player, Boolean shouldArmSwing) {
|
public static boolean blockBreakSimulate(Block block, Player player, boolean shouldArmSwing) {
|
||||||
PluginManager pluginManger = mcMMO.p.getServer().getPluginManager();
|
PluginManager pluginManger = mcMMO.p.getServer().getPluginManager();
|
||||||
|
|
||||||
// Support for NoCheat
|
// Support for NoCheat
|
||||||
|
|||||||
@@ -26,9 +26,6 @@ General:
|
|||||||
Verbose_Logging: false
|
Verbose_Logging: false
|
||||||
# Should mcMMO over-write configs to update, or make new ones ending in .new?
|
# Should mcMMO over-write configs to update, or make new ones ending in .new?
|
||||||
Config_Update_Overwrite: true
|
Config_Update_Overwrite: true
|
||||||
# Enable potato easter egg?
|
|
||||||
Potato_Explosion_Enabled: false
|
|
||||||
Potato_Explosion_Chance: 1
|
|
||||||
|
|
||||||
Scoreboards:
|
Scoreboards:
|
||||||
# Should mcMMO use scoreboards for /inspect?
|
# Should mcMMO use scoreboards for /inspect?
|
||||||
|
|||||||
@@ -442,8 +442,11 @@ Commands.mmoedit=[player] <skill> <newvalue> [[RED]] - Modify target
|
|||||||
Commands.mmoedit.AllSkills.1=[[GREEN]]Your level in all skills was set to {0}!
|
Commands.mmoedit.AllSkills.1=[[GREEN]]Your level in all skills was set to {0}!
|
||||||
Commands.mmoedit.Modified.1=[[GREEN]]Your level in {0} was set to {1}!
|
Commands.mmoedit.Modified.1=[[GREEN]]Your level in {0} was set to {1}!
|
||||||
Commands.mmoedit.Modified.2=[[RED]]{0} has been modified for {1}.
|
Commands.mmoedit.Modified.2=[[RED]]{0} has been modified for {1}.
|
||||||
Commands.mmoupdate.Start=[[GRAY]]Starting conversion...
|
Commands.mmoupdate.Same=[[RED]]You are already using the {0} database!
|
||||||
Commands.mmoupdate.Finish=[[GREEN]]Conversion finished!
|
Commands.mmoupdate.InvalidType=[[RED]]{0} is not a valid database type.
|
||||||
|
Commands.mmoupdate.Start=[[GRAY]]Starting conversion from {0} to {1}...
|
||||||
|
Commands.mmoupdate.Finish=[[GRAY]]Database migration complete; the {1} database now has all data from the {0} database.
|
||||||
|
Commands.mmoshowdb=[[YELLOW]]The currently used database is [[GREEN]]{0}
|
||||||
Commands.ModDescription=[[RED]]- Read brief mod description
|
Commands.ModDescription=[[RED]]- Read brief mod description
|
||||||
Commands.NoConsole=This command does not support console usage.
|
Commands.NoConsole=This command does not support console usage.
|
||||||
Commands.Notifications.Off=Ability notifications toggled [[RED]]off
|
Commands.Notifications.Off=Ability notifications toggled [[RED]]off
|
||||||
@@ -505,6 +508,7 @@ Commands.Usage.0=[[RED]]Proper usage is /{0}
|
|||||||
Commands.Usage.1=[[RED]]Proper usage is /{0} {1}
|
Commands.Usage.1=[[RED]]Proper usage is /{0} {1}
|
||||||
Commands.Usage.2=[[RED]]Proper usage is /{0} {1} {2}
|
Commands.Usage.2=[[RED]]Proper usage is /{0} {1} {2}
|
||||||
Commands.Usage.3=[[RED]]Proper usage is /{0} {1} {2} {3}
|
Commands.Usage.3=[[RED]]Proper usage is /{0} {1} {2} {3}
|
||||||
|
Commands.Usage.FullClassName=classname
|
||||||
Commands.Usage.Level=level
|
Commands.Usage.Level=level
|
||||||
Commands.Usage.Message=message
|
Commands.Usage.Message=message
|
||||||
Commands.Usage.Page=page
|
Commands.Usage.Page=page
|
||||||
@@ -751,7 +755,8 @@ Commands.Description.mcremove=Remove a user from the mcMMO database
|
|||||||
Commands.Description.mcstats=Show your mcMMO levels and XP
|
Commands.Description.mcstats=Show your mcMMO levels and XP
|
||||||
Commands.Description.mctop=Show mcMMO leader boards
|
Commands.Description.mctop=Show mcMMO leader boards
|
||||||
Commands.Description.mmoedit=Edit mcMMO levels for a user
|
Commands.Description.mmoedit=Edit mcMMO levels for a user
|
||||||
Commands.Description.mmoupdate=Convert mcMMO database from Flatfile to MySQL
|
Commands.Description.mmoupdate=Migrate mcMMO database from an old database into the current one
|
||||||
|
Commands.Description.mmoshowdb=Show the name of the current database type (for later use with /mmoupdate)
|
||||||
Commands.Description.party=Control various mcMMO party settings
|
Commands.Description.party=Control various mcMMO party settings
|
||||||
Commands.Description.partychat=Toggle mcMMO party chat on/off or send party chat messages
|
Commands.Description.partychat=Toggle mcMMO party chat on/off or send party chat messages
|
||||||
Commands.Description.ptp=Teleport to an mcMMO party member
|
Commands.Description.ptp=Teleport to an mcMMO party member
|
||||||
@@ -764,3 +769,14 @@ Commands.Description.xprate=Modify the mcMMO XP rate or start an mcMMO XP event
|
|||||||
#UPDATE CHECKER
|
#UPDATE CHECKER
|
||||||
UpdateChecker.outdated=You are using an outdated version of mcMMO!
|
UpdateChecker.outdated=You are using an outdated version of mcMMO!
|
||||||
UpdateChecker.newavailable=There is a new version available on BukkitDev.
|
UpdateChecker.newavailable=There is a new version available on BukkitDev.
|
||||||
|
|
||||||
|
#SCOREBOARD HEADERS
|
||||||
|
Scoreboard.Header.PlayerStats=mcMMO Stats
|
||||||
|
Scoreboard.Header.PlayerRank=mcMMO Rankings
|
||||||
|
Scoreboard.Header.PlayerInspect=mcMMO Stats:
|
||||||
|
Scoreboard.Header.PowerLevel=Power Level
|
||||||
|
Scoreboard.Misc.PowerLevel=Power Level
|
||||||
|
Scoreboard.Misc.Level=Level
|
||||||
|
Scoreboard.Misc.CurrentXP=Current XP
|
||||||
|
Scoreboard.Misc.RemainingXP=Remaining XP
|
||||||
|
Scoreboard.Misc.Overall=Overall
|
||||||
|
|||||||
@@ -58,7 +58,9 @@ commands:
|
|||||||
inspect:
|
inspect:
|
||||||
description: View detailed mcMMO info on another player
|
description: View detailed mcMMO info on another player
|
||||||
mmoupdate:
|
mmoupdate:
|
||||||
description: Convert from Flat File to MySQL
|
description: Migrate mcMMO database from an old database type to the current
|
||||||
|
mmoshowdb:
|
||||||
|
description: Show the name of the current database type (for later use with /mmoupdate)
|
||||||
partychat:
|
partychat:
|
||||||
aliases: [pc, p]
|
aliases: [pc, p]
|
||||||
description: Toggle Party chat or send party chat messages
|
description: Toggle Party chat or send party chat messages
|
||||||
@@ -612,6 +614,7 @@ permissions:
|
|||||||
mcmmo.bypass.hardcoremode: true
|
mcmmo.bypass.hardcoremode: true
|
||||||
mcmmo.bypass.kraken: true
|
mcmmo.bypass.kraken: true
|
||||||
mcmmo.commands.inspect.far: true
|
mcmmo.commands.inspect.far: true
|
||||||
|
mcmmo.commands.inspect.hidden: true
|
||||||
mcmmo.commands.inspect.offline: true
|
mcmmo.commands.inspect.offline: true
|
||||||
mcmmo.bypass.arcanebypass:
|
mcmmo.bypass.arcanebypass:
|
||||||
default: false
|
default: false
|
||||||
@@ -701,6 +704,7 @@ permissions:
|
|||||||
mcmmo.commands.defaults: true
|
mcmmo.commands.defaults: true
|
||||||
mcmmo.commands.hardcore.all: true
|
mcmmo.commands.hardcore.all: true
|
||||||
mcmmo.commands.inspect.far: true
|
mcmmo.commands.inspect.far: true
|
||||||
|
mcmmo.commands.inspect.hidden: true
|
||||||
mcmmo.commands.inspect.offline: true
|
mcmmo.commands.inspect.offline: true
|
||||||
mcmmo.commands.kraken: true
|
mcmmo.commands.kraken: true
|
||||||
mcmmo.commands.kraken.others: true
|
mcmmo.commands.kraken.others: true
|
||||||
@@ -715,6 +719,7 @@ permissions:
|
|||||||
mcmmo.commands.mmoedit: true
|
mcmmo.commands.mmoedit: true
|
||||||
mcmmo.commands.mmoedit.others: true
|
mcmmo.commands.mmoedit.others: true
|
||||||
mcmmo.commands.mmoupdate: true
|
mcmmo.commands.mmoupdate: true
|
||||||
|
mcmmo.commands.mmoshowdb: true
|
||||||
mcmmo.commands.ptp.world.all: true
|
mcmmo.commands.ptp.world.all: true
|
||||||
mcmmo.commands.skillreset.all: true
|
mcmmo.commands.skillreset.all: true
|
||||||
mcmmo.commands.vampirism.all: true
|
mcmmo.commands.vampirism.all: true
|
||||||
@@ -772,11 +777,14 @@ permissions:
|
|||||||
children:
|
children:
|
||||||
mcmmo.commands.inspect: true
|
mcmmo.commands.inspect: true
|
||||||
mcmmo.commands.inspect.far: true
|
mcmmo.commands.inspect.far: true
|
||||||
|
mcmmo.commands.inspect.hidden: true
|
||||||
mcmmo.commands.inspect.offline: true
|
mcmmo.commands.inspect.offline: true
|
||||||
mcmmo.commands.inspect:
|
mcmmo.commands.inspect:
|
||||||
description: Allows access to the inspect command
|
description: Allows access to the inspect command
|
||||||
mcmmo.commands.inspect.far:
|
mcmmo.commands.inspect.far:
|
||||||
description: Allows access to the inspect command for far players
|
description: Allows access to the inspect command for far players
|
||||||
|
mcmmo.commands.inspect.hidden:
|
||||||
|
description: Allows access to the inspect command for hidden players
|
||||||
mcmmo.commands.inspect.offline:
|
mcmmo.commands.inspect.offline:
|
||||||
description: Allows access to the inspect command for offline players
|
description: Allows access to the inspect command for offline players
|
||||||
mcmmo.commands.kraken:
|
mcmmo.commands.kraken:
|
||||||
@@ -903,6 +911,8 @@ permissions:
|
|||||||
description: Allows access to the mmoedit command for other players
|
description: Allows access to the mmoedit command for other players
|
||||||
mcmmo.commands.mmoupdate:
|
mcmmo.commands.mmoupdate:
|
||||||
description: Allows access to the mmoupdate command
|
description: Allows access to the mmoupdate command
|
||||||
|
mcmmo.commands.mmoshowdb:
|
||||||
|
description: Allows access to the mmoshowdb command
|
||||||
mcmmo.commands.mobhealth:
|
mcmmo.commands.mobhealth:
|
||||||
default: true
|
default: true
|
||||||
description: Allows access to the mobhealth command
|
description: Allows access to the mobhealth command
|
||||||
|
|||||||
Reference in New Issue
Block a user