1
0
mirror of https://github.com/mcMMO-Dev/mcMMO.git synced 2026-02-21 19:22:59 +01:00

Compare commits

...

132 Commits

Author SHA1 Message Date
nossr50
3934392219 Did somebody say HOTFIX? 2012-08-14 13:52:31 -07:00
nossr50
ed6f48b5fe Merge pull request #215 from btarb24/master
Player command to reset a skill level (for when cap is enabled)
2012-08-09 13:10:44 -07:00
nossr50
729e4a6eac Fixed some deprecated things, removed some unneeded imports. 2012-08-07 17:41:13 -07:00
nossr50
9a39dead4f Forgot an import. 2012-08-07 17:38:28 -07:00
nossr50
cb1eabc3fa 1.3.10 release soon, added 1.3.1 compatibility 2012-08-07 16:49:25 -07:00
nossr50
b30002948c Fix for COTW and a fix for stat wipes w/ offline mode off for FlatFile 2012-08-04 15:21:34 -07:00
Bill Tarbell
d528f11082 Allow global multiplier to be a double 2012-08-01 19:32:25 -04:00
GJ
42a1fdf2df Removed deprecated function in 1.2.5-R5 2012-07-31 09:06:23 -04:00
Bill Tarbell
394ddd4e51 copy paste error. 2012-07-30 00:02:41 -04:00
Bill Tarbell
8c7d95f9ea Add player command to reset skill levels 2012-07-29 23:49:42 -04:00
Bill Tarbell
422550abfd Display power level cap on mcstats command 2012-07-29 20:05:05 -04:00
GJ
ca9ce1ba1b Fixed possible ClassCastException from catching something other than a
mob when using the Shake Mob skill
2012-07-21 09:37:17 -04:00
nossr50
ac1c420cb5 Ryokai! 2012-07-13 10:01:51 -07:00
GJ
05a9e85529 No reason to pull the ArrayLists every time. 2012-07-10 14:52:43 -04:00
GJ
ca6ed76e8f Log when someone's missing from a table. 2012-07-10 14:43:48 -04:00
GJ
3d04da39e3 Null check our DB tables. 2012-07-10 14:38:51 -04:00
GJ
127908f104 Save the tablePrefix as a String. 2012-07-10 14:32:56 -04:00
GJ
686bcd5308 Null check ALL the profiles.
We should probably find a more elegant way to do this, though.
2012-07-10 14:02:48 -04:00
GJ
07c66378c0 Some optimizations to how we handle our SQL connections and queries. 2012-07-10 12:04:18 -04:00
GJ
4e7107c8a8 Remove unused variable 2012-07-09 11:12:58 -04:00
GJ
3c2d658b37 Protect our database. 2012-07-09 11:12:46 -04:00
GJ
f0b2cc1bab Protect our file paths. 2012-07-09 10:55:33 -04:00
GJ
d038cbf357 Bad variables names are bad. 2012-07-09 10:47:33 -04:00
GJ
c3ea632cb9 This should be private. 2012-07-09 10:46:55 -04:00
GJ
a31d50924d Only create objects where we need them. 2012-07-09 10:43:16 -04:00
GJ
c567e2714a Fixed custom woodcutting blocks throwing errors. 2012-07-09 09:26:22 -04:00
bm01
a2e342b4fc Oops 2012-07-08 00:17:33 +02:00
bm01
4469637f27 NPE prevention for Users.getProfile() 2012-07-08 00:02:40 +02:00
bm01
f4ecbe7f65 Removed unused import 2012-07-07 23:48:36 +02:00
bm01
dbaab4efe1 Don't call SpoutStuff if Spout isn't enabled 2012-07-07 23:48:22 +02:00
bm01
8c178869b7 Fixed /mcremove 2012-07-07 23:38:05 +02:00
NuclearW
3c7bcb990e NPE Prevention 2012-07-07 17:02:33 -04:00
NuclearW
f7a5678814 Change ChunkletManager to a notify/demand system
Allowing NullChunkletManager to bypass the ChunkletUnloader as it is not needed.
2012-07-07 14:43:14 -04:00
NuclearW
646bb32965 Let the Unit testing begin
Could use some more test cases on the make test, though
2012-07-07 14:43:14 -04:00
NuclearW
dce7d8fdd3 Format this before GJ finds out 2012-07-07 14:43:14 -04:00
NuclearW
6dd17312f4 Change this back to private 2012-07-07 14:43:14 -04:00
NuclearW
9c64f40ea1 Changelog 2012-07-07 14:43:13 -04:00
NuclearW
da6b461408 Move our Externalizeable to PrimitveExChunkletStore
This will let us deserialize Primitive normally.

In addition, we now enforce all chunklets being of type PrimitiveEx, as any non-Ex are repalced with a new Ex on load.
2012-07-07 14:43:13 -04:00
NuclearW
77dce75108 Formatting a single line 2012-07-07 14:43:13 -04:00
NuclearW
37308917d1 Parenthesis for clarity 2012-07-07 14:43:13 -04:00
NuclearW
21d2229572 Column comment 2012-07-07 14:43:13 -04:00
NuclearW
7d372af51e Some address byte comments 2012-07-07 14:43:12 -04:00
NuclearW
a3e0753076 We must be sure to flush 2012-07-07 14:43:12 -04:00
NuclearW
a728d1f9c8 These must be called in the reverse order we open them 2012-07-07 14:43:12 -04:00
NuclearW
b893e86f3c A bit more clear
But no functional change
2012-07-07 14:43:12 -04:00
NuclearW
63cf6e9b3a Do not increment i in this location 2012-07-07 14:43:12 -04:00
NuclearW
67738d811e Move things around to fit together better 2012-07-07 14:43:12 -04:00
bm01
4d77f6d04d Introducing external chunklets 2012-07-07 14:43:11 -04:00
bm01
3702495038 Don't need to .save() for online players 2012-07-07 20:02:54 +02:00
bm01
ede08ce5ac Moved hudType back to PlayerProfile
Removed some convenient methods from PlayerProfile to avoid NPE because of
spoutHud
2012-07-07 19:59:10 +02:00
bm01
5571e0bc0c Arranged InspectCommand 2012-07-07 19:39:22 +02:00
bm01
73bb73c8ca Fixed /mmoedit 2012-07-07 19:35:32 +02:00
bm01
54011fdeb7 Removed unused OfflinePlayer from PlayerProfile 2012-07-07 19:27:47 +02:00
GJ
5b8811bd09 More work on McMMOPlayer 2012-07-06 11:57:17 -04:00
GJ
c460eec0ab Oops. 2012-07-06 09:30:30 -04:00
GJ
bc6233541a Start changing PlayerProfile to use an OfflinePlayer 2012-07-06 09:14:25 -04:00
bm01
18aef9d526 Typo 2012-07-06 07:13:52 +02:00
bm01
ccc6fd30f8 Fixed /inspect not working on offline player 2012-07-06 07:07:29 +02:00
GJ
1ba498c443 Because "final static" is just backwards. 2012-07-06 00:12:17 -04:00
GJ
64f31f2b5a Fixed issue with JSON API plugin & player chat events 2012-07-05 11:25:36 -04:00
GJ
b94085c5f4 Make 'em final 2012-07-05 09:33:57 -04:00
GJ
62b90ad552 Using .equals() is better 2012-07-05 09:25:48 -04:00
GJ
d6d1e0ffed More efficient handling of Party/Admin chat messages 2012-07-05 09:21:07 -04:00
GJ
ccd103cd88 More efficient iteration. 2012-07-05 09:11:40 -04:00
GJ
0606f16a11 pm is lazy too. 2012-07-04 15:38:26 -04:00
GJ
c9e3ea005b Because loc is lazy. 2012-07-04 15:38:25 -04:00
bm01
f009f5803f Changelog update 2012-07-04 20:24:34 +02:00
GJ
3f8268d848 Fixed custom blocks dropping the wrong thing with Super Breaker & Silk
Touch
2012-07-04 10:33:20 -04:00
GJ
cefec723d0 Javadoc typo 2012-07-04 10:12:10 -04:00
GJ
124aa72fd9 Better file handling 2012-07-04 10:00:11 -04:00
GJ
dbc7277ba9 FileWriter is pointless here. 2012-07-04 09:45:47 -04:00
GJ
24d8769b5b Remove useless FileWriter 2012-07-03 21:23:32 -04:00
GJ
4aecb9756e Improve file handling. 2012-07-03 21:21:32 -04:00
bm01
51ca29ab9f Forgot to loadKeys() 2012-07-03 23:29:26 +02:00
bm01
c6e5264b7b Print the stack trace for easier debugging 2012-07-03 23:28:58 +02:00
bm01
73203ce869 Removed unneeded method call 2012-07-03 22:05:47 +02:00
bm01
b80a29ca04 Configs rework, fixed mod config files not loading, fixed comment blocks not being copied 2012-07-03 21:57:46 +02:00
GJ
5ee440d9a5 Ensure that our stuff gets closed when working with Chunklets. 2012-07-03 15:10:35 -04:00
GJ
cda3675dc5 More bad variable names. 2012-07-03 10:14:01 -04:00
GJ
caf9c07ba3 Because PP is an awful variable name. 2012-07-03 10:04:04 -04:00
GJ
96e70aa4d2 Fixed "lower tool" messages still being displayed even when ability
messages are disabled.
2012-07-03 08:40:56 -04:00
GJ
9f1b77a007 Refactoring 2012-07-03 08:36:21 -04:00
GJ
946b5bb006 Added null checks to BlockBreak & BlockDamage events to help with mod
compatibility.
2012-07-03 07:59:36 -04:00
bm01
bebcc40987 Added missing annotations 2012-07-03 03:55:19 +02:00
bm01
d6d7f5099f Removed unused import 2012-07-03 03:54:20 +02:00
bm01
bdcc2f644b Removed unneeded instanceof 2012-07-03 03:53:51 +02:00
bm01
c3ba54a0ce Removed unneeded cast 2012-07-03 03:53:11 +02:00
bm01
1443e2f6b8 Removed unneeded null check, according to eclipse :3 2012-07-03 03:52:12 +02:00
bm01
7799acec05 Oops 2012-07-03 03:40:12 +02:00
bm01
1bbc1f28aa TrackedEntity.java cleanup 2012-07-03 03:37:11 +02:00
GJ
8257fd8e7c Tweaked a few switch statements. 2012-07-02 21:05:55 -04:00
GJ
bc58aff362 Fixed resource leak from never closing the JarFile. 2012-07-02 20:44:54 -04:00
GJ
1073954550 Lucky perk is actually a 33.3% boost. 2012-07-02 20:17:48 -04:00
GJ
c3d7a4e3de Fixed "lucky" perk making downgrades from repair more likely. 2012-07-02 19:56:48 -04:00
GJ
92ae92c116 Fixed children nodes of "lucky" perk not being set to true. 2012-07-02 19:46:47 -04:00
GJ
3c10be6d1a Added some missing defaults to switch cases. 2012-07-02 19:27:07 -04:00
bm01
f18a9bdcc7 Fixed duplication bug with sticky pistons 2012-07-02 23:54:05 +02:00
bm01
87f59cd3eb Fixed the possibility to use some abilities without the proper tool 2012-07-02 21:30:19 +02:00
GJ
819b6fcacb Added "lucky" donor perk - abilities have 25% better chance to activate 2012-07-02 11:09:55 -04:00
bm01
246961887e Build test 2012-07-01 13:09:34 +02:00
bm01
54e21333a3 Reworked some Spout stuff
among other things
2012-07-01 12:54:11 +02:00
bm01
c45beec59d Fixed repair enchant downgrade 2012-07-01 00:04:53 +02:00
bm01
c88ada489a Chunklets optimization 2012-06-30 02:38:22 +02:00
GJ
189f23f407 Fixed custom tools not handling the Ability_Enabled flag properly. 2012-06-28 11:20:53 -04:00
GJ
9789143c6d Check if player is online for EntityDamage events too. 2012-06-28 10:22:00 -04:00
GJ
f4dd7ff483 Fixed ClassDef error that prevented the server from loading unless
Spout was installed.
2012-06-28 10:03:22 -04:00
GJ
50e05c6320 Minor refactoring 2012-06-28 09:01:02 -04:00
GJ
9ba5360bfc Cleaned up inSameParty method 2012-06-28 08:14:49 -04:00
GJ
565ef693ce Fix issue with EntityDamageByEntityEvents & Offline Players 2012-06-28 08:14:49 -04:00
bm01
0c1a8eff85 Fixed NPE caused by Spout players after a /reload 2012-06-28 06:51:13 +02:00
GJ
32e9de6e9a Fix for NPE on party checks due to CombatTag plugin. 2012-06-27 23:51:18 -04:00
bm01
533955a9c7 Removed redundant calls 2012-06-28 05:35:56 +02:00
bm01
2faa0356a5 It's better that way 2012-06-27 20:46:45 +02:00
GJ
ee2a5c199a Added functionality to specify custom blocks that should not trigger
abilities.
2012-06-27 14:46:44 -04:00
bm01
bdcc522897 Fixed ConcurrentModificationException on world unload 2012-06-27 20:39:54 +02:00
GJ
71b20bdeaa Fixed ArrayIndexOutOfBounds error 2012-06-27 11:18:04 -04:00
GJ
0e85b4776a Add more XP boost permissions nodes. 2012-06-27 08:31:10 -04:00
GJ
24d2c1bc7a Fix for UTFDataFormatException 2012-06-26 14:58:51 -04:00
GJ
1610e932c6 Removed some debug code that got left in... 2012-06-26 13:23:56 -04:00
GJ
31d7bb2332 Javadoc fix 2012-06-26 08:03:19 -04:00
GJ
3d9c03c0c8 Added a few requested functions to the ExperienceAPI 2012-06-26 08:02:49 -04:00
bm01
dd94343d92 One more fix to admin chat 2012-06-25 21:35:38 +02:00
GJ
4b93dede33 Add ability to check if any ability is enabled. 2012-06-25 10:35:47 -04:00
GJ
61205989cc Cleanup cooldown monitoring a bit. 2012-06-25 10:29:29 -04:00
GJ
2559ea61d8 Added Ability API 2012-06-25 10:05:47 -04:00
GJ
eae665c1c5 Added ability for custom blocks to drop a range of items. MOD BLOCK
FILES WILL NEED TO BE REDONE.
2012-06-25 09:47:22 -04:00
bm01
d73521e0a0 Fixed admin chat being seen by everyone 2012-06-25 15:05:20 +02:00
GJ
e8deb0384a Fix Iron Grip calculations using incorrect values. 2012-06-25 08:54:05 -04:00
GJ
881f2c023e Added permission node for Iron Grip 2012-06-25 08:54:05 -04:00
bm01
5057a8a7a3 Fixed memory leak in ProfileSaveTask 2012-06-25 14:38:07 +02:00
bm01
b8e9269488 Made things cleaner 2012-06-25 14:37:18 +02:00
GJ
76afd5a7ca Back to new development. 2012-06-25 08:29:58 -04:00
115 changed files with 3318 additions and 2038 deletions

View File

@@ -7,6 +7,36 @@ Key:
! Change
- Removal
Version 1.3.11
= Fixed bug where mcMMO would ignore other block-protection plugins for various abilities
Version 1.3.10
+ Added 1.3.1 compatibility
+ Added permission node for Iron Grip ability (mcmmo.ability.unarmed.irongrip)
+ Added ability for custom blocks to drop a range of items.
+ Added Ability API functions
+ Added 50% & 150% XP boost perks
+ Added "lucky" perk for donors
= Fixed /inspect not working on offline players
= Fixed custom blocks, tools and armors not loading properly
= Fixed duplication bug with sticky pistons
= Fixed "GenericLabel belonging to mcMMO..." message
= Fixed menu exit button not working
= Fixed Repair enchant downgrade not working
= Fixed NPE caused by Spout players after a /reload
= Fixed ConcurrentModificationException on world unload
= Fixed players never being removed from memory (memory leak)
= Fixed admin chat being seen by everyone
= Fixed issue with UTFDataFormatException occurring on occasion when trying to load Chunklets
= Fixed ArrayIndexOutOfBounds error caused when trying to use /xplock after logging in but before gaining XP
= Fixed custom tools not properly respecting the Ability_Enabled flag.
= Fixed "lower tool" messages still being displayed even when ability messages are disabled.
= Fixed custom blocks not dropping the proper item with Super Breaker when Silk Touch is used
= Fixed custom woodcutting blocks throwing errors.
= Fixed possible ClassCastException from catching something other than a mob when using the Shake Mob skill
! Changed the format by which Chunklets are stored to be much smaller, and much faster to load
! Optimized how player placed blocks are tracked
Version 1.3.09
+ Added compatibility with AntiCheat (Which I highly recommend to prevent cheating)
+ Added several permission nodes to give individual users special perks (Double/Triple/Quadruple XP)

View File

@@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.gmail.nossr50.mcMMO</groupId>
<artifactId>mcMMO</artifactId>
<version>1.3.09</version>
<version>1.3.11</version>
<name>mcMMO</name>
<url>https://github.com/mcMMO-Dev/mcMMO</url>
<issueManagement>
@@ -128,6 +128,12 @@
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit-dep</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View File

@@ -0,0 +1,47 @@
package com.gmail.nossr50.api;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.AbilityType;
import com.gmail.nossr50.util.Users;
public class AbilityAPI {
public static boolean berserkEnabled(Player player) {
return Users.getProfile(player).getAbilityMode(AbilityType.BERSERK);
}
public static boolean gigaDrillBreakerEnabled(Player player) {
return Users.getProfile(player).getAbilityMode(AbilityType.GIGA_DRILL_BREAKER);
}
public static boolean greenTerraEnabled(Player player) {
return Users.getProfile(player).getAbilityMode(AbilityType.GREEN_TERRA);
}
public static boolean serratedStrikesEnabled(Player player) {
return Users.getProfile(player).getAbilityMode(AbilityType.SERRATED_STRIKES);
}
public static boolean skullSplitterEnabled(Player player) {
return Users.getProfile(player).getAbilityMode(AbilityType.SKULL_SPLIITER);
}
public static boolean superBreakerEnabled(Player player) {
return Users.getProfile(player).getAbilityMode(AbilityType.SUPER_BREAKER);
}
public static boolean treeFellerEnabled(Player player) {
return Users.getProfile(player).getAbilityMode(AbilityType.TREE_FELLER);
}
public static boolean isAnyAbilityEnabled(Player player) {
for (AbilityType ability : AbilityType.values()) {
if (Users.getProfile(player).getAbilityMode(ability)) {
return true;
}
}
return false;
}
}

View File

@@ -35,7 +35,7 @@ public final class ExperienceAPI {
* @param XP The amount of XP to add
*/
public static void addRawXP(Player player, SkillType skillType, int XP) {
Users.getProfile(player).addXPOverride(skillType, XP);
Users.getPlayer(player).addXPOverride(skillType, XP);
checkXP(player, skillType);
}
@@ -49,7 +49,7 @@ public final class ExperienceAPI {
* @param XP The amount of XP to add
*/
public static void addMultipliedXP(Player player, SkillType skillType, int XP) {
Users.getProfile(player).addXPOverrideBonus(skillType, XP);
Users.getPlayer(player).addXPOverrideBonus(skillType, XP);
checkXP(player, skillType);
}
@@ -63,7 +63,7 @@ public final class ExperienceAPI {
* @param XP The amount of XP to add
*/
public static void addXP(Player player, SkillType skillType, int XP) {
Users.getProfile(player).addXP(skillType, XP);
Users.getPlayer(player).addXP(skillType, XP);
checkXP(player, skillType);
}
@@ -133,6 +133,45 @@ public final class ExperienceAPI {
* @return the power level of the player
*/
public static int getPowerLevel(Player player) {
return Users.getProfile(player).getPowerLevel();
return Users.getPlayer(player).getPowerLevel();
}
/**
* Sets the level of a player in a specific skill type.
* </br>
* This function is designed for API usage.
*
* @param player The player to set the level of
* @param skillType The skill to set the level for
* @param skillLevel The value to set the level to
*/
public static void setLevel(Player player, SkillType skillType, int skillLevel) {
Users.getProfile(player).modifySkill(skillType, skillLevel);
}
/**
* Sets the XP of a player in a specific skill type.
* </br>
* This function is designed for API usage.
*
* @param player The player to set the XP of
* @param skillType The skill to set the XP for
* @param newValue The value to set the XP to
*/
public static void setXP(Player player, SkillType skillType, int newValue) {
Users.getProfile(player).setSkillXPLevel(skillType, newValue);
}
/**
* Removes XP from a player in a specific skill type.
* </br>
* This function is designed for API usage.
*
* @param player The player to change the XP of
* @param skillType The skill to change the XP for
* @param xp The amount of XP to remove
*/
public static void removeXP(Player player, SkillType skillType, int xp) {
Users.getProfile(player).removeXP(skillType, xp);
}
}

View File

@@ -11,11 +11,11 @@ public final class SpoutToolsAPI {
private SpoutToolsAPI() {}
public static List<ItemStack> spoutSwords = new ArrayList<ItemStack>();
public static List<ItemStack> spoutAxes = new ArrayList<ItemStack>();
public static List<ItemStack> spoutPickaxes = new ArrayList<ItemStack>();
public static List<ItemStack> spoutHoes = new ArrayList<ItemStack>();
public static List<ItemStack> spoutShovels = new ArrayList<ItemStack>();
public static final List<ItemStack> spoutSwords = new ArrayList<ItemStack>();
public static final List<ItemStack> spoutAxes = new ArrayList<ItemStack>();
public static final List<ItemStack> spoutPickaxes = new ArrayList<ItemStack>();
public static final List<ItemStack> spoutHoes = new ArrayList<ItemStack>();
public static final List<ItemStack> spoutShovels = new ArrayList<ItemStack>();
/**
* Add a custom Spout tool to mcMMO for XP gain & ability use.

View File

@@ -23,7 +23,7 @@ public class CommandHelper {
if (sender instanceof Player) {
Player player = (Player) sender;
if (player != null && !Permissions.getInstance().permission(player, permission)) {
if (!Permissions.getInstance().permission(player, permission)) {
player.sendMessage(LocaleLoader.getString("mcMMO.NoPermission"));
return true;
}
@@ -49,28 +49,28 @@ public class CommandHelper {
*/
public static void printGatheringSkills(Player inspect, CommandSender display) {
if (Skills.hasGatheringSkills(inspect)) {
PlayerProfile PP = Users.getProfile(inspect);
PlayerProfile profile = Users.getProfile(inspect);
display.sendMessage(LocaleLoader.getString("Stats.Header.Gathering"));
if (Permissions.getInstance().excavation(inspect)) {
display.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Excavation.Listener"), PP.getSkillLevel(SkillType.EXCAVATION), PP.getSkillXpLevel(SkillType.EXCAVATION), PP.getXpToLevel(SkillType.EXCAVATION) }));
display.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Excavation.Listener"), profile.getSkillLevel(SkillType.EXCAVATION), profile.getSkillXpLevel(SkillType.EXCAVATION), profile.getXpToLevel(SkillType.EXCAVATION) }));
}
if (Permissions.getInstance().fishing(inspect)) {
display.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Fishing.Listener"), PP.getSkillLevel(SkillType.FISHING), PP.getSkillXpLevel(SkillType.FISHING), PP.getXpToLevel(SkillType.FISHING) }));
display.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Fishing.Listener"), profile.getSkillLevel(SkillType.FISHING), profile.getSkillXpLevel(SkillType.FISHING), profile.getXpToLevel(SkillType.FISHING) }));
}
if (Permissions.getInstance().herbalism(inspect)) {
display.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Herbalism.Listener"), PP.getSkillLevel(SkillType.HERBALISM), PP.getSkillXpLevel(SkillType.HERBALISM), PP.getXpToLevel(SkillType.HERBALISM) }));
display.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Herbalism.Listener"), profile.getSkillLevel(SkillType.HERBALISM), profile.getSkillXpLevel(SkillType.HERBALISM), profile.getXpToLevel(SkillType.HERBALISM) }));
}
if (Permissions.getInstance().mining(inspect)) {
display.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Mining.Listener"), PP.getSkillLevel(SkillType.MINING), PP.getSkillXpLevel(SkillType.MINING), PP.getXpToLevel(SkillType.MINING) }));
display.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Mining.Listener"), profile.getSkillLevel(SkillType.MINING), profile.getSkillXpLevel(SkillType.MINING), profile.getXpToLevel(SkillType.MINING) }));
}
if (Permissions.getInstance().woodcutting(inspect)) {
display.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Woodcutting.Listener"), PP.getSkillLevel(SkillType.WOODCUTTING), PP.getSkillXpLevel(SkillType.WOODCUTTING), PP.getXpToLevel(SkillType.WOODCUTTING) }));
display.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Woodcutting.Listener"), profile.getSkillLevel(SkillType.WOODCUTTING), profile.getSkillXpLevel(SkillType.WOODCUTTING), profile.getXpToLevel(SkillType.WOODCUTTING) }));
}
}
}
@@ -87,28 +87,28 @@ public class CommandHelper {
*/
public static void printCombatSkills(Player inspect, CommandSender display) {
if (Skills.hasCombatSkills(inspect)) {
PlayerProfile PP = Users.getProfile(inspect);
PlayerProfile profile = Users.getProfile(inspect);
display.sendMessage(LocaleLoader.getString("Stats.Header.Combat"));
if (Permissions.getInstance().axes(inspect)) {
display.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Axes.Listener"), PP.getSkillLevel(SkillType.AXES), PP.getSkillXpLevel(SkillType.AXES), PP.getXpToLevel(SkillType.AXES) }));
display.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Axes.Listener"), profile.getSkillLevel(SkillType.AXES), profile.getSkillXpLevel(SkillType.AXES), profile.getXpToLevel(SkillType.AXES) }));
}
if (Permissions.getInstance().archery(inspect)) {
display.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Archery.Listener"), PP.getSkillLevel(SkillType.ARCHERY), PP.getSkillXpLevel(SkillType.ARCHERY), PP.getXpToLevel(SkillType.ARCHERY) }));
display.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Archery.Listener"), profile.getSkillLevel(SkillType.ARCHERY), profile.getSkillXpLevel(SkillType.ARCHERY), profile.getXpToLevel(SkillType.ARCHERY) }));
}
if (Permissions.getInstance().swords(inspect)) {
display.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Swords.Listener"), PP.getSkillLevel(SkillType.SWORDS), PP.getSkillXpLevel(SkillType.SWORDS), PP.getXpToLevel(SkillType.SWORDS) }));
display.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Swords.Listener"), profile.getSkillLevel(SkillType.SWORDS), profile.getSkillXpLevel(SkillType.SWORDS), profile.getXpToLevel(SkillType.SWORDS) }));
}
if (Permissions.getInstance().taming(inspect)) {
display.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Taming.Listener"), PP.getSkillLevel(SkillType.TAMING), PP.getSkillXpLevel(SkillType.TAMING), PP.getXpToLevel(SkillType.TAMING) }));
display.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Taming.Listener"), profile.getSkillLevel(SkillType.TAMING), profile.getSkillXpLevel(SkillType.TAMING), profile.getXpToLevel(SkillType.TAMING) }));
}
if (Permissions.getInstance().unarmed(inspect)) {
display.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Unarmed.Listener"), PP.getSkillLevel(SkillType.UNARMED), PP.getSkillXpLevel(SkillType.UNARMED), PP.getXpToLevel(SkillType.UNARMED) }));
display.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Unarmed.Listener"), profile.getSkillLevel(SkillType.UNARMED), profile.getSkillXpLevel(SkillType.UNARMED), profile.getXpToLevel(SkillType.UNARMED) }));
}
}
}
@@ -125,15 +125,15 @@ public class CommandHelper {
*/
public static void printMiscSkills(Player inspect, CommandSender display) {
if (Skills.hasMiscSkills(inspect)) {
PlayerProfile PP = Users.getProfile(inspect);
PlayerProfile profile = Users.getProfile(inspect);
display.sendMessage(LocaleLoader.getString("Stats.Header.Misc"));
if (Permissions.getInstance().acrobatics(inspect)) {
display.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Acrobatics.Listener"), PP.getSkillLevel(SkillType.ACROBATICS), PP.getSkillXpLevel(SkillType.ACROBATICS), PP.getXpToLevel(SkillType.ACROBATICS) }));
display.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Acrobatics.Listener"), profile.getSkillLevel(SkillType.ACROBATICS), profile.getSkillXpLevel(SkillType.ACROBATICS), profile.getXpToLevel(SkillType.ACROBATICS) }));
}
if (Permissions.getInstance().repair(inspect)) {
display.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Repair.Listener"), PP.getSkillLevel(SkillType.REPAIR), PP.getSkillXpLevel(SkillType.REPAIR), PP.getXpToLevel(SkillType.REPAIR) }));
display.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Repair.Listener"), profile.getSkillLevel(SkillType.REPAIR), profile.getSkillXpLevel(SkillType.REPAIR), profile.getXpToLevel(SkillType.REPAIR) }));
}
}
}

View File

@@ -26,7 +26,7 @@ public class AddlevelsCommand implements CommandExecutor{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
OfflinePlayer modifiedPlayer;
PlayerProfile PP;
PlayerProfile profile;
int levels;
SkillType skill;
String skillName;
@@ -48,7 +48,7 @@ public class AddlevelsCommand implements CommandExecutor{
modifiedPlayer = (Player) sender;
levels = Integer.valueOf(args[1]);
skill = Skills.getSkillType(args[0]);
PP = Users.getProfile(modifiedPlayer);
profile = Users.getProfile(modifiedPlayer);
if (skill.equals(SkillType.ALL)) {
skillName = "all skills";
@@ -57,7 +57,7 @@ public class AddlevelsCommand implements CommandExecutor{
skillName = Misc.getCapitalized(skill.toString());
}
PP.addLevels(skill, levels);
profile.addLevels(skill, levels);
sender.sendMessage(ChatColor.GREEN + "You were awarded " + levels + " levels in " + skillName + "!"); //TODO: Needs more locale.
}
}
@@ -70,9 +70,9 @@ public class AddlevelsCommand implements CommandExecutor{
case 3:
modifiedPlayer = plugin.getServer().getOfflinePlayer(args[0]);
String playerName = modifiedPlayer.getName();
PP = Users.getProfile(modifiedPlayer);
profile = Users.getProfile(modifiedPlayer);
if (!PP.isLoaded()) {
if (!profile.isLoaded()) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}

View File

@@ -8,6 +8,7 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.locale.LocaleLoader;
@@ -49,7 +50,8 @@ public class AddxpCommand implements CommandExecutor {
skill = Skills.getSkillType(args[0]);
PlayerProfile profile = Users.getProfile(modifiedPlayer);
profile.addXPOverride(skill, xp);
McMMOPlayer mcMMOPlayer = Users.getPlayer(modifiedPlayer);
mcMMOPlayer.addXPOverride(skill, xp);
if (skill.equals(SkillType.ALL)) {
skillName = "all skills";
@@ -80,6 +82,7 @@ public class AddxpCommand implements CommandExecutor {
case 3:
modifiedPlayer = plugin.getServer().getPlayer(args[0]);
String playerName = modifiedPlayer.getName();
McMMOPlayer mcMMOPlayer = Users.getPlayer(modifiedPlayer);
PlayerProfile profile = Users.getProfile(modifiedPlayer);
if (!profile.isLoaded()) {
@@ -97,7 +100,7 @@ public class AddxpCommand implements CommandExecutor {
skill = Skills.getSkillType(args[1]);
String message;
profile.addXPOverride(skill, xp);
mcMMOPlayer.addXPOverride(skill, xp);
if (skill.equals(SkillType.ALL)) {
skillName = "all skills";

View File

@@ -1,13 +1,12 @@
package com.gmail.nossr50.commands.general;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.locale.LocaleLoader;
@@ -16,16 +15,8 @@ import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users;
public class InspectCommand implements CommandExecutor {
private final mcMMO plugin;
public InspectCommand (mcMMO plugin) {
this.plugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
OfflinePlayer target;
PlayerProfile PP;
String usage = "Proper usage is /inspect <player>"; //TODO: Needs more locale.
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.inspect")) {
@@ -34,22 +25,21 @@ public class InspectCommand implements CommandExecutor {
switch (args.length) {
case 1:
target = plugin.getServer().getOfflinePlayer(args[0]);
PP = Users.getProfile(target);
McMMOPlayer mcmmoPlayer = Users.getPlayer(args[0]);
if (target.isOnline()) {
Player player = (Player) target;
if (mcmmoPlayer != null) {
Player target = mcmmoPlayer.getPlayer();
if (sender instanceof Player && !sender.isOp() && !Misc.isNear(((Player) sender).getLocation(), player.getLocation(), 5.0) && !Permissions.getInstance().inspectDistanceBypass((Player) sender)) {
if (sender instanceof Player && !sender.isOp() && !Misc.isNear(((Player) sender).getLocation(), target.getLocation(), 5.0) && !Permissions.getInstance().inspectDistanceBypass((Player) sender)) {
sender.sendMessage(LocaleLoader.getString("Inspect.TooFar"));
return true;
}
sender.sendMessage(LocaleLoader.getString("Inspect.Stats", new Object[] { target.getName() }));
CommandHelper.printGatheringSkills(player, sender);
CommandHelper.printCombatSkills(player, sender);
CommandHelper.printMiscSkills(player, sender);
sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel", new Object[] { PP.getPowerLevel() }));
CommandHelper.printGatheringSkills(target, sender);
CommandHelper.printCombatSkills(target, sender);
CommandHelper.printMiscSkills(target, sender);
sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel", new Object[] { mcmmoPlayer.getPowerLevel() }));
return true;
}
@@ -59,7 +49,9 @@ public class InspectCommand implements CommandExecutor {
return true;
}
if (!PP.isLoaded()) {
PlayerProfile profile = new PlayerProfile(args[0], false); //Temporary Profile
if (!profile.isLoaded()) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
@@ -67,22 +59,22 @@ public class InspectCommand implements CommandExecutor {
sender.sendMessage(LocaleLoader.getString("Inspect.OfflineStats", new Object[] { args[0] }));
sender.sendMessage(LocaleLoader.getString("Stats.Header.Gathering"));
sender.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Excavation.Listener"), PP.getSkillLevel(SkillType.EXCAVATION), PP.getSkillXpLevel(SkillType.EXCAVATION), PP.getXpToLevel(SkillType.EXCAVATION) }));
sender.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Fishing.Listener"), PP.getSkillLevel(SkillType.FISHING), PP.getSkillXpLevel(SkillType.FISHING), PP.getXpToLevel(SkillType.FISHING) }));
sender.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Herbalism.Listener"), PP.getSkillLevel(SkillType.HERBALISM), PP.getSkillXpLevel(SkillType.HERBALISM), PP.getXpToLevel(SkillType.HERBALISM) }));
sender.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Mining.Listener"), PP.getSkillLevel(SkillType.MINING), PP.getSkillXpLevel(SkillType.MINING), PP.getXpToLevel(SkillType.MINING) }));
sender.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Woodcutting.Listener"), PP.getSkillLevel(SkillType.WOODCUTTING), PP.getSkillXpLevel(SkillType.WOODCUTTING), PP.getXpToLevel(SkillType.WOODCUTTING) }));
sender.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Excavation.Listener"), profile.getSkillLevel(SkillType.EXCAVATION), profile.getSkillXpLevel(SkillType.EXCAVATION), profile.getXpToLevel(SkillType.EXCAVATION) }));
sender.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Fishing.Listener"), profile.getSkillLevel(SkillType.FISHING), profile.getSkillXpLevel(SkillType.FISHING), profile.getXpToLevel(SkillType.FISHING) }));
sender.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Herbalism.Listener"), profile.getSkillLevel(SkillType.HERBALISM), profile.getSkillXpLevel(SkillType.HERBALISM), profile.getXpToLevel(SkillType.HERBALISM) }));
sender.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Mining.Listener"), profile.getSkillLevel(SkillType.MINING), profile.getSkillXpLevel(SkillType.MINING), profile.getXpToLevel(SkillType.MINING) }));
sender.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Woodcutting.Listener"), profile.getSkillLevel(SkillType.WOODCUTTING), profile.getSkillXpLevel(SkillType.WOODCUTTING), profile.getXpToLevel(SkillType.WOODCUTTING) }));
sender.sendMessage(LocaleLoader.getString("Stats.Header.Combat"));
sender.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Axes.Listener"), PP.getSkillLevel(SkillType.AXES), PP.getSkillXpLevel(SkillType.AXES), PP.getXpToLevel(SkillType.AXES) }));
sender.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Archery.Listener"), PP.getSkillLevel(SkillType.ARCHERY), PP.getSkillXpLevel(SkillType.ARCHERY), PP.getXpToLevel(SkillType.ARCHERY) }));
sender.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Swords.Listener"), PP.getSkillLevel(SkillType.SWORDS), PP.getSkillXpLevel(SkillType.SWORDS), PP.getXpToLevel(SkillType.SWORDS) }));
sender.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Taming.Listener"), PP.getSkillLevel(SkillType.TAMING), PP.getSkillXpLevel(SkillType.TAMING), PP.getXpToLevel(SkillType.TAMING) }));
sender.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Unarmed.Listener"), PP.getSkillLevel(SkillType.UNARMED), PP.getSkillXpLevel(SkillType.UNARMED), PP.getXpToLevel(SkillType.UNARMED) }));
sender.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Axes.Listener"), profile.getSkillLevel(SkillType.AXES), profile.getSkillXpLevel(SkillType.AXES), profile.getXpToLevel(SkillType.AXES) }));
sender.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Archery.Listener"), profile.getSkillLevel(SkillType.ARCHERY), profile.getSkillXpLevel(SkillType.ARCHERY), profile.getXpToLevel(SkillType.ARCHERY) }));
sender.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Swords.Listener"), profile.getSkillLevel(SkillType.SWORDS), profile.getSkillXpLevel(SkillType.SWORDS), profile.getXpToLevel(SkillType.SWORDS) }));
sender.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Taming.Listener"), profile.getSkillLevel(SkillType.TAMING), profile.getSkillXpLevel(SkillType.TAMING), profile.getXpToLevel(SkillType.TAMING) }));
sender.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Unarmed.Listener"), profile.getSkillLevel(SkillType.UNARMED), profile.getSkillXpLevel(SkillType.UNARMED), profile.getXpToLevel(SkillType.UNARMED) }));
sender.sendMessage(LocaleLoader.getString("Stats.Header.Misc"));
sender.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Acrobatics.Listener"), PP.getSkillLevel(SkillType.ACROBATICS), PP.getSkillXpLevel(SkillType.ACROBATICS), PP.getXpToLevel(SkillType.ACROBATICS) }));
sender.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Repair.Listener"), PP.getSkillLevel(SkillType.REPAIR), PP.getSkillXpLevel(SkillType.REPAIR), PP.getXpToLevel(SkillType.REPAIR) }));
sender.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Acrobatics.Listener"), profile.getSkillLevel(SkillType.ACROBATICS), profile.getSkillXpLevel(SkillType.ACROBATICS), profile.getXpToLevel(SkillType.ACROBATICS) }));
sender.sendMessage(LocaleLoader.getString("Skills.Stats", new Object[] { LocaleLoader.getString("Repair.Listener"), profile.getSkillLevel(SkillType.REPAIR), profile.getSkillXpLevel(SkillType.REPAIR), profile.getXpToLevel(SkillType.REPAIR) }));
return true;
}

View File

@@ -6,7 +6,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Users;
@@ -19,7 +19,6 @@ public class McstatsCommand implements CommandExecutor {
}
Player player = (Player) sender;
PlayerProfile PP = Users.getProfile(player);
player.sendMessage(LocaleLoader.getString("Stats.Own.Stats"));
player.sendMessage(LocaleLoader.getString("mcMMO.NoSkillNote"));
@@ -27,8 +26,13 @@ public class McstatsCommand implements CommandExecutor {
CommandHelper.printGatheringSkills(player);
CommandHelper.printCombatSkills(player);
CommandHelper.printMiscSkills(player);
player.sendMessage(LocaleLoader.getString("Commands.PowerLevel", new Object[] { String.valueOf(PP.getPowerLevel()) }));
int powerLevelCap = Config.getInstance().getPowerLevelCap();
if (powerLevelCap > 0)
player.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Capped", new Object[] { String.valueOf(Users.getPlayer(player).getPowerLevel()), String.valueOf(powerLevelCap) }));
else
player.sendMessage(LocaleLoader.getString("Commands.PowerLevel", new Object[] { String.valueOf(Users.getPlayer(player).getPowerLevel()) }));
return true;
}

View File

@@ -1,13 +1,13 @@
package com.gmail.nossr50.commands.general;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.locale.LocaleLoader;
@@ -18,8 +18,7 @@ import com.gmail.nossr50.util.Users;
public class MmoeditCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
OfflinePlayer modifiedPlayer;
PlayerProfile playerProfile;
PlayerProfile profile;
int newValue;
SkillType skill;
String skillName;
@@ -38,10 +37,10 @@ public class MmoeditCommand implements CommandExecutor {
}
if (Misc.isInt(args[1])) {
modifiedPlayer = (Player) sender;
Player player = (Player) sender;
newValue = Integer.valueOf(args[1]);
skill = Skills.getSkillType(args[0]);
playerProfile = Users.getProfile(modifiedPlayer);
profile = Users.getProfile(player);
if (skill.equals(SkillType.ALL)) {
skillName = "all skills";
@@ -50,7 +49,7 @@ public class MmoeditCommand implements CommandExecutor {
skillName = Misc.getCapitalized(skill.toString());
}
playerProfile.modifySkill(skill, newValue);
profile.modifySkill(skill, newValue);
sender.sendMessage(ChatColor.GREEN + "Your level in " + skillName + " was set to " + newValue + "!"); //TODO: Needs more locale.
}
else {
@@ -84,27 +83,26 @@ public class MmoeditCommand implements CommandExecutor {
}
newValue = Integer.valueOf(args[2]);
playerProfile = Users.getProfile(args[0]);
McMMOPlayer mcmmoPlayer = Users.getPlayer(args[0]);
if (playerProfile != null) {
Player player = playerProfile.getPlayer();
if (mcmmoPlayer != null) {
profile = mcmmoPlayer.getProfile();
if (player.isOnline()) {
player.sendMessage(ChatColor.GREEN + "Your level in " + skillName + " was set to " + newValue + "!"); //TODO: Needs more locale.
}
profile.modifySkill(skill, newValue);
mcmmoPlayer.getPlayer().sendMessage(ChatColor.GREEN + "Your level in " + skillName + " was set to " + newValue + "!"); //TODO: Needs more locale.
sender.sendMessage(ChatColor.RED + skillName + " has been modified for " + args[0] + "."); //TODO: Use locale
}
else {
playerProfile = new PlayerProfile(null, args[0], false);
profile = new PlayerProfile(args[0], false); //Temporary Profile
if (!playerProfile.isLoaded()) {
if (!profile.isLoaded()) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
}
sender.sendMessage(ChatColor.RED + skillName + " has been modified for " + args[0] + "."); //TODO: Use locale
playerProfile.modifySkill(skill, newValue);
playerProfile.save();
profile.modifySkill(skill, newValue);
profile.save();
}
return true;
default:

View File

@@ -26,7 +26,7 @@ public class MmoupdateCommand implements CommandExecutor {
}
sender.sendMessage(ChatColor.GRAY + "Starting conversion..."); //TODO: Needs more locale.
Users.clearUsers();
Users.clearAll();
convertToMySQL();
for (Player x : plugin.getServer().getOnlinePlayers()) {

View File

@@ -0,0 +1,59 @@
package com.gmail.nossr50.commands.general;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Users;
public class SkillResetCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (CommandHelper.noConsoleUsage(sender)) {
return true;
}
//ensure they have the skillreset perm
if (CommandHelper.noCommandPermissions(sender, "mcmmo.skillreset")) {
return true;
}
SkillType skillType = null; //simple initialization
//make sure there's only one argument. output at least some kind of error if not
if (args.length != 1 && args[0] != null) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true;
}
//parse the skilltype that they sent
try
{
skillType = SkillType.valueOf(args[0].toUpperCase().trim()); //ucase needed to match enum since it's case sensitive. trim to be nice
}catch(IllegalArgumentException ex)
{
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true;
}
//reset the values in the hash table and persist them
PlayerProfile profile = Users.getProfile((Player)sender);
profile.resetSkill(skillType);
profile.save();
//display a success message to the user
if (skillType == SkillType.ALL)
sender.sendMessage(LocaleLoader.getString("Commands.Reset.All"));
else
sender.sendMessage(LocaleLoader.getString("Commands.Reset.Single", new Object[] { args[0] }));
return true;
}
}

View File

@@ -13,8 +13,8 @@ import com.gmail.nossr50.util.Misc;
public class XprateCommand implements CommandExecutor {
private final mcMMO plugin;
private static int oldrate = Config.getInstance().xpGainMultiplier;
public static boolean xpevent = false;
private static double oldRate = Config.getInstance().xpGainMultiplier;
private static boolean xpEvent = false;
public XprateCommand (mcMMO plugin) {
this.plugin = plugin;
@@ -33,16 +33,16 @@ public class XprateCommand implements CommandExecutor {
switch (args.length) {
case 1:
if (args[0].equalsIgnoreCase("reset")) {
if (xpevent) {
if (xpEvent) {
for (Player x : plugin.getServer().getOnlinePlayers()) {
x.sendMessage(LocaleLoader.getString("Commands.xprate.over"));
}
xpevent = !xpevent;
Config.getInstance().xpGainMultiplier = oldrate;
xpEvent = !xpEvent;
Config.getInstance().xpGainMultiplier = oldRate;
}
else {
Config.getInstance().xpGainMultiplier = oldrate;
Config.getInstance().xpGainMultiplier = oldRate;
}
}
else if (Misc.isInt(args[0])) {
@@ -56,10 +56,10 @@ public class XprateCommand implements CommandExecutor {
case 2:
if (Misc.isInt(args[0])) {
oldrate = Config.getInstance().xpGainMultiplier;
oldRate = Config.getInstance().xpGainMultiplier;
if (args[1].equalsIgnoreCase("true") || args[1].equalsIgnoreCase("false")) {
xpevent = Boolean.valueOf(args[1]);
xpEvent = Boolean.valueOf(args[1]);
}
else {
sender.sendMessage(usage3);
@@ -67,7 +67,7 @@ public class XprateCommand implements CommandExecutor {
Config.getInstance().xpGainMultiplier = Misc.getInt(args[0]);
if (xpevent) {
if (xpEvent) {
for (Player x : plugin.getServer().getOnlinePlayers()) {
x.sendMessage(LocaleLoader.getString("Commands.xprate.started.0"));
x.sendMessage(LocaleLoader.getString("Commands.xprate.started.1", new Object[] {Config.getInstance().xpGainMultiplier}));
@@ -90,4 +90,8 @@ public class XprateCommand implements CommandExecutor {
return true;
}
}
public static boolean isXpEventRunning() {
return xpEvent;
}
}

View File

@@ -22,16 +22,16 @@ public class McabilityCommand implements CommandExecutor {
return true;
}
PlayerProfile PP = Users.getProfile((Player) sender);
PlayerProfile profile = Users.getProfile((Player) sender);
if (PP.getAbilityUse()) {
if (profile.getAbilityUse()) {
sender.sendMessage(LocaleLoader.getString("Commands.Ability.Off"));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.Ability.On"));
}
PP.toggleAbilityUse();
profile.toggleAbilityUse();
return true;
}

View File

@@ -7,6 +7,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
@@ -44,6 +45,10 @@ public class MccCommand implements CommandExecutor {
player.sendMessage("/mcstats " + LocaleLoader.getString("Commands.Stats"));
player.sendMessage("/mctop " + LocaleLoader.getString("Commands.Leaderboards"));
if (Config.getInstance().getCommandSkillResetEnabled() && Permissions.getInstance().skillReset(player)) {
player.sendMessage("/skillreset <skill|all> " + LocaleLoader.getString("Commands.Reset"));
}
if (Permissions.getInstance().mcAbility(player)) {
player.sendMessage("/mcability " + LocaleLoader.getString("Commands.ToggleAbility"));
}

View File

@@ -22,16 +22,16 @@ public class McgodCommand implements CommandExecutor {
return true;
}
PlayerProfile PP = Users.getProfile((Player) sender);
PlayerProfile profile = Users.getProfile((Player) sender);
if (PP.getGodMode()) {
if (profile.getGodMode()) {
sender.sendMessage(LocaleLoader.getString("Commands.GodMode.Disabled"));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.GodMode.Enabled"));
}
PP.toggleGodMode();
profile.toggleGodMode();
return true;
}

View File

@@ -20,9 +20,9 @@ public class McmmoCommand implements CommandExecutor {
if (Config.getInstance().getDonateMessageEnabled()) {
if (mcMMO.spoutEnabled && sender instanceof SpoutPlayer) {
SpoutPlayer sPlayer = (SpoutPlayer) sender;
SpoutPlayer spoutPlayer = (SpoutPlayer) sender;
sPlayer.sendNotification(ChatColor.YELLOW + "[mcMMO]" + ChatColor.GOLD + " Donate!", ChatColor.GREEN + "mcmmodev@gmail.com", Material.DIAMOND);
spoutPlayer.sendNotification(ChatColor.YELLOW + "[mcMMO]" + ChatColor.GOLD + " Donate!", ChatColor.GREEN + "mcmmodev@gmail.com", Material.DIAMOND);
}
sender.sendMessage(ChatColor.DARK_AQUA + "Donation Info:");

View File

@@ -23,7 +23,7 @@ public class McrefreshCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
OfflinePlayer player;
PlayerProfile PP;
PlayerProfile profile;
String usage = ChatColor.RED + "Proper usage is /mcrefresh [player]"; //TODO: Needs more locale
if (CommandHelper.noCommandPermissions(sender, "mcmmo.tools.mcrefresh")) {
@@ -34,7 +34,7 @@ public class McrefreshCommand implements CommandExecutor {
case 0:
if (sender instanceof Player) {
player = (Player) sender;
PP = Users.getProfile(player);
profile = Users.getProfile(player);
}
else {
sender.sendMessage(usage);
@@ -44,10 +44,10 @@ public class McrefreshCommand implements CommandExecutor {
case 1:
player = plugin.getServer().getOfflinePlayer(args[0]);
PP = Users.getProfile(player);
profile = Users.getProfile(player);
String playerName = player.getName();
if (!PP.isLoaded()) {
if (!profile.isLoaded()) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
@@ -61,10 +61,10 @@ public class McrefreshCommand implements CommandExecutor {
return true;
}
PP.setRecentlyHurt(0);
PP.resetCooldowns();
PP.resetToolPrepMode();
PP.resetAbilityMode();
profile.setRecentlyHurt(0);
profile.resetCooldowns();
profile.resetToolPrepMode();
profile.resetAbilityMode();
if (player.isOnline()) {
((Player) player).sendMessage(LocaleLoader.getString("Ability.Generic.Refresh"));

View File

@@ -3,9 +3,9 @@ package com.gmail.nossr50.commands.mc;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@@ -14,8 +14,11 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.SpoutHud;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.spout.SpoutStuff;
import com.gmail.nossr50.util.Database;
import com.gmail.nossr50.util.Users;
public class McremoveCommand implements CommandExecutor {
@@ -24,7 +27,7 @@ public class McremoveCommand implements CommandExecutor {
public McremoveCommand (mcMMO plugin) {
this.plugin = plugin;
this.location = mcMMO.usersFile;
this.location = mcMMO.getUsersFile();
}
@Override
@@ -52,31 +55,32 @@ public class McremoveCommand implements CommandExecutor {
/* MySQL */
if (Config.getInstance().getUseMySQL()) {
Database database = mcMMO.getPlayerDatabase();
int userId = 0;
userId = mcMMO.database.getInt("SELECT id FROM " + tablePrefix + "users WHERE user = '" + playerName + "'");
userId = database.getInt("SELECT id FROM " + tablePrefix + "users WHERE user = '" + playerName + "'");
if (userId > 0) {
mcMMO.database.write("DELETE FROM "
database.write("DELETE FROM "
+ databaseName + "."
+ tablePrefix + "users WHERE "
+ tablePrefix + "users.id=" + userId);
mcMMO.database.write("DELETE FROM "
database.write("DELETE FROM "
+ databaseName + "."
+ tablePrefix + "cooldowns WHERE "
+ tablePrefix + "cooldowns.user_id=" + userId);
mcMMO.database.write("DELETE FROM "
database.write("DELETE FROM "
+ databaseName + "."
+ tablePrefix + "huds WHERE "
+ tablePrefix + "huds.user_id=" + userId);
mcMMO.database.write("DELETE FROM "
database.write("DELETE FROM "
+ databaseName + "."
+ tablePrefix + "skills WHERE "
+ tablePrefix + "skills.user_id=" + userId);
mcMMO.database.write("DELETE FROM "
database.write("DELETE FROM "
+ databaseName + "."
+ tablePrefix + "experience WHERE "
+ tablePrefix + "experience.user_id=" + userId);
@@ -98,14 +102,24 @@ public class McremoveCommand implements CommandExecutor {
}
//Force PlayerProfile stuff to update
OfflinePlayer player = plugin.getServer().getOfflinePlayer(playerName);
PlayerProfile playerProfile = Users.getProfile(player);
McMMOPlayer mcmmoPlayer = Users.getPlayer(playerName);
if (playerProfile != null) {
Users.getProfiles().remove(playerProfile);
if (mcmmoPlayer != null) {
Player player = mcmmoPlayer.getPlayer();
SpoutHud spoutHud = mcmmoPlayer.getProfile().getSpoutHud();
if (spoutHud != null) {
spoutHud.removeWidgets();
}
Users.remove(playerName);
if (player.isOnline()) {
Users.addUser((Player) player);
Users.addUser(player);
if (mcMMO.spoutEnabled) {
SpoutStuff.reloadSpoutPlayer(player);
}
}
}
@@ -115,9 +129,12 @@ public class McremoveCommand implements CommandExecutor {
private boolean removeFlatFileUser(String playerName) {
boolean worked = false;
BufferedReader in = null;
FileWriter out = null;
try {
FileReader file = new FileReader(location);
BufferedReader in = new BufferedReader(file);
in = new BufferedReader(file);
StringBuilder writer = new StringBuilder();
String line = "";
@@ -134,16 +151,32 @@ public class McremoveCommand implements CommandExecutor {
}
}
in.close();
FileWriter out = new FileWriter(location); //Write out the new file
out = new FileWriter(location); //Write out the new file
out.write(writer.toString());
out.close();
return worked;
}
catch (Exception e) {
plugin.getLogger().severe("Exception while reading " + location + " (Are you sure you formatted it correctly?)" + e.toString());
return worked;
}
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;
}
}

View File

@@ -11,6 +11,7 @@ import org.bukkit.command.CommandSender;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Database;
import com.gmail.nossr50.util.Leaderboard;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Skills;
@@ -107,7 +108,7 @@ public class MctopCommand implements CommandExecutor {
private void flatfileDisplay(int page, String skill, CommandSender sender) {
String[] info = Leaderboard.retrieveInfo(skill, page);
if (skill == "ALL") {
if (skill.equals("ALL")) {
sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Leaderboard"));
}
else {
@@ -134,9 +135,11 @@ public class MctopCommand implements CommandExecutor {
private void sqlDisplay(int page, String query, CommandSender sender) {
String tablePrefix = Config.getInstance().getMySQLTablePrefix();
HashMap<Integer, ArrayList<String>> userslist = mcMMO.database.read("SELECT " + query + ", user_id FROM " + tablePrefix + "skills WHERE " + query + " > 0 ORDER BY " + query + " DESC ");
Database database = mcMMO.getPlayerDatabase();
if (query == "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing") {
HashMap<Integer, ArrayList<String>> userslist = database.read("SELECT " + query + ", user_id FROM " + tablePrefix + "skills WHERE " + query + " > 0 ORDER BY " + query + " DESC ");
if (query.equals("taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing")) {
sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Leaderboard"));
}
else {
@@ -144,11 +147,11 @@ public class MctopCommand implements CommandExecutor {
}
for (int i = (page * 10) - 9; i <= (page * 10); i++) {
if (i > userslist.size() || mcMMO.database.read("SELECT user FROM " + tablePrefix + "users WHERE id = '" + Integer.valueOf(userslist.get(i).get(1)) + "'") == null) {
if (i > userslist.size() || database.read("SELECT user FROM " + tablePrefix + "users WHERE id = '" + Integer.valueOf(userslist.get(i).get(1)) + "'") == null) {
break;
}
HashMap<Integer, ArrayList<String>> username = mcMMO.database.read("SELECT user FROM " + tablePrefix + "users WHERE id = '" + Integer.valueOf(userslist.get(i).get(1)) + "'");
HashMap<Integer, ArrayList<String>> username = database.read("SELECT user FROM " + tablePrefix + "users WHERE id = '" + Integer.valueOf(userslist.get(i).get(1)) + "'");
sender.sendMessage(String.valueOf(i) + ". " + ChatColor.GREEN + userslist.get(i).get(0) + " - " + ChatColor.WHITE + username.get(1).get(0));
}
}

View File

@@ -23,7 +23,7 @@ public class ACommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
PlayerProfile PP;
PlayerProfile profile;
String usage = ChatColor.RED + "Proper usage is /a <message>"; //TODO: Needs more locale.
if (CommandHelper.noCommandPermissions(sender, "mcmmo.chat.adminchat")) {
@@ -33,15 +33,15 @@ public class ACommand implements CommandExecutor {
switch (args.length) {
case 0:
if (sender instanceof Player) {
PP = Users.getProfile((Player) sender);
profile = Users.getProfile((Player) sender);
if (PP.getPartyChatMode()) {
PP.togglePartyChat();
if (profile.getPartyChatMode()) {
profile.togglePartyChat();
}
PP.toggleAdminChat();
profile.toggleAdminChat();
if (PP.getAdminChatMode()) {
if (profile.getAdminChatMode()) {
sender.sendMessage(LocaleLoader.getString("Commands.AdminChat.On"));
}
else {
@@ -55,12 +55,16 @@ public class ACommand implements CommandExecutor {
return true;
default:
String message = args[0];
StringBuffer buffer = new StringBuffer();
buffer.append(args[0]);
for (int i = 1; i < args.length; i++) {
message = message + " " + args [i];
buffer.append(" ");
buffer.append(args[i]);
}
String message = buffer.toString();
if (sender instanceof Player) {
Player player = (Player) sender;
@@ -76,9 +80,9 @@ public class ACommand implements CommandExecutor {
plugin.getLogger().info("[A]<" + player.getName() + "> " + message);
for (Player p : plugin.getServer().getOnlinePlayers()) {
if (Permissions.getInstance().adminChat(player) || player.isOp()) {
p.sendMessage(prefix + message);
for (Player otherPlayer : plugin.getServer().getOnlinePlayers()) {
if (Permissions.getInstance().adminChat(otherPlayer) || otherPlayer.isOp()) {
otherPlayer.sendMessage(prefix + message);
}
}
}

View File

@@ -24,7 +24,7 @@ public class PCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
PlayerProfile PP;
PlayerProfile profile;
String usage = ChatColor.RED + "Proper usage is /p <party-name> <message>"; //TODO: Needs more locale.
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party")) {
@@ -34,15 +34,15 @@ public class PCommand implements CommandExecutor {
switch (args.length) {
case 0:
if (sender instanceof Player) {
PP = Users.getProfile((Player) sender);
profile = Users.getProfile((Player) sender);
if (PP.getAdminChatMode()) {
PP.toggleAdminChat();
if (profile.getAdminChatMode()) {
profile.toggleAdminChat();
}
PP.togglePartyChat();
profile.togglePartyChat();
if (PP.getPartyChatMode()) {
if (profile.getPartyChatMode()) {
sender.sendMessage(LocaleLoader.getString("Commands.Party.Chat.On"));
}
else {
@@ -65,12 +65,16 @@ public class PCommand implements CommandExecutor {
return true;
}
String message = args[0];
StringBuffer buffer = new StringBuffer();
buffer.append(args[0]);
for (int i = 1; i < args.length; i++) {
message = message + " " + args [i];
buffer.append(" ");
buffer.append(args[i]);
}
String message = buffer.toString();
McMMOPartyChatEvent chatEvent = new McMMOPartyChatEvent(player.getName(), party.getName(), message);
plugin.getServer().getPluginManager().callEvent(chatEvent);
@@ -98,12 +102,16 @@ public class PCommand implements CommandExecutor {
return true;
}
String message = args[1];
StringBuffer buffer = new StringBuffer();
buffer.append(args[1]);
for (int i = 2; i < args.length; i++) {
message = message + " " + args [i];
buffer.append(" ");
buffer.append(args[i]);
}
String message = buffer.toString();
McMMOPartyChatEvent chatEvent = new McMMOPartyChatEvent("Console", args[0], message);
plugin.getServer().getPluginManager().callEvent(chatEvent);

View File

@@ -37,9 +37,9 @@ public class PtpCommand implements CommandExecutor {
switch (args.length) {
case 1:
Player player = (Player) sender;
PlayerProfile PP = Users.getProfile(player);
PlayerProfile profile = Users.getProfile(player);
if (PP.getRecentlyHurt() + (Config.getInstance().getPTPCommandCooldown() * 1000) > System.currentTimeMillis()) {
if (profile.getRecentlyHurt() + (Config.getInstance().getPTPCommandCooldown() * 1000) > System.currentTimeMillis()) {
player.sendMessage(LocaleLoader.getString("Party.Teleport.Hurt", new Object[] { Config.getInstance().getPTPCommandCooldown() }));
return true;
}
@@ -62,7 +62,7 @@ public class PtpCommand implements CommandExecutor {
}
if (PartyManager.getInstance().inSameParty(player, target)) {
McMMOPartyTeleportEvent event = new McMMOPartyTeleportEvent(player, target, PP.getParty().getName());
McMMOPartyTeleportEvent event = new McMMOPartyTeleportEvent(player, target, profile.getParty().getName());
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {

View File

@@ -9,20 +9,13 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.config.SpoutConfig;
import com.gmail.nossr50.datatypes.HUDType;
import com.gmail.nossr50.datatypes.HUDmmo;
import com.gmail.nossr50.datatypes.HudType;
import com.gmail.nossr50.datatypes.SpoutHud;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.spout.SpoutStuff;
import com.gmail.nossr50.util.Users;
public class MchudCommand implements CommandExecutor {
private final mcMMO plugin;
public MchudCommand (mcMMO plugin) {
this.plugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
String usage = ChatColor.RED + "Proper usage is /mchud <hud-type>"; //TODO: Locale
@@ -37,40 +30,32 @@ public class MchudCommand implements CommandExecutor {
return true;
}
Player player = (Player) sender;
PlayerProfile playerProfile = Users.getProfile(player);
SpoutHud spoutHud = playerProfile.getSpoutHud();
if (spoutHud == null) {
sender.sendMessage(LocaleLoader.getString("Commands.Disabled"));
return true;
}
switch (args.length) {
case 1:
Player player = (Player) sender;
PlayerProfile PP = Users.getProfile(player);
HUDType hud;
for (HudType hudType : HudType.values()) {
if (hudType.toString().equalsIgnoreCase(args[0])) {
playerProfile.setHudType(hudType);
spoutHud.initializeXpBar();
spoutHud.updateXpBar();
if (args[0].equalsIgnoreCase("disabled")) {
hud = HUDType.DISABLED;
}
else if (args[0].equalsIgnoreCase("standard")) {
hud = HUDType.STANDARD;
}
else if (args[0].equalsIgnoreCase("small")) {
hud = HUDType.SMALL;
}
else if (args[0].equalsIgnoreCase("retro")) {
hud = HUDType.RETRO;
}
else {
player.sendMessage(invalid);
return true;
}
if (SpoutStuff.playerHUDs.containsKey(player)) {
SpoutStuff.playerHUDs.get(player).resetHUD();
SpoutStuff.playerHUDs.remove(player);
PP.setHUDType(hud);
SpoutStuff.playerHUDs.put(player, new HUDmmo(player, plugin));
return true;
}
}
player.sendMessage(invalid);
return true;
default:
sender.sendMessage(usage);
player.sendMessage(usage);
return true;
}
}

View File

@@ -12,8 +12,8 @@ import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.SpoutConfig;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.datatypes.SpoutHud;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.spout.SpoutStuff;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Skills;
@@ -34,45 +34,54 @@ public class XplockCommand implements CommandExecutor {
}
Player player = (Player) sender;
PlayerProfile PP = Users.getProfile(player);
PlayerProfile playerProfile = Users.getProfile(player);
SpoutHud spoutHud = playerProfile.getSpoutHud();
if (spoutHud == null) {
sender.sendMessage(LocaleLoader.getString("Commands.Disabled"));
return true;
}
switch (args.length) {
case 0:
if (PP.getXpBarLocked()) {
PP.toggleXpBarLocked();
if (spoutHud.getXpBarLocked()) {
spoutHud.toggleXpBarLocked();
player.sendMessage(LocaleLoader.getString("Commands.xplock.unlocked"));
return true;
}
SkillType lastGained = PP.getLastGained();
SkillType lastGained = spoutHud.getLastGained();
if (lastGained != null) {
PP.toggleXpBarLocked();
PP.setSkillLock(lastGained);
spoutHud.toggleXpBarLocked();
spoutHud.setSkillLock(lastGained);
player.sendMessage(LocaleLoader.getString("Commands.xplock.locked", new Object[] { Misc.getCapitalized(lastGained.toString()) }));
return true;
}
else {
player.sendMessage(usage);
}
return true;
case 1:
if (Skills.isSkill(args[0])) {
if (Permissions.getInstance().permission(player, "mcmmo.skills." + args[0].toLowerCase())) {
PP.setXpBarLocked(true);
PP.setSkillLock(Skills.getSkillType(args[0]));
SpoutStuff.updateXpBar(player);
spoutHud.setXpBarLocked(true);
spoutHud.setSkillLock(Skills.getSkillType(args[0]));
spoutHud.updateXpBar();
player.sendMessage(LocaleLoader.getString("Commands.xplock.locked", new Object[] { Misc.getCapitalized(args[0]) }));
return true;
}
else {
player.sendMessage(LocaleLoader.getString("mcMMO.NoPermission"));
return true;
}
}
else {
player.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true;
}
return true;
default:
player.sendMessage(usage);
return true;

View File

@@ -5,21 +5,27 @@ import java.util.Set;
import org.bukkit.configuration.ConfigurationSection;
import com.gmail.nossr50.mcMMO;
public class Config extends ConfigLoader {
public int xpGainMultiplier = 1;
private static Config instance;
public double xpGainMultiplier = 1;
private Config() {
super("config.yml");
xpGainMultiplier = getExperienceGainsGlobalMultiplier();
loadKeys();
}
public static Config getInstance() {
if (instance == null) {
instance = new Config(mcMMO.p);
instance.load();
instance = new Config();
}
return instance;
}
@Override
protected void loadKeys() {}
/*
* GENERAL SETTINGS
*/
@@ -71,6 +77,7 @@ public class Config extends ConfigLoader {
public boolean getCommandMCCEnabled() { return config.getBoolean("Commands.mcc.Enabled", true); }
public boolean getCommandMCGodEnabled() { return config.getBoolean("Commands.mcgod.Enabled", true); }
public boolean getCommandMCStatsEnabled() { return config.getBoolean("Commands.mcstats.Enabled", true); }
public boolean getCommandSkillResetEnabled() { return config.getBoolean("Commands.skillreset.Enabled", true); }
public boolean getCommandMmoeditEnabled() { return config.getBoolean("Commands.mmoedit.Enabled", true); }
public boolean getCommandMCRemoveEnabled() { return config.getBoolean("Commands.mcremove.Enable", true); }
public boolean getCommandPTPEnabled() { return config.getBoolean("Commands.ptp.Enabled", true); }
@@ -336,7 +343,7 @@ public class Config extends ConfigLoader {
/* General Settings */
public boolean getExperienceGainsMobspawnersEnabled() { return config.getBoolean("Experience.Gains.Mobspawners.Enabled", false); }
public boolean getExperienceGainsPlayerVersusPlayerEnabled() { return config.getBoolean("Experience.PVP.Rewards", true); }
public int getExperienceGainsGlobalMultiplier() { return config.getInt("Experience.Gains.Multiplier.Global", 1); }
public double getExperienceGainsGlobalMultiplier() { return config.getDouble("Experience.Gains.Multiplier.Global", 1.0); }
/* Combat XP Multipliers */
public double getPlayerVersusPlayerXP() { return config.getDouble("Experience.Gains.Multiplier.PVP", 1.0); }
@@ -370,19 +377,4 @@ public class Config extends ConfigLoader {
public double getFormulaMultiplierAxes() { return config.getDouble("Experience.Formula.Multiplier.Axes", 1.0); }
public double getFormulaMultiplierAcrobatics() { return config.getDouble("Experience.Formula.Multiplier.Acrobatics", 1.0); }
public double getFormulaMultiplierFishing() { return config.getDouble("Experience.Formula.Multiplier.Fishing", 1.0); }
/*
* CONFIG LOADING
*/
private Config(mcMMO plugin) {
super(plugin, "config.yml");
saveIfNotExist();
xpGainMultiplier = getExperienceGainsGlobalMultiplier();
}
@Override
protected void loadKeys() {
plugin.getLogger().info("Loading mcMMO config.yml File...");
}
}

View File

@@ -1,7 +1,9 @@
package com.gmail.nossr50.config;
import java.io.File;
import java.io.IOException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
@@ -9,69 +11,69 @@ import org.bukkit.configuration.file.YamlConfiguration;
import com.gmail.nossr50.mcMMO;
public abstract class ConfigLoader {
protected static final mcMMO plugin = mcMMO.p;
protected String fileName;
protected File configFile;
protected File dataFolder;
protected final mcMMO plugin;
protected FileConfiguration config;
public ConfigLoader(mcMMO plugin, String fileName){
this.plugin = plugin;
public ConfigLoader(String relativePath, String fileName){
this.fileName = fileName;
dataFolder = plugin.getDataFolder();
configFile = new File(dataFolder, File.separator + fileName);
configFile = new File(plugin.getDataFolder(), relativePath + File.separator + fileName);
loadFile();
}
public ConfigLoader(String fileName){
this.fileName = fileName;
configFile = new File(plugin.getDataFolder(), fileName);
loadFile();
}
protected void loadFile() {
if (!configFile.exists()) {
plugin.getLogger().info("Creating mcMMO " + fileName + " File...");
createFile();
}
else {
plugin.getLogger().info("Loading mcMMO " + fileName + " File...");
}
config = YamlConfiguration.loadConfiguration(configFile);
}
/**
* Load this config file.
*/
public void load() {
if (!configFile.exists()) {
dataFolder.mkdir();
saveConfig();
}
addDefaults();
loadKeys();
}
/**
* Save this config file.
*/
private void saveConfig() {
try {
config.save(configFile);
}
catch (IOException ex) {
plugin.getLogger().severe("Could not save config to " + configFile + ex);
}
}
protected void saveIfNotExist() {
if (!configFile.exists()) {
if (plugin.getResource(fileName) != null) {
plugin.saveResource(fileName, false);
}
}
rereadFromDisk();
}
protected void rereadFromDisk() {
config = YamlConfiguration.loadConfiguration(configFile);
}
/**
* Add the defaults to this config file.
*/
protected void addDefaults() {
config.options().copyDefaults(true);
saveConfig();
}
/**
* Load the keys from this config file.
*/
protected abstract void loadKeys();
protected void createFile() {
if (configFile.exists()) {
return;
}
configFile.getParentFile().mkdirs();
InputStream inputStream = plugin.getResource(fileName);
if (inputStream != null) {
try {
copyStreamToFile(inputStream, configFile);
} catch (Exception e) {
e.printStackTrace();
}
}
else {
plugin.getLogger().severe("Missing ressource file: '" + fileName + "' please notify the plugin authors");
}
}
private static void copyStreamToFile(InputStream inputStream, File file) throws Exception {
OutputStream outputStream = new FileOutputStream(file);
int read = 0;
byte[] bytes = new byte[1024];
while ((read = inputStream.read(bytes)) != -1) {
outputStream.write(bytes, 0, read);
}
inputStream.close();
outputStream.close();
}
}

View File

@@ -4,42 +4,32 @@ import org.bukkit.configuration.file.YamlConfiguration;
import com.gmail.nossr50.mcMMO;
public class HiddenConfig extends ConfigLoader {
private static String fileName;
public class HiddenConfig {
private static HiddenConfig instance;
private static String fileName;
private static YamlConfiguration config;
private static boolean chunkletsEnabled;
public HiddenConfig(mcMMO plugin, String fileName) {
super(plugin, fileName);
public HiddenConfig(String fileName) {
HiddenConfig.fileName = fileName;
load();
}
public static HiddenConfig getInstance() {
if (instance == null) {
instance = new HiddenConfig(mcMMO.p, "hidden.yml");
instance.load();
instance = new HiddenConfig("hidden.yml");
}
return instance;
}
@Override
public void load() {
if (plugin.getResource(fileName) != null) {
loadKeys();
if (mcMMO.p.getResource(fileName) != null) {
config = YamlConfiguration.loadConfiguration(mcMMO.p.getResource(fileName));
chunkletsEnabled = config.getBoolean("Options.Chunklets", true);
}
}
@Override
protected void loadKeys() {
config = YamlConfiguration.loadConfiguration(plugin.getResource(fileName));
chunkletsEnabled = config.getBoolean("Options.Chunklets", true);
}
public boolean getChunkletsEnabled() {
return chunkletsEnabled;
}

View File

@@ -1,25 +1,39 @@
package com.gmail.nossr50.config;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.HUDType;
import com.gmail.nossr50.datatypes.HudType;
public class SpoutConfig extends ConfigLoader {
private static SpoutConfig instance;
public HudType defaultHudType;
private SpoutConfig() {
super("spout.yml");
loadKeys();
}
public static SpoutConfig getInstance() {
if (instance == null) {
instance = new SpoutConfig(mcMMO.p);
instance.load();
instance = new SpoutConfig();
}
return instance;
}
public HUDType defaulthud;
@Override
protected void loadKeys() {
// Setup default HUD
String temp = config.getString("Spout.HUD.Default", "STANDARD");
private SpoutConfig(mcMMO plugin) {
super(plugin, "spout.yml");
saveIfNotExist();
for (HudType hudType : HudType.values()) {
if (hudType.toString().equalsIgnoreCase(temp.toString())) {
defaultHudType = hudType;
break;
}
}
if (defaultHudType == null) {
defaultHudType = HudType.STANDARD;
}
}
public boolean getShowPowerLevel() { return config.getBoolean("HUD.Show_Power_Level", true); }
@@ -77,22 +91,4 @@ public class SpoutConfig extends ConfigLoader {
public double getRetroHUDFishingRed() { return config.getDouble("HUD.Retro.Colors.Fishing.RED", 0.3); }
public double getRetroHUDFishingGreen() { return config.getDouble("HUD.Retro.Colors.Fishing.GREEN", 0.3); }
public double getRetroHUDFishingBlue() { return config.getDouble("HUD.Retro.Colors.Fishing.BLUE", 0.75); }
@Override
protected void loadKeys() {
plugin.getLogger().info("Loading mcMMO spout.yml File...");
// Setup default HUD
String temp = config.getString("Spout.HUD.Default", "STANDARD");
for (HUDType x : HUDType.values()) {
if (x.toString().equalsIgnoreCase(temp.toString())) {
defaulthud = x;
}
}
if (defaulthud == null) {
defaulthud = HUDType.STANDARD;
}
}
}

View File

@@ -5,29 +5,19 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure;
import com.gmail.nossr50.datatypes.treasure.FishingTreasure;
import com.gmail.nossr50.datatypes.treasure.Treasure;
public class TreasuresConfig extends ConfigLoader{
private static TreasuresConfig instance;
public static TreasuresConfig getInstance() {
if (instance == null) {
instance = new TreasuresConfig(mcMMO.p);
instance.load();
}
return instance;
}
public List<ExcavationTreasure> excavationFromDirt = new ArrayList<ExcavationTreasure>();
public List<ExcavationTreasure> excavationFromGrass = new ArrayList<ExcavationTreasure>();
public List<ExcavationTreasure> excavationFromSand = new ArrayList<ExcavationTreasure>();
@@ -41,15 +31,21 @@ public class TreasuresConfig extends ConfigLoader{
public List<FishingTreasure> fishingRewardsTier4 = new ArrayList<FishingTreasure>();
public List<FishingTreasure> fishingRewardsTier5 = new ArrayList<FishingTreasure>();
private TreasuresConfig(mcMMO plugin) {
super(plugin, "treasures.yml");
saveIfNotExist();
private TreasuresConfig() {
super("treasures.yml");
loadKeys();
}
public static TreasuresConfig getInstance() {
if (instance == null) {
instance = new TreasuresConfig();
}
return instance;
}
@Override
protected void loadKeys() {
plugin.getLogger().info("Loading mcMMO treasures.yml File...");
Map<String, Treasure> treasures = new HashMap<String, Treasure>();
ConfigurationSection treasureSection = config.getConfigurationSection("Treasures");
Set<String> treasureConfigSet = treasureSection.getKeys(false);
@@ -194,11 +190,13 @@ public class TreasuresConfig extends ConfigLoader{
List<String> excavationTreasures = config.getStringList("Excavation.Treasure");
List<String> fishingTreasures = config.getStringList("Fishing.Treasure");
Iterator<String> treasureIterator = treasures.keySet().iterator();
// Iterator<String> treasureIterator = treasures.keySet().iterator();
Iterator<Entry<String,Treasure>> treasureIterator = treasures.entrySet().iterator();
while (treasureIterator.hasNext()) {
String treasureKey = treasureIterator.next();
Treasure treasure = treasures.get(treasureKey);
Entry<String,Treasure> nextEntry = treasureIterator.next();
String treasureKey = nextEntry.getKey();
Treasure treasure = nextEntry.getValue();
if (treasure instanceof FishingTreasure) {
if (!fishingTreasures.contains(treasureKey)) {

View File

@@ -8,40 +8,37 @@ import java.util.Set;
import org.bukkit.configuration.ConfigurationSection;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.ConfigLoader;
import com.gmail.nossr50.datatypes.mods.CustomItem;
import com.gmail.nossr50.skills.repair.Repairable;
import com.gmail.nossr50.skills.repair.RepairableFactory;
public class CustomArmorConfig extends ModConfigLoader{
public class CustomArmorConfig extends ConfigLoader{
private static CustomArmorConfig instance;
private List<Repairable> repairables;
public List<Integer> customBootIDs = new ArrayList<Integer>();
public List<Integer> customChestplateIDs = new ArrayList<Integer>();
public List<Integer> customHelmetIDs = new ArrayList<Integer>();
public List<Integer> customLeggingIDs = new ArrayList<Integer>();
public List<Integer> customIDs = new ArrayList<Integer>();
public List<CustomItem> customArmorList = new ArrayList<CustomItem>();
public HashMap<Integer, CustomItem> customArmor = new HashMap<Integer, CustomItem>();
public CustomArmorConfig() {
super("ModConfigs", "armor.yml");
loadKeys();
}
public static CustomArmorConfig getInstance() {
if (instance == null) {
instance = new CustomArmorConfig(mcMMO.p);
instance = new CustomArmorConfig();
}
return instance;
}
private List<Repairable> repairables;
public List<Integer> customBootIDs = new ArrayList<Integer>();
public List<Integer> customChestplateIDs = new ArrayList<Integer>();
public List<Integer> customHelmetIDs = new ArrayList<Integer>();
public List<Integer> customLeggingIDs = new ArrayList<Integer>();
public List<Integer> customIDs = new ArrayList<Integer>();
public List<CustomItem> customArmorList = new ArrayList<CustomItem>();
public HashMap<Integer, CustomItem> customArmor = new HashMap<Integer, CustomItem>();
public CustomArmorConfig(mcMMO plugin) {
super(plugin, "armor.yml");
}
@Override
protected void loadKeys() {
plugin.getLogger().info("Loading mcMMO armor.yml File...");
repairables = new ArrayList<Repairable>();
loadArmor("Boots", customBootIDs);

View File

@@ -8,44 +8,42 @@ import java.util.Set;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.ConfigLoader;
import com.gmail.nossr50.datatypes.mods.CustomBlock;
public class CustomBlocksConfig extends ModConfigLoader{
public class CustomBlocksConfig extends ConfigLoader {
private static CustomBlocksConfig instance;
public List<ItemStack> customExcavationBlocks = new ArrayList<ItemStack>();
public List<ItemStack> customHerbalismBlocks = new ArrayList<ItemStack>();
public List<ItemStack> customMiningBlocks = new ArrayList<ItemStack>();
public List<ItemStack> customWoodcuttingBlocks = new ArrayList<ItemStack>();
public List<ItemStack> customOres = new ArrayList<ItemStack>();
public List<ItemStack> customLogs = new ArrayList<ItemStack>();
public List<ItemStack> customLeaves = new ArrayList<ItemStack>();
public List<ItemStack> customAbilityBlocks = new ArrayList<ItemStack>();
public List<ItemStack> customItems = new ArrayList<ItemStack>();
public List<CustomBlock> customBlocks = new ArrayList<CustomBlock>();
public CustomBlocksConfig() {
super("ModConfigs", "blocks.yml");
loadKeys();
}
public static CustomBlocksConfig getInstance() {
if (instance == null) {
instance = new CustomBlocksConfig(mcMMO.p);
instance = new CustomBlocksConfig();
}
return instance;
}
public List<ItemStack> customExcavationBlocks = new ArrayList<ItemStack>();
public List<ItemStack> customHerbalismBlocks = new ArrayList<ItemStack>();
public List<ItemStack> customMiningBlocks = new ArrayList<ItemStack>();
public List<ItemStack> customWoodcuttingBlocks = new ArrayList<ItemStack>();
public List<ItemStack> customOres = new ArrayList<ItemStack>();
public List<ItemStack> customLogs = new ArrayList<ItemStack>();
public List<ItemStack> customLeaves = new ArrayList<ItemStack>();
public List<ItemStack> customItems = new ArrayList<ItemStack>();
public List<CustomBlock> customBlocks = new ArrayList<CustomBlock>();
public CustomBlocksConfig(mcMMO plugin) {
super(plugin, "blocks.yml");
}
@Override
protected void loadKeys() {
plugin.getLogger().info("Loading mcMMO blocks.yml File...");
loadBlocks("Excavation", customExcavationBlocks);
loadBlocks("Herbalism", customHerbalismBlocks);
loadBlocks("Mining", customMiningBlocks);
loadBlocks("Woodcutting", customWoodcuttingBlocks);
loadBlocks("Ability_Blocks", customAbilityBlocks);
}
private void loadBlocks(String skillType, List<ItemStack> blockList) {
@@ -63,30 +61,37 @@ public class CustomBlocksConfig extends ModConfigLoader{
boolean dropItem = config.getBoolean(skillType + "." + blockName + ".Drop_Item", false);
int dropID = config.getInt(skillType + "." + blockName + ".Drop_Item_ID", 0);
byte dropData = (byte) config.getInt(skillType + "." + blockName + ".Drop_Item_Data_Value", 0);
int dropAmount = config.getInt(skillType + "." + blockName + ".Drop_Item_Amount", 1);
int minimumDropAmount = config.getInt(skillType + "." + blockName + ".Min_Drop_Item_Amount", 1);
int maxiumDropAmount = config.getInt(skillType + "." + blockName + ".Max_Drop_Item_Amount", 1);
CustomBlock block;
ItemStack itemDrop;
ItemStack blockItem;
if (id == 0) {
plugin.getLogger().warning("Missing ID. This block will be skipped.");
continue;
}
if (skillType.equals("Ability_Blocks")) {
blockItem = new ItemStack(id, 1, (short) 0, data);
blockList.add(blockItem);
continue;
}
if (dropItem && dropID == 0) {
plugin.getLogger().warning("Incomplete item drop information. This block will drop itself.");
dropItem = false;
}
CustomBlock block;
ItemStack itemDrop;
ItemStack blockItem;
if (dropItem) {
itemDrop = new ItemStack(dropID, dropAmount, (short) 0, dropData);
itemDrop = new ItemStack(dropID, 1, (short) 0, dropData);
}
else {
itemDrop = new ItemStack(id, dropAmount, (short) 0, data);
itemDrop = new ItemStack(id, 1, (short) 0, data);
}
block = new CustomBlock(itemDrop, tier, xp, data, id);
block = new CustomBlock(minimumDropAmount, maxiumDropAmount, itemDrop, tier, xp, data, id);
blockItem = new ItemStack(id, 1, (short) 0, data);
if (skillType.equals("Mining") && config.getBoolean(skillType + "." + blockName + ".Is_Ore")) {

View File

@@ -8,42 +8,39 @@ import java.util.Set;
import org.bukkit.configuration.ConfigurationSection;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.ConfigLoader;
import com.gmail.nossr50.datatypes.mods.CustomTool;
import com.gmail.nossr50.skills.repair.Repairable;
import com.gmail.nossr50.skills.repair.RepairableFactory;
public class CustomToolsConfig extends ModConfigLoader {
public class CustomToolsConfig extends ConfigLoader {
private static CustomToolsConfig instance;
public static CustomToolsConfig getInstance() {
if (instance == null) {
instance = new CustomToolsConfig(mcMMO.p);
}
return instance;
}
private List<Repairable> repairables;
public List<Integer> customAxeIDs = new ArrayList<Integer>();
public List<Integer> customBowIDs = new ArrayList<Integer>();
public List<Integer> customHoeIDs = new ArrayList<Integer>();
public List<Integer> customPickaxeIDs = new ArrayList<Integer>();
public List<Integer> customShovelIDs = new ArrayList<Integer>();
public List<Integer> customSwordIDs = new ArrayList<Integer>();
public List<Integer> customIDs = new ArrayList<Integer>();
public List<CustomTool> customToolList = new ArrayList<CustomTool>();
public HashMap<Integer, CustomTool> customTools = new HashMap<Integer, CustomTool>();
private CustomToolsConfig(mcMMO plugin) {
super(plugin, "tools.yml");
private CustomToolsConfig() {
super("ModConfigs", "tools.yml");
loadKeys();
}
public static CustomToolsConfig getInstance() {
if (instance == null) {
instance = new CustomToolsConfig();
}
return instance;
}
@Override
protected void loadKeys() {
plugin.getLogger().info("Loading mcMMO tools.yml File...");
repairables = new ArrayList<Repairable>();
loadTool("Axes", customAxeIDs);

View File

@@ -1,13 +0,0 @@
package com.gmail.nossr50.config.mods;
import java.io.File;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.ConfigLoader;
public abstract class ModConfigLoader extends ConfigLoader{
public ModConfigLoader(mcMMO plugin, String fileName) {
super(plugin, "ModConfigs" + File.separator + fileName);
}
}

View File

@@ -1,13 +1,12 @@
package com.gmail.nossr50.config;
package com.gmail.nossr50.config.repair;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.ConfigLoader;
import com.gmail.nossr50.skills.repair.RepairItemType;
import com.gmail.nossr50.skills.repair.RepairMaterialType;
import com.gmail.nossr50.skills.repair.Repairable;
@@ -16,13 +15,8 @@ import com.gmail.nossr50.skills.repair.RepairableFactory;
public class RepairConfig extends ConfigLoader {
private List<Repairable> repairables;
public RepairConfig(mcMMO plugin, String fileName) {
super(plugin, fileName);
this.config = YamlConfiguration.loadConfiguration(this.configFile);
}
@Override
public void load() {
public RepairConfig(String fileName) {
super(fileName);
loadKeys();
}

View File

@@ -1,4 +1,4 @@
package com.gmail.nossr50.config;
package com.gmail.nossr50.config.repair;
import java.io.File;
import java.util.ArrayList;
@@ -22,22 +22,18 @@ public class RepairConfigManager {
plugin.saveResource("repair.vanilla.yml", false);
}
for (String location : dataFolder.list()) {
if (!pattern.matcher(location).matches()) {
for (String fileName : dataFolder.list()) {
if (!pattern.matcher(fileName).matches()) {
continue;
}
plugin.getLogger().info("Loading " + location + " repair config file...");
File file = new File(dataFolder, location);
File file = new File(dataFolder, fileName);
if (file.isDirectory()) {
continue;
}
RepairConfig rConfig = new RepairConfig(plugin, location);
rConfig.load();
RepairConfig rConfig = new RepairConfig(fileName);
List<Repairable> rConfigRepairables = rConfig.getLoadedRepairables();
if (rConfigRepairables != null) {

View File

@@ -1,8 +0,0 @@
package com.gmail.nossr50.datatypes;
public enum HUDType {
DISABLED,
STANDARD,
SMALL,
RETRO;
}

View File

@@ -1,417 +0,0 @@
package com.gmail.nossr50.datatypes;
import org.bukkit.entity.Player;
import org.getspout.spoutapi.SpoutManager;
import org.getspout.spoutapi.gui.Color;
import org.getspout.spoutapi.gui.GenericGradient;
import org.getspout.spoutapi.gui.GenericTexture;
import org.getspout.spoutapi.gui.RenderPriority;
import org.getspout.spoutapi.gui.Widget;
import org.getspout.spoutapi.player.SpoutPlayer;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.SpoutConfig;
import com.gmail.nossr50.spout.SpoutStuff;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Users;
public class HUDmmo {
private int center_x = 427 / 2;
private String playerName;
private final mcMMO plugin;
private Widget xpbar = null;
private GenericGradient xpfill = null;
private GenericGradient xpbg = null;
private GenericGradient xpicon_bg = null;
private GenericGradient xpicon_border = null;
private GenericTexture xpicon = null;
public HUDmmo(Player player, mcMMO plugin) {
this.playerName = player.getName();
this.plugin = plugin;
initializeHUD(player);
}
/**
* Initialize the HUD.
*
* @param player Player whose HUD to initialize
*/
public void initializeHUD(Player player) {
HUDType type = Users.getProfile(player).getHUDType();
SpoutPlayer sPlayer = SpoutManager.getPlayer(player);
switch (type) {
case RETRO:
initializeXpBarDisplayRetro(sPlayer);
break;
case STANDARD:
initializeXpBarDisplayStandard(sPlayer);
break;
case SMALL:
initializeXpBarDisplaySmall(sPlayer);
break;
case DISABLED:
break;
default:
break;
}
}
/**
* Update the XP bar.
*
* @param type Type of XP bar
* @param player Player whose XP bar to update
*/
public void updateXpBarDisplay(HUDType type, Player player) {
PlayerProfile PP = Users.getProfile(player);
switch (type) {
case RETRO:
updateXpBarRetro(player, PP);
break;
case STANDARD:
updateXpBarStandard(player, PP);
break;
case SMALL:
updateXpBarStandard(player, PP);
break;
case DISABLED:
break;
default:
break;
}
}
/**
* Reset a player's HUD.
*/
public void resetHUD() {
SpoutPlayer sPlayer = SpoutStuff.getSpoutPlayer(playerName);
if (sPlayer != null) {
sPlayer.getMainScreen().removeWidgets(plugin);
//Reset the objects
xpbar = null;
xpfill = null;
xpbg = null;
xpicon = null;
sPlayer.getMainScreen().setDirty(true);
}
}
/**
* Initialize Retro XP bar.
*
* @param sPlayer Player to initialize XP bar for
*/
private void initializeXpBarDisplayRetro(SpoutPlayer sPlayer) {
Color border = new Color((float) SpoutConfig.getInstance().getRetroHUDXPBorderRed(), (float) SpoutConfig.getInstance().getRetroHUDXPBorderGreen(), (float) SpoutConfig.getInstance().getRetroHUDXPBorderBlue(), 1f);
Color green = new Color(0f, 1f, 0f, 1f);
Color background = new Color((float) SpoutConfig.getInstance().getRetroHUDXPBackgroundRed(), (float) SpoutConfig.getInstance().getRetroHUDXPBackgroundGreen(), (float) SpoutConfig.getInstance().getRetroHUDXPBackgroundBlue(), 1f);
Color darkbg = new Color(0.2f, 0.2f, 0.2f, 1f);
xpicon = new GenericTexture();
xpbar = new GenericGradient();
xpfill = new GenericGradient();
xpbg = new GenericGradient();
xpicon_bg = new GenericGradient();
xpicon_border = new GenericGradient();
xpicon_bg.setBottomColor(darkbg);
xpicon_bg.setTopColor(darkbg);
xpicon_bg.setWidth(4);
xpicon_bg.setHeight(4);
xpicon_bg.setPriority(RenderPriority.High);
xpicon_bg.setX(142);
xpicon_bg.setY(10);
xpicon_bg.setDirty(true);
xpicon_border.setBottomColor(border);
xpicon_border.setTopColor(border);
xpicon_border.setWidth(6);
xpicon_border.setHeight(6);
xpicon_border.setPriority(RenderPriority.Highest);
xpicon_border.setX(141);
xpicon_border.setY(9);
xpicon_border.setDirty(true);
xpicon.setWidth(6);
xpicon.setHeight(6);
xpicon.setX(141);
xpicon.setY(9);
xpicon.setPriority(RenderPriority.Normal);
xpicon.setDirty(true);
xpicon.setUrl("Icon_r.png");
xpbar.setWidth(128);
xpbar.setHeight(4);
xpbar.setX(149);
xpbar.setY(10);
((GenericGradient) xpbar).setBottomColor(border);
((GenericGradient) xpbar).setTopColor(border);
xpbar.setPriority(RenderPriority.Highest);
xpbar.setDirty(true);
xpfill.setWidth(0);
xpfill.setHeight(2);
xpfill.setX(150);
xpfill.setY(11);
xpfill.setBottomColor(green);
xpfill.setTopColor(green);
xpfill.setPriority(RenderPriority.Lowest);
xpfill.setDirty(true);
xpbg.setWidth(126);
xpbg.setHeight(2);
xpbg.setX(150);
xpbg.setY(11);
xpbg.setBottomColor(background);
xpbg.setTopColor(background);
xpbg.setPriority(RenderPriority.Low);
xpbg.setDirty(true);
if (SpoutConfig.getInstance().getXPBarEnabled()) {
sPlayer.getMainScreen().attachWidget(plugin, xpbar);
sPlayer.getMainScreen().attachWidget(plugin, xpfill);
sPlayer.getMainScreen().attachWidget(plugin, xpbg);
if (SpoutConfig.getInstance().getXPBarIconEnabled()) {
sPlayer.getMainScreen().attachWidget(plugin, xpicon);
sPlayer.getMainScreen().attachWidget(plugin, xpicon_bg);
sPlayer.getMainScreen().attachWidget(plugin, xpicon_border);
}
}
sPlayer.getMainScreen().setDirty(true);
}
/**
* Initialize Standard XP bar.
*
* @param sPlayer Player to initialize XP bar for
*/
public void initializeXpBarDisplayStandard(SpoutPlayer sPlayer) {
if (SpoutConfig.getInstance().getXPBarEnabled()) {
xpbar = new GenericTexture();
((GenericTexture) xpbar).setUrl("xpbar_inc000.png");
xpbar.setX(SpoutConfig.getInstance().getXPBarXPosition());
xpbar.setY(SpoutConfig.getInstance().getXPBarYPosition());
xpbar.setHeight(8);
xpbar.setWidth(256);
xpbar.setPriority(RenderPriority.Lowest);
sPlayer.getMainScreen().attachWidget(plugin, xpbar);
if (SpoutConfig.getInstance().getXPBarIconEnabled()) {
xpicon = new GenericTexture();
xpicon.setUrl("Icon.png");
xpicon.setHeight(16);
xpicon.setWidth(32);
xpicon.setX(SpoutConfig.getInstance().getXPIconXPosition());
xpicon.setY(SpoutConfig.getInstance().getXPIconYPosition());
xpicon.setPriority(RenderPriority.High);
xpicon.setDirty(true);
sPlayer.getMainScreen().attachWidget(plugin, xpicon);
}
}
sPlayer.getMainScreen().setDirty(true);
}
/**
* Initialize Small XP bar.
*
* @param sPlayer Player to initialize XP bar for
*/
private void initializeXpBarDisplaySmall(SpoutPlayer sPlayer) {
if (SpoutConfig.getInstance().getXPBarEnabled()) {
xpbar = new GenericTexture();
((GenericTexture)xpbar).setUrl("xpbar_inc000.png");
xpbar.setX(center_x - 64);
xpbar.setY(SpoutConfig.getInstance().getXPBarYPosition());
xpbar.setHeight(4);
xpbar.setWidth(128);
xpbar.setPriority(RenderPriority.Lowest);
sPlayer.getMainScreen().attachWidget(plugin, xpbar);
if (SpoutConfig.getInstance().getXPBarIconEnabled()) {
xpicon = new GenericTexture();
xpicon.setUrl("Icon.png");
xpicon.setHeight(8);
xpicon.setWidth(16);
xpicon.setX(center_x - (8 + 64));
xpicon.setY(SpoutConfig.getInstance().getXPIconYPosition() + 2);
xpicon.setPriority(RenderPriority.High);
xpicon.setDirty(true);
sPlayer.getMainScreen().attachWidget(plugin, xpicon);
}
}
sPlayer.getMainScreen().setDirty(true);
}
/**
* Update XP bar for Standard & Small styles.
*
* @param player Player whose XP bar to update
* @param PP Profile of the given player
*/
private void updateXpBarStandard(Player player, PlayerProfile PP) {
if (!SpoutConfig.getInstance().getXPBarEnabled()) {
return;
}
SkillType theType = getType(PP);
if (theType == null) { //Can this ever actually BE null? (Yes, it's null when the player has just logged in. It's not null when they gain XP in anything)
return;
}
xpicon.setUrl(Misc.getCapitalized(theType.toString()) + ".png");
xpicon.setDirty(true);
((GenericTexture) xpbar).setUrl(getUrlBar(getXpInc(PP.getSkillXpLevel(theType), PP.getXpToLevel(theType), HUDType.STANDARD)));
xpbar.setDirty(true);
SpoutManager.getPlayer(player).getMainScreen().setDirty(true);
}
/**
* Update XP bar for Retro styles.
*
* @param player Player whose XP bar to update
* @param PP Profile of the given player
*/
private void updateXpBarRetro(Player player, PlayerProfile PP) {
if (!SpoutConfig.getInstance().getXPBarEnabled()) {
return;
}
SkillType theType = getType(PP);
if (theType == null) { //Can this ever actually BE null? (Yes, it's null when the player has just logged in. It's not null when they gain XP in anything)
return;
}
Color color = getRetroColor(theType);
xpicon.setUrl(Misc.getCapitalized(theType.toString()) + "_r.png");
xpfill.setBottomColor(color);
xpfill.setTopColor(color);
xpfill.setWidth(getXpInc(PP.getSkillXpLevel(theType), PP.getXpToLevel(theType), HUDType.RETRO));
xpfill.setDirty(true);
SpoutManager.getPlayer(player).getMainScreen().setDirty(true);
}
private static Color getRetroColor(SkillType type) {
switch (type) {
case ACROBATICS:
return new Color((float) SpoutConfig.getInstance().getRetroHUDAcrobaticsRed(), (float) SpoutConfig.getInstance().getRetroHUDAcrobaticsGreen(), (float) SpoutConfig.getInstance().getRetroHUDAcrobaticsBlue(), 1f);
case ARCHERY:
return new Color((float) SpoutConfig.getInstance().getRetroHUDArcheryRed(), (float) SpoutConfig.getInstance().getRetroHUDArcheryGreen(), (float) SpoutConfig.getInstance().getRetroHUDArcheryBlue(), 1f);
case AXES:
return new Color((float) SpoutConfig.getInstance().getRetroHUDAxesRed(), (float) SpoutConfig.getInstance().getRetroHUDAxesGreen(), (float) SpoutConfig.getInstance().getRetroHUDAxesBlue(), 1f);
case EXCAVATION:
return new Color((float) SpoutConfig.getInstance().getRetroHUDExcavationRed(), (float) SpoutConfig.getInstance().getRetroHUDExcavationGreen(), (float) SpoutConfig.getInstance().getRetroHUDExcavationBlue(), 1f);
case HERBALISM:
return new Color((float) SpoutConfig.getInstance().getRetroHUDHerbalismRed(), (float) SpoutConfig.getInstance().getRetroHUDHerbalismGreen(), (float) SpoutConfig.getInstance().getRetroHUDHerbalismBlue(), 1f);
case MINING:
return new Color((float) SpoutConfig.getInstance().getRetroHUDMiningRed(), (float) SpoutConfig.getInstance().getRetroHUDMiningGreen(), (float) SpoutConfig.getInstance().getRetroHUDMiningBlue(), 1f);
case REPAIR:
return new Color((float) SpoutConfig.getInstance().getRetroHUDRepairRed(), (float) SpoutConfig.getInstance().getRetroHUDRepairGreen(), (float) SpoutConfig.getInstance().getRetroHUDRepairBlue(), 1f);
case SWORDS:
return new Color((float) SpoutConfig.getInstance().getRetroHUDSwordsRed(), (float) SpoutConfig.getInstance().getRetroHUDSwordsGreen(), (float) SpoutConfig.getInstance().getRetroHUDSwordsBlue(), 1f);
case TAMING:
return new Color((float) SpoutConfig.getInstance().getRetroHUDTamingRed(), (float) SpoutConfig.getInstance().getRetroHUDTamingGreen(), (float) SpoutConfig.getInstance().getRetroHUDTamingBlue(), 1f);
case UNARMED:
return new Color((float) SpoutConfig.getInstance().getRetroHUDUnarmedRed(), (float) SpoutConfig.getInstance().getRetroHUDUnarmedGreen(), (float) SpoutConfig.getInstance().getRetroHUDUnarmedBlue(), 1f);
case WOODCUTTING:
return new Color((float) SpoutConfig.getInstance().getRetroHUDWoodcuttingRed(), (float) SpoutConfig.getInstance().getRetroHUDWoodcuttingGreen(), (float) SpoutConfig.getInstance().getRetroHUDWoodcuttingBlue(), 1f);
case FISHING:
return new Color((float) SpoutConfig.getInstance().getRetroHUDFishingRed(), (float) SpoutConfig.getInstance().getRetroHUDFishingGreen(), (float) SpoutConfig.getInstance().getRetroHUDFishingBlue(), 1f);
default:
return new Color(0.3f, 0.3f, 0.75f, 1f);
}
}
private static String getUrlBar(Integer number) {
char[] num = number.toString().toCharArray();
switch (num.length) {
case 1:
return "xpbar_inc00" + number + ".png";
case 2:
return "xpbar_inc0" + number + ".png";
default:
return "xpbar_inc" + number + ".png";
}
}
private static Integer getXpInc(int skillxp, int xptolevel, HUDType hud) {
double percentage = (double) skillxp / xptolevel;
double inc;
switch (hud) {
case RETRO:
inc = 0.0079365079365079;
break;
case STANDARD:
inc = 0.0039370078740157;
break;
default:
return 1;
}
return (int) (percentage / inc);
}
private static SkillType getType(PlayerProfile PP) {
if (PP.getXpBarLocked()) {
return PP.getSkillLock();
}
else {
return PP.getLastGained();
}
}
}

View File

@@ -0,0 +1,12 @@
package com.gmail.nossr50.datatypes;
public enum HudType {
DISABLED,
STANDARD,
SMALL,
RETRO;
public HudType getNext() {
return values()[(ordinal() + 1) % values().length];
}
}

View File

@@ -0,0 +1,235 @@
package com.gmail.nossr50.datatypes;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.mods.CustomTool;
import com.gmail.nossr50.events.experience.McMMOPlayerXpGainEvent;
import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.ModChecks;
import com.gmail.nossr50.util.Users;
public class McMMOPlayer {
private Player player;
private PlayerProfile profile;
private Party party;
private Party invite;
public McMMOPlayer (Player player) {
String playerName = player.getName();
this.player = player;
this.profile = new PlayerProfile(playerName, true);
this.party = PartyManager.getInstance().getPlayerParty(playerName);
}
/**
* Gets the power level of this player.
*
* @return the power level of the player
*/
public int getPowerLevel() {
int powerLevel = 0;
for (SkillType type : SkillType.values()) {
if (type.getPermissions(player)) {
powerLevel += profile.getSkillLevel(type);
}
}
return powerLevel;
}
/**
* Calculate the party XP modifier.
*
* @param skillType Type of skill to check
* @return the party bonus multiplier
*/
private double calculatePartyXPModifier(SkillType skillType) {
double bonusModifier = 0.0;
for (Player member : party.getOnlineMembers()) {
if (party.getLeader().equals(member.getName())) {
if (Misc.isNear(player.getLocation(), member.getLocation(), 25.0)) {
PlayerProfile partyLeader = Users.getProfile(member);
int leaderSkill = partyLeader.getSkillLevel(skillType);
int playerSkill = profile.getSkillLevel(skillType);
if (leaderSkill >= playerSkill) {
int difference = leaderSkill - playerSkill;
bonusModifier = (difference * 0.75) / 100.0;
}
}
}
}
return bonusModifier;
}
/**
* Adds XP to the player, doesn't calculate for XP Rate
*
* @param skillType The skill to add XP to
* @param newValue The amount of XP to add
*/
public void addXPOverride(SkillType skillType, int xp) {
if (skillType.equals(SkillType.ALL)) {
for (SkillType type : SkillType.values()) {
if (type.equals(SkillType.ALL)) {
continue;
}
mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerXpGainEvent(player, type, xp));
profile.setSkillXPLevel(type, profile.getSkillXpLevel(type) + xp);
}
}
else {
mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerXpGainEvent(player, skillType, xp));
profile.setSkillXPLevel(skillType, profile.getSkillXpLevel(skillType) + xp);
SpoutHud spoutHud = profile.getSpoutHud();
if (spoutHud != null) {
spoutHud.setLastGained(skillType);
}
}
}
/**
* Adds XP to the player, this ignores skill modifiers.
*
* @param skillType The skill to add XP to
* @param newValue The amount of XP to add
*/
public void addXPOverrideBonus(SkillType skillType, int xp) {
int modifiedXp = (int)Math.floor(xp * Config.getInstance().xpGainMultiplier);
addXPOverride(skillType, modifiedXp);
}
/**
* Adds XP to the player, this is affected by skill modifiers and XP Rate and Permissions
*
* @param skillType The skill to add XP to
* @param newvalue The amount of XP to add
*/
public void addXP(SkillType skillType, int newValue) {
if (player.getGameMode().equals(GameMode.CREATIVE)) {
return;
}
double bonusModifier = 0;
if (inParty()) {
bonusModifier = calculatePartyXPModifier(skillType);
}
int xp = (int)Math.floor((newValue / skillType.getXpModifier()) * Config.getInstance().xpGainMultiplier);
if (bonusModifier > 0) {
if (bonusModifier >= 2) {
bonusModifier = 2;
}
double trueBonus = bonusModifier * xp;
xp += trueBonus;
}
if (Config.getInstance().getToolModsEnabled()) {
ItemStack item = player.getItemInHand();
CustomTool tool = ModChecks.getToolFromItemStack(item);
if (tool != null) {
xp = (int) (xp * tool.getXpMultiplier());
}
}
if (player.hasPermission("mcmmo.perks.xp.quadruple")) {
xp = xp * 4;
}
else if (player.hasPermission("mcmmo.perks.xp.triple")) {
xp = xp * 3;
}
else if (player.hasPermission("mcmmo.perks.xp.150percentboost")) {
xp = (int) (xp * 2.5);
}
else if (player.hasPermission("mcmmo.perks.xp.double")) {
xp = xp * 2;
}
else if (player.hasPermission("mcmmo.perks.xp.50percentboost")) {
xp = (int) (xp * 1.5);
}
mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerXpGainEvent(player, skillType, xp));
profile.setSkillXPLevel(skillType, profile.getSkillXpLevel(skillType) + xp);
SpoutHud spoutHud = profile.getSpoutHud();
if (spoutHud != null) {
spoutHud.setLastGained(skillType);
}
}
// Players & Profiles
public Player getPlayer() {
return player;
}
public void setPlayer(Player player) {
this.player = player;
}
public PlayerProfile getProfile() {
return profile;
}
// Party Stuff
public void setInvite(Party invite) {
this.invite = invite;
}
public Party getInvite() {
return invite;
}
public boolean hasPartyInvite() {
if (invite != null) {
return true;
}
else {
return false;
}
}
public void setParty(Party party) {
this.party = party;
}
public Party getParty() {
return party;
}
public boolean inParty() {
if (party != null) {
return true;
}
else {
return false;
}
}
public void removeParty() {
party = null;
}
public void removeInvite() {
invite = null;
}
}

View File

@@ -7,28 +7,21 @@ import java.io.FileWriter;
import java.util.ArrayList;
import java.util.HashMap;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.SpoutConfig;
import com.gmail.nossr50.datatypes.mods.CustomTool;
import com.gmail.nossr50.events.experience.McMMOPlayerXpGainEvent;
import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.Database;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.ModChecks;
import com.gmail.nossr50.util.Users;
public class PlayerProfile {
private String playerName;
/* HUD */
private HUDType hud;
private int xpbarinc;
private SkillType lastgained;
private SkillType skillLock;
private SpoutHud spoutHud;
private HudType hudType = SpoutConfig.getInstance().defaultHudType;
/* Party Stuff */
private Party party;
@@ -36,7 +29,7 @@ public class PlayerProfile {
/* Toggles */
private boolean loaded;
private boolean partyhud = true, spoutcraft, xpbarlocked;
private boolean placedAnvil;
private boolean partyChatMode, adminChatMode;
private boolean godMode;
@@ -45,29 +38,24 @@ public class PlayerProfile {
superBreakerInformed = true, blastMiningInformed = true, serratedStrikesInformed = true, treeFellerInformed = true;
private boolean hoePreparationMode, shovelPreparationMode, swordsPreparationMode, fistsPreparationMode,
pickaxePreparationMode, axePreparationMode;
private boolean abilityuse = true;
private boolean abilityUse = true;
/* Timestamps */
private int recentlyHurt;
private int respawnATS;
/* mySQL STUFF */
private int userid;
private int userId;
HashMap<SkillType, Integer> skills = new HashMap<SkillType, Integer>(); //Skills and Levels
private HashMap<SkillType, Integer> skills = new HashMap<SkillType, Integer>(); //Skills and Levels
HashMap<SkillType, Integer> skillsXp = new HashMap<SkillType, Integer>(); //Skills and XP
HashMap<AbilityType, Integer> skillsDATS = new HashMap<AbilityType, Integer>();
HashMap<ToolType, Integer> toolATS = new HashMap<ToolType, Integer>();
private Player player;
private String playerName;
private final static String location = mcMMO.usersFile;
private final static String location = mcMMO.getUsersFile();
public PlayerProfile(Player player, String playerName, boolean addNew) {
hud = SpoutConfig.getInstance().defaulthud;
this.player = player;
public PlayerProfile(String playerName, boolean addNew) {
this.playerName = playerName;
party = PartyManager.getInstance().getPlayerParty(playerName);
for (AbilityType abilityType : AbilityType.values()) {
@@ -93,101 +81,113 @@ public class PlayerProfile {
}
}
public Player getPlayer() {
return player;
}
public String getPlayerName() {
return playerName;
}
public void setPlayer(Player player) {
this.player = player;
this.playerName = player.getName();
}
public boolean loadMySQL() {
userid = mcMMO.database.getInt("SELECT id FROM " + Config.getInstance().getMySQLTablePrefix() + "users WHERE user = '" + playerName + "'");
Database database = mcMMO.getPlayerDatabase();
String tablePrefix = Config.getInstance().getMySQLTablePrefix();
if (userid == 0) {
userId = database.getInt("SELECT id FROM " + tablePrefix + "users WHERE user = '" + playerName + "'");
if (userId == 0) {
return false;
}
else {
HashMap<Integer, ArrayList<String>> huds = mcMMO.database.read("SELECT hudtype FROM " + Config.getInstance().getMySQLTablePrefix() + "huds WHERE user_id = " + userid);
HashMap<Integer, ArrayList<String>> huds = database.read("SELECT hudtype FROM " + tablePrefix + "huds WHERE user_id = " + userId);
if (huds.get(1) == null) {
mcMMO.database.write("INSERT INTO " + Config.getInstance().getMySQLTablePrefix() + "huds (user_id) VALUES (" + userid + ")");
database.write("INSERT INTO " + tablePrefix + "huds (user_id) VALUES (" + userId + ")");
}
else {
if (huds.get(1).get(0) != null) {
for (HUDType x : HUDType.values()) {
if (x.toString().equals(huds.get(1).get(0))) {
hud = x;
}
for (HudType type : HudType.values()) {
if (type.toString().equals(huds.get(1).get(0))) {
hudType = type;
}
}
else {
hud = SpoutConfig.getInstance().defaulthud;
}
}
/*
* I'm still learning MySQL, this is a fix for adding a new table
* its not pretty but it works
*/
HashMap<Integer, ArrayList<String>> cooldowns = mcMMO.database.read("SELECT mining, woodcutting, unarmed, herbalism, excavation, swords, axes, blast_mining FROM " + Config.getInstance().getMySQLTablePrefix() + "cooldowns WHERE user_id = " + userid);
HashMap<Integer, ArrayList<String>> cooldowns = database.read("SELECT mining, woodcutting, unarmed, herbalism, excavation, swords, axes, blast_mining FROM " + tablePrefix + "cooldowns WHERE user_id = " + userId);
ArrayList<String> cooldownValues = cooldowns.get(1);
if(cooldowns.get(1) == null) {
mcMMO.database.write("INSERT INTO " + Config.getInstance().getMySQLTablePrefix() + "cooldowns (user_id) VALUES (" + userid + ")");
if (cooldownValues == null) {
database.write("INSERT INTO " + tablePrefix + "cooldowns (user_id) VALUES (" + userId + ")");
mcMMO.p.getLogger().warning(playerName + "does not exist in the cooldown table. Their cooldowns will be reset.");
}
else {
skillsDATS.put(AbilityType.SUPER_BREAKER, Integer.valueOf(cooldowns.get(1).get(0)));
skillsDATS.put(AbilityType.TREE_FELLER, Integer.valueOf(cooldowns.get(1).get(1)));
skillsDATS.put(AbilityType.BERSERK, Integer.valueOf(cooldowns.get(1).get(2)));
skillsDATS.put(AbilityType.GREEN_TERRA, Integer.valueOf(cooldowns.get(1).get(3)));
skillsDATS.put(AbilityType.GIGA_DRILL_BREAKER, Integer.valueOf(cooldowns.get(1).get(4)));
skillsDATS.put(AbilityType.SERRATED_STRIKES, Integer.valueOf(cooldowns.get(1).get(5)));
skillsDATS.put(AbilityType.SKULL_SPLIITER, Integer.valueOf(cooldowns.get(1).get(6)));
skillsDATS.put(AbilityType.BLAST_MINING, Integer.valueOf(cooldowns.get(1).get(7)));
skillsDATS.put(AbilityType.SUPER_BREAKER, Integer.valueOf(cooldownValues.get(0)));
skillsDATS.put(AbilityType.TREE_FELLER, Integer.valueOf(cooldownValues.get(1)));
skillsDATS.put(AbilityType.BERSERK, Integer.valueOf(cooldownValues.get(2)));
skillsDATS.put(AbilityType.GREEN_TERRA, Integer.valueOf(cooldownValues.get(3)));
skillsDATS.put(AbilityType.GIGA_DRILL_BREAKER, Integer.valueOf(cooldownValues.get(4)));
skillsDATS.put(AbilityType.SERRATED_STRIKES, Integer.valueOf(cooldownValues.get(5)));
skillsDATS.put(AbilityType.SKULL_SPLIITER, Integer.valueOf(cooldownValues.get(6)));
skillsDATS.put(AbilityType.BLAST_MINING, Integer.valueOf(cooldownValues.get(7)));
}
HashMap<Integer, ArrayList<String>> stats = database.read("SELECT taming, mining, repair, woodcutting, unarmed, herbalism, excavation, archery, swords, axes, acrobatics, fishing FROM " + tablePrefix + "skills WHERE user_id = " + userId);
ArrayList<String> statValues = stats.get(1);
if (statValues == null) {
database.write("INSERT INTO " + tablePrefix + "skills (user_id) VALUES (" + userId + ")");
mcMMO.p.getLogger().warning(playerName + "does not exist in the skills table. Their stats will be reset.");
}
else {
skills.put(SkillType.TAMING, Integer.valueOf(statValues.get(0)));
skills.put(SkillType.MINING, Integer.valueOf(statValues.get(1)));
skills.put(SkillType.REPAIR, Integer.valueOf(statValues.get(2)));
skills.put(SkillType.WOODCUTTING, Integer.valueOf(statValues.get(3)));
skills.put(SkillType.UNARMED, Integer.valueOf(statValues.get(4)));
skills.put(SkillType.HERBALISM, Integer.valueOf(statValues.get(5)));
skills.put(SkillType.EXCAVATION, Integer.valueOf(statValues.get(6)));
skills.put(SkillType.ARCHERY, Integer.valueOf(statValues.get(7)));
skills.put(SkillType.SWORDS, Integer.valueOf(statValues.get(8)));
skills.put(SkillType.AXES, Integer.valueOf(statValues.get(9)));
skills.put(SkillType.ACROBATICS, Integer.valueOf(statValues.get(10)));
skills.put(SkillType.FISHING, Integer.valueOf(statValues.get(11)));
}
HashMap<Integer, ArrayList<String>> experience = database.read("SELECT taming, mining, repair, woodcutting, unarmed, herbalism, excavation, archery, swords, axes, acrobatics, fishing FROM " + tablePrefix + "experience WHERE user_id = " + userId);
ArrayList<String> experienceValues = experience.get(1);
if (experienceValues == null) {
database.write("INSERT INTO " + tablePrefix + "experience (user_id) VALUES (" + userId + ")");
mcMMO.p.getLogger().warning(playerName + "does not exist in the experience table. Their experience will be reset.");
}
else {
skillsXp.put(SkillType.TAMING, Integer.valueOf(experienceValues.get(0)));
skillsXp.put(SkillType.MINING, Integer.valueOf(experienceValues.get(1)));
skillsXp.put(SkillType.REPAIR, Integer.valueOf(experienceValues.get(2)));
skillsXp.put(SkillType.WOODCUTTING, Integer.valueOf(experienceValues.get(3)));
skillsXp.put(SkillType.UNARMED, Integer.valueOf(experienceValues.get(4)));
skillsXp.put(SkillType.HERBALISM, Integer.valueOf(experienceValues.get(5)));
skillsXp.put(SkillType.EXCAVATION, Integer.valueOf(experienceValues.get(6)));
skillsXp.put(SkillType.ARCHERY, Integer.valueOf(experienceValues.get(7)));
skillsXp.put(SkillType.SWORDS, Integer.valueOf(experienceValues.get(8)));
skillsXp.put(SkillType.AXES, Integer.valueOf(experienceValues.get(9)));
skillsXp.put(SkillType.ACROBATICS, Integer.valueOf(experienceValues.get(10)));
skillsXp.put(SkillType.FISHING, Integer.valueOf(experienceValues.get(11)));
}
HashMap<Integer, ArrayList<String>> stats = mcMMO.database.read("SELECT taming, mining, repair, woodcutting, unarmed, herbalism, excavation, archery, swords, axes, acrobatics, fishing FROM "+Config.getInstance().getMySQLTablePrefix()+"skills WHERE user_id = " + userid);
skills.put(SkillType.TAMING, Integer.valueOf(stats.get(1).get(0)));
skills.put(SkillType.MINING, Integer.valueOf(stats.get(1).get(1)));
skills.put(SkillType.REPAIR, Integer.valueOf(stats.get(1).get(2)));
skills.put(SkillType.WOODCUTTING, Integer.valueOf(stats.get(1).get(3)));
skills.put(SkillType.UNARMED, Integer.valueOf(stats.get(1).get(4)));
skills.put(SkillType.HERBALISM, Integer.valueOf(stats.get(1).get(5)));
skills.put(SkillType.EXCAVATION, Integer.valueOf(stats.get(1).get(6)));
skills.put(SkillType.ARCHERY, Integer.valueOf(stats.get(1).get(7)));
skills.put(SkillType.SWORDS, Integer.valueOf(stats.get(1).get(8)));
skills.put(SkillType.AXES, Integer.valueOf(stats.get(1).get(9)));
skills.put(SkillType.ACROBATICS, Integer.valueOf(stats.get(1).get(10)));
skills.put(SkillType.FISHING, Integer.valueOf(stats.get(1).get(11)));
HashMap<Integer, ArrayList<String>> experience = mcMMO.database.read("SELECT taming, mining, repair, woodcutting, unarmed, herbalism, excavation, archery, swords, axes, acrobatics, fishing FROM "+Config.getInstance().getMySQLTablePrefix()+"experience WHERE user_id = " + userid);
skillsXp.put(SkillType.TAMING, Integer.valueOf(experience.get(1).get(0)));
skillsXp.put(SkillType.MINING, Integer.valueOf(experience.get(1).get(1)));
skillsXp.put(SkillType.REPAIR, Integer.valueOf(experience.get(1).get(2)));
skillsXp.put(SkillType.WOODCUTTING, Integer.valueOf(experience.get(1).get(3)));
skillsXp.put(SkillType.UNARMED, Integer.valueOf(experience.get(1).get(4)));
skillsXp.put(SkillType.HERBALISM, Integer.valueOf(experience.get(1).get(5)));
skillsXp.put(SkillType.EXCAVATION, Integer.valueOf(experience.get(1).get(6)));
skillsXp.put(SkillType.ARCHERY, Integer.valueOf(experience.get(1).get(7)));
skillsXp.put(SkillType.SWORDS, Integer.valueOf(experience.get(1).get(8)));
skillsXp.put(SkillType.AXES, Integer.valueOf(experience.get(1).get(9)));
skillsXp.put(SkillType.ACROBATICS, Integer.valueOf(experience.get(1).get(10)));
skillsXp.put(SkillType.FISHING, Integer.valueOf(experience.get(1).get(11)));
loaded = true;
return true;
}
}
public void addMySQLPlayer() {
mcMMO.database.write("INSERT INTO " + Config.getInstance().getMySQLTablePrefix() + "users (user, lastlogin) VALUES ('" + playerName + "'," + System.currentTimeMillis() / 1000 + ")");
userid = mcMMO.database.getInt("SELECT id FROM "+Config.getInstance().getMySQLTablePrefix() + "users WHERE user = '" + playerName + "'");
mcMMO.database.write("INSERT INTO " + Config.getInstance().getMySQLTablePrefix() + "cooldowns (user_id) VALUES (" + userid + ")");
mcMMO.database.write("INSERT INTO " + Config.getInstance().getMySQLTablePrefix() + "skills (user_id) VALUES (" + userid + ")");
mcMMO.database.write("INSERT INTO " + Config.getInstance().getMySQLTablePrefix() + "experience (user_id) VALUES (" + userid + ")");
Database database = mcMMO.getPlayerDatabase();
String tablePrefix = Config.getInstance().getMySQLTablePrefix();
database.write("INSERT INTO " + tablePrefix + "users (user, lastlogin) VALUES ('" + playerName + "'," + System.currentTimeMillis() / 1000 + ")");
userId = database.getInt("SELECT id FROM "+tablePrefix + "users WHERE user = '" + playerName + "'");
database.write("INSERT INTO " + tablePrefix + "cooldowns (user_id) VALUES (" + userId + ")");
database.write("INSERT INTO " + tablePrefix + "skills (user_id) VALUES (" + userId + ")");
database.write("INSERT INTO " + tablePrefix + "experience (user_id) VALUES (" + userId + ")");
}
public boolean load() {
@@ -264,9 +264,9 @@ public class PlayerProfile {
if (character.length > 32)
skillsDATS.put(AbilityType.SUPER_BREAKER, Integer.valueOf(character[32]));
if (character.length > 33) {
for (HUDType x : HUDType.values()) {
if (x.toString().equalsIgnoreCase(character[33])) {
hud = x;
for (HudType type : HudType.values()) {
if (type.toString().equalsIgnoreCase(character[33])) {
hudType = type;
}
}
}
@@ -285,7 +285,7 @@ public class PlayerProfile {
in.close();
} catch (Exception e) {
mcMMO.p.getLogger().severe("Exception while reading " + location + " (Are you sure you formatted it correctly?)" + e.toString());
e.printStackTrace();
}
return false;
}
@@ -295,9 +295,12 @@ public class PlayerProfile {
// if we are using mysql save to database
if (Config.getInstance().getUseMySQL()) {
mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "huds SET hudtype = '" + hud.toString() + "' WHERE user_id = " + userid);
mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "users SET lastlogin = " + timestamp.intValue() + " WHERE id = " + userid);
mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "cooldowns SET "
Database database = mcMMO.getPlayerDatabase();
String tablePrefix = Config.getInstance().getMySQLTablePrefix();
database.write("UPDATE " + tablePrefix + "huds SET hudtype = '" + hudType.toString() + "' WHERE user_id = " + userId);
database.write("UPDATE " + tablePrefix + "users SET lastlogin = " + timestamp.intValue() + " WHERE id = " + userId);
database.write("UPDATE " + tablePrefix + "cooldowns SET "
+ " mining = " + skillsDATS.get(AbilityType.SUPER_BREAKER)
+ ", woodcutting = " + skillsDATS.get(AbilityType.TREE_FELLER)
+ ", unarmed = " + skillsDATS.get(AbilityType.BERSERK)
@@ -306,8 +309,8 @@ public class PlayerProfile {
+ ", swords = " + skillsDATS.get(AbilityType.SERRATED_STRIKES)
+ ", axes = " + skillsDATS.get(AbilityType.SKULL_SPLIITER)
+ ", blast_mining = " + skillsDATS.get(AbilityType.BLAST_MINING)
+ " WHERE user_id = " + userid);
mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "skills SET "
+ " WHERE user_id = " + userId);
database.write("UPDATE " + tablePrefix + "skills SET "
+ " taming = " + skills.get(SkillType.TAMING)
+ ", mining = " + skills.get(SkillType.MINING)
+ ", repair = " + skills.get(SkillType.REPAIR)
@@ -320,8 +323,8 @@ public class PlayerProfile {
+ ", axes = " + skills.get(SkillType.AXES)
+ ", acrobatics = " + skills.get(SkillType.ACROBATICS)
+ ", fishing = " + skills.get(SkillType.FISHING)
+ " WHERE user_id = " + userid);
mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "experience SET "
+ " WHERE user_id = " + userId);
database.write("UPDATE " + tablePrefix + "experience SET "
+ " taming = " + skillsXp.get(SkillType.TAMING)
+ ", mining = " + skillsXp.get(SkillType.MINING)
+ ", repair = " + skillsXp.get(SkillType.REPAIR)
@@ -334,7 +337,7 @@ public class PlayerProfile {
+ ", axes = " + skillsXp.get(SkillType.AXES)
+ ", acrobatics = " + skillsXp.get(SkillType.ACROBATICS)
+ ", fishing = " + skillsXp.get(SkillType.FISHING)
+ " WHERE user_id = " + userid);
+ " WHERE user_id = " + userId);
}
else {
// otherwise save to flatfile
@@ -349,7 +352,7 @@ public class PlayerProfile {
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)) {
if (!line.split(":")[0].equals(playerName)) {
writer.append(line).append("\r\n");
}
else {
@@ -389,7 +392,7 @@ public class PlayerProfile {
writer.append(String.valueOf(skillsDATS.get(AbilityType.SERRATED_STRIKES)) + ":");
writer.append(String.valueOf(skillsDATS.get(AbilityType.SKULL_SPLIITER)) + ":");
writer.append(String.valueOf(skillsDATS.get(AbilityType.SUPER_BREAKER)) + ":");
writer.append(hud.toString() + ":");
writer.append(hudType.toString() + ":");
writer.append(skills.get(SkillType.FISHING) + ":");
writer.append(skillsXp.get(SkillType.FISHING) + ":");
writer.append(String.valueOf(skillsDATS.get(AbilityType.BLAST_MINING)) + ":");
@@ -404,7 +407,7 @@ public class PlayerProfile {
out.close();
}
catch (Exception e) {
mcMMO.p.getLogger().severe("Exception while writing to " + location + " (Are you sure you formatted it correctly?)" + e.toString());
e.printStackTrace();
}
}
}
@@ -449,7 +452,7 @@ public class PlayerProfile {
out.append(0 + ":"); //DATS
out.append(0 + ":"); //DATS
out.append(0 + ":"); //DATS
out.append(SpoutConfig.getInstance().defaulthud.toString() + ":");//HUD
out.append(SpoutConfig.getInstance().defaultHudType.toString() + ":");//HUD
out.append(0 + ":"); //Fishing
out.append(0 +":"); //FishingXP
out.append(0 + ":"); //Blast Mining
@@ -459,7 +462,7 @@ public class PlayerProfile {
out.newLine();
out.close();
} catch (Exception e) {
mcMMO.p.getLogger().severe("Exception while writing to " + location + " (Are you sure you formatted it correctly?)" + e.toString());
e.printStackTrace();
}
}
@@ -468,7 +471,7 @@ public class PlayerProfile {
*/
public int getMySQLuserId() {
return userid;
return userId;
}
public boolean isLoaded() {
@@ -503,61 +506,20 @@ public class PlayerProfile {
* HUD Stuff
*/
public void togglePartyHUD() {
partyhud = !partyhud;
public HudType getHudType() {
return hudType;
}
public boolean getPartyHUD() {
return partyhud;
public SpoutHud getSpoutHud() {
return spoutHud;
}
public void toggleSpoutEnabled() {
spoutcraft = !spoutcraft;
public void setSpoutHud(SpoutHud spoutHud) {
this.spoutHud = spoutHud;
}
public HUDType getHUDType() {
return hud;
}
public void setHUDType(HUDType type) {
hud = type;
save();
}
public void setXpBarLocked(boolean locked) {
xpbarlocked = locked;
}
public boolean getXpBarLocked() {
return xpbarlocked;
}
public void toggleXpBarLocked() {
xpbarlocked = !xpbarlocked;
}
public int getXpBarInc() {
return xpbarinc;
}
public void setXpBarInc(int newvalue) {
xpbarinc = newvalue;
}
public void setSkillLock(SkillType newvalue) {
skillLock = newvalue;
}
public SkillType getSkillLock() {
return skillLock;
}
public void setLastGained(SkillType newvalue) {
lastgained = newvalue;
}
public SkillType getLastGained() {
return lastgained;
public void setHudType(HudType hudType) {
this.hudType = hudType;
}
/*
@@ -853,11 +815,11 @@ public class PlayerProfile {
}
public boolean getAbilityUse() {
return abilityuse;
return abilityUse;
}
public void toggleAbilityUse() {
abilityuse = !abilityuse;
abilityUse = !abilityUse;
}
/*
@@ -934,96 +896,122 @@ public class PlayerProfile {
return skillsXp.get(skillType);
}
public void setSkillXPLevel(SkillType skillType, int newValue) {
skillsXp.put(skillType, newValue);
}
public void skillUp(SkillType skillType, int newValue) {
skills.put(skillType, skills.get(skillType) + newValue);
}
/**
* Adds XP to the player, doesn't calculate for XP Rate
*
* @param skillType The skill to add XP to
* @param newValue The amount of XP to add
*/
public void addXPOverride(SkillType skillType, int newValue) {
if (skillType.equals(SkillType.ALL)) {
for (SkillType x : SkillType.values()) {
if (x.equals(SkillType.ALL)) {
continue;
}
mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerXpGainEvent(player, x, newValue));
skillsXp.put(x, skillsXp.get(x) + newValue);
}
}
else {
mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerXpGainEvent(player, skillType, newValue));
skillsXp.put(skillType, skillsXp.get(skillType) + newValue);
lastgained = skillType;
}
public void resetSkill(SkillType skillType)
{
//do a single skilltype
if (skillType != SkillType.ALL)
skills.put(skillType, 0);
else //do them all
{
for(SkillType skill : SkillType.values()) //iterate over all items in the enumeration
{
if (skill != SkillType.ALL) // skip the "all" value
skills.put(skill, 0);
}
}
}
/**
* Adds XP to the player, this ignores skill modifiers.
*
* @param skillType The skill to add XP to
* @param newValue The amount of XP to add
*/
public void addXPOverrideBonus(SkillType skillType, int newValue) {
int xp = newValue * Config.getInstance().xpGainMultiplier;
addXPOverride(skillType, xp);
}
// /**
// * Adds XP to the player, doesn't calculate for XP Rate
// *
// * @param skillType The skill to add XP to
// * @param newValue The amount of XP to add
// */
// public void addXPOverride(SkillType skillType, int newValue) {
// if (skillType.equals(SkillType.ALL)) {
// for (SkillType x : SkillType.values()) {
// if (x.equals(SkillType.ALL)) {
// continue;
// }
//
// mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerXpGainEvent(player, x, newValue));
// skillsXp.put(x, skillsXp.get(x) + newValue);
// }
// }
// else {
// mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerXpGainEvent(player, skillType, newValue));
// skillsXp.put(skillType, skillsXp.get(skillType) + newValue);
// spoutHud.setLastGained(skillType);
// }
// }
/**
* Adds XP to the player, this is affected by skill modifiers and XP Rate and Permissions
*
* @param skillType The skill to add XP to
* @param newvalue The amount of XP to add
*/
public void addXP(SkillType skillType, int newValue) {
if (player.getGameMode().equals(GameMode.CREATIVE)) {
return;
}
// /**
// * Adds XP to the player, this ignores skill modifiers.
// *
// * @param skillType The skill to add XP to
// * @param newValue The amount of XP to add
// */
// public void addXPOverrideBonus(SkillType skillType, int newValue) {
// int xp = newValue * Config.getInstance().xpGainMultiplier;
// addXPOverride(skillType, xp);
// }
double bonusModifier = 0;
if (inParty()) {
bonusModifier = partyModifier(skillType);
}
int xp = (int) (newValue / skillType.getXpModifier()) * Config.getInstance().xpGainMultiplier;
if (bonusModifier > 0) {
if (bonusModifier >= 2) {
bonusModifier = 2;
}
double trueBonus = bonusModifier * xp;
xp += trueBonus;
}
if (Config.getInstance().getToolModsEnabled()) {
ItemStack item = player.getItemInHand();
CustomTool tool = ModChecks.getToolFromItemStack(item);
if (tool != null) {
xp = (int) (xp * tool.getXpMultiplier());
}
}
if (player.hasPermission("mcmmo.perks.xp.quadruple")) {
xp = xp * 4;
}
else if (player.hasPermission("mcmmo.perks.xp.triple")) {
xp = xp * 3;
}
else if (player.hasPermission("mcmmo.perks.xp.double")) {
xp = xp * 2;
}
mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerXpGainEvent(player, skillType, xp));
skillsXp.put(skillType, skillsXp.get(skillType) + xp);
lastgained = skillType;
}
// /**
// * Adds XP to the player, this is affected by skill modifiers and XP Rate and Permissions
// *
// * @param skillType The skill to add XP to
// * @param newvalue The amount of XP to add
// */
// public void addXP(SkillType skillType, int newValue) {
// if (player.getGameMode().equals(GameMode.CREATIVE)) {
// return;
// }
//
// double bonusModifier = 0;
//
// if (inParty()) {
// bonusModifier = partyModifier(skillType);
// }
//
// int xp = (int) (newValue / skillType.getXpModifier()) * Config.getInstance().xpGainMultiplier;
//
// if (bonusModifier > 0) {
// if (bonusModifier >= 2) {
// bonusModifier = 2;
// }
//
// double trueBonus = bonusModifier * xp;
// xp += trueBonus;
// }
//
// if (Config.getInstance().getToolModsEnabled()) {
// ItemStack item = player.getItemInHand();
// CustomTool tool = ModChecks.getToolFromItemStack(item);
//
// if (tool != null) {
// xp = (int) (xp * tool.getXpMultiplier());
// }
// }
//
// //TODO: Can we make this so we do perks by doing "mcmmo.perks.xp.[multiplier]" ?
// if (player.hasPermission("mcmmo.perks.xp.quadruple")) {
// xp = xp * 4;
// }
// else if (player.hasPermission("mcmmo.perks.xp.triple")) {
// xp = xp * 3;
// }
// else if (player.hasPermission("mcmmo.perks.xp.150percentboost")) {
// xp = (int) (xp * 2.5);
// }
// else if (player.hasPermission("mcmmo.perks.xp.double")) {
// xp = xp * 2;
// }
// else if (player.hasPermission("mcmmo.perks.xp.50percentboost")) {
// xp = (int) (xp * 1.5);
// }
//
// mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerXpGainEvent(player, skillType, xp));
// skillsXp.put(skillType, skillsXp.get(skillType) + xp);
// spoutHud.setLastGained(skillType);
// }
/**
* Remove XP from a skill.
@@ -1090,8 +1078,6 @@ public class PlayerProfile {
skills.put(skillType, skills.get(skillType) + levels);
skillsXp.put(skillType, 0);
}
save();
}
/**
@@ -1101,52 +1087,52 @@ public class PlayerProfile {
* @return the XP remaining until next level
*/
public int getXpToLevel(SkillType skillType) {
return 1020 + (skills.get(skillType) * Config.getInstance().getFormulaMultiplierCurve()); //Do we REALLY need to cast to int here?
return 1020 + (skills.get(skillType) * Config.getInstance().getFormulaMultiplierCurve());
}
/**
* Gets the power level of a player.
*
* @return the power level of the player
*/
public int getPowerLevel() {
int powerLevel = 0;
// /**
// * Gets the power level of a player.
// *
// * @return the power level of the player
// */
// public int getPowerLevel() {
// int powerLevel = 0;
//
// for (SkillType type : SkillType.values()) {
// if (type.getPermissions(player)) {
// powerLevel += getSkillLevel(type);
// }
// }
//
// return powerLevel;
// }
for (SkillType type : SkillType.values()) {
if (type.getPermissions(player)) {
powerLevel += getSkillLevel(type);
}
}
return powerLevel;
}
/**
* Calculate the party XP modifier.
*
* @param skillType Type of skill to check
* @return the party bonus multiplier
*/
private double partyModifier(SkillType skillType) {
double bonusModifier = 0.0;
for (Player member : party.getOnlineMembers()) {
if (party.getLeader().equals(member.getName())) {
if (Misc.isNear(player.getLocation(), member.getLocation(), 25.0)) {
PlayerProfile PartyLeader = Users.getProfile(member);
int leaderSkill = PartyLeader.getSkillLevel(skillType);
int playerSkill = getSkillLevel(skillType);
if (leaderSkill >= playerSkill) {
int difference = leaderSkill - playerSkill;
bonusModifier = (difference * 0.75) / 100.0;
}
}
}
}
return bonusModifier;
}
// /**
// * Calculate the party XP modifier.
// *
// * @param skillType Type of skill to check
// * @return the party bonus multiplier
// */
// private double partyModifier(SkillType skillType) {
// double bonusModifier = 0.0;
//
// for (Player member : party.getOnlineMembers()) {
// if (party.getLeader().equals(member.getName())) {
// if (Misc.isNear(player.getLocation(), member.getLocation(), 25.0)) {
// PlayerProfile PartyLeader = Users.getProfile(member);
// int leaderSkill = PartyLeader.getSkillLevel(skillType);
// int playerSkill = getSkillLevel(skillType);
//
// if (leaderSkill >= playerSkill) {
// int difference = leaderSkill - playerSkill;
// bonusModifier = (difference * 0.75) / 100.0;
// }
// }
// }
// }
//
// return bonusModifier;
// }
/*
* Party Stuff

View File

@@ -0,0 +1,102 @@
package com.gmail.nossr50.datatypes;
import org.bukkit.entity.Player;
import org.getspout.spoutapi.SpoutManager;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.SpoutConfig;
import com.gmail.nossr50.datatypes.popups.Menu;
import com.gmail.nossr50.datatypes.popups.XpBar;
public class SpoutHud {
private Player player;
private PlayerProfile profile;
private SkillType lastGained;
private SkillType skillLock;
private boolean xpBarLocked;
private Menu menu;
private XpBar xpBar;
public SpoutHud(McMMOPlayer mcMMOPlayer) {
this.player = mcMMOPlayer.getPlayer();
this.profile = mcMMOPlayer.getProfile();
initializeXpBar();
}
/**
* Initialize the HUD.
*/
public void initializeXpBar() {
if (SpoutConfig.getInstance().getXPBarEnabled()) {
if (xpBar != null) {
xpBar.removeWidgets();
}
xpBar = new XpBar(SpoutManager.getPlayer(player), profile.getHudType());
}
}
/**
* Update the XP bar.
*/
public void updateXpBar() {
SkillType skillType = xpBarLocked ? skillLock : lastGained;
if (skillType == null) {
return;
}
xpBar.update(skillType, profile);
}
public boolean isMenuOpened() {
return (menu != null) ? true : false;
}
public void openMenu() {
menu = new Menu(SpoutManager.getPlayer(player), profile);
}
public void onMenuClose() {
menu = null;
}
public void removeWidgets() {
if (menu != null) {
menu.close();
}
SpoutManager.getPlayer(player).getMainScreen().removeWidgets(mcMMO.p);
}
public SkillType getLastGained() {
return lastGained;
}
public void setLastGained(SkillType type) {
this.lastGained = type;
}
public boolean getXpBarLocked() {
return xpBarLocked;
}
public void setXpBarLocked(boolean locked) {
this.xpBarLocked = locked;
}
public void toggleXpBarLocked() {
xpBarLocked = !xpBarLocked;
}
public SkillType getSkillLock() {
return skillLock;
}
public void setSkillLock(SkillType type) {
this.skillLock = type;
}
}

View File

@@ -1,13 +0,0 @@
package com.gmail.nossr50.datatypes.buttons;
import org.getspout.spoutapi.gui.GenericButton;
public class ButtonEscape extends GenericButton {
public ButtonEscape() {
this.setText("EXIT");
this.setWidth(60);
this.setHeight(20);
this.setDirty(true);
}
}

View File

@@ -1,14 +0,0 @@
package com.gmail.nossr50.datatypes.buttons;
import com.gmail.nossr50.datatypes.PlayerProfile;
public class ButtonHUDStyle extends ButtonToggle {
public ButtonHUDStyle(PlayerProfile PP) {
super("HUD Type: ", PP.getHUDType().toString(), "Change your HUD style!"); //TODO: Needs more locale
}
public void updateText(PlayerProfile PP) {
super.updateText("HUD Type: ", PP.getHUDType().toString()); //TODO: Needs more locale
}
}

View File

@@ -1,14 +0,0 @@
package com.gmail.nossr50.datatypes.buttons;
import com.gmail.nossr50.datatypes.PlayerProfile;
public class ButtonPartyToggle extends ButtonToggle {
public ButtonPartyToggle(PlayerProfile PP) {
super("Party HUD: ", ((Boolean) PP.getPartyHUD()).toString(), "Toggle the Party HUD!"); //TODO: Needs more locale
}
public void updateText(PlayerProfile PP) {
super.updateText("Party HUD: ", ((Boolean) PP.getPartyHUD()).toString()); //TODO: Needs more locale
}
}

View File

@@ -1,19 +0,0 @@
package com.gmail.nossr50.datatypes.buttons;
import org.getspout.spoutapi.gui.GenericButton;
public class ButtonToggle extends GenericButton{
public ButtonToggle(String text1, String text2, String tooltip) {
this.setText(text1 + text2);
this.setTooltip(tooltip);
this.setWidth(120);
this.setHeight(20);
this.setDirty(true);
}
public void updateText(String text1, String text2) {
this.setText(text1 + text2);
this.setDirty(true);
}
}

View File

@@ -0,0 +1,24 @@
package com.gmail.nossr50.datatypes.buttons;
import org.getspout.spoutapi.gui.GenericButton;
public class McmmoButton extends GenericButton {
private Slot slot;
public McmmoButton(String text, String toolTip) {
this.setText(text);
this.setTooltip(toolTip);
}
public void connect(Slot slot) {
this.slot = slot;
}
public void activate() {
slot.activate();
}
public interface Slot {
public void activate();
}
}

View File

@@ -8,13 +8,17 @@ public class CustomBlock {
private int xpGain;
private int tier;
private ItemStack itemDrop;
private int minimumDropAmount;
private int maximumDropAmount;
public CustomBlock(ItemStack itemDrop, int tier, int xpGain, byte dataValue, int itemID) {
public CustomBlock(int minimumDropAmount, int maximumDropAmount, ItemStack itemDrop, int tier, int xpGain, byte dataValue, int itemID) {
this.itemID = itemID;
this.dataValue = dataValue;
this.xpGain = xpGain;
this.tier = tier;
this.itemDrop = itemDrop;
this.minimumDropAmount = minimumDropAmount;
this.maximumDropAmount = maximumDropAmount;
}
public int getItemID() {
@@ -56,4 +60,20 @@ public class CustomBlock {
public void setItemDrop(ItemStack itemDrop) {
this.itemDrop = itemDrop;
}
public int getMinimumDropAmount() {
return minimumDropAmount;
}
public void setMinimumDropAmount(int minimumDropAmount) {
this.minimumDropAmount = minimumDropAmount;
}
public int getMaximumDropAmount() {
return maximumDropAmount;
}
public void setMaximumDropAmount(int maximumDropAmount) {
this.maximumDropAmount = maximumDropAmount;
}
}

View File

@@ -0,0 +1,79 @@
package com.gmail.nossr50.datatypes.popups;
import org.bukkit.ChatColor;
import org.getspout.spoutapi.gui.GenericLabel;
import org.getspout.spoutapi.gui.GenericPopup;
import org.getspout.spoutapi.gui.InGameHUD;
import org.getspout.spoutapi.player.SpoutPlayer;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.HudType;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SpoutHud;
import com.gmail.nossr50.datatypes.buttons.McmmoButton;
import com.gmail.nossr50.datatypes.buttons.McmmoButton.Slot;
public class Menu extends GenericPopup {
private McmmoButton hudButton;
private McmmoButton escapeButton;
private GenericLabel titleLabel = new GenericLabel();
private GenericLabel escapeLabel = new GenericLabel();
private static int centerX = 427 / 2;
private static int centerY = 240 / 2;
public Menu(final SpoutPlayer spoutPlayer, final PlayerProfile playerProfile) {
//240, 427 are the bottom right
titleLabel.setText(ChatColor.GOLD + "~mcMMO Menu~"); //TODO: Needs more locale
titleLabel.setWidth(100);
titleLabel.setHeight(100);
titleLabel.setX(centerX - 35);
titleLabel.setY((centerY / 2) - 20);
escapeLabel.setText(ChatColor.GRAY + "Press ESCAPE to exit!"); //TODO: Needs more locale
escapeLabel.setWidth(100);
escapeLabel.setHeight(100);
escapeLabel.setX(titleLabel.getX() - 15);
escapeLabel.setY(titleLabel.getY() + 10);
hudButton = new McmmoButton("HUD Type: " + playerProfile.getHudType().toString(), "Change your HUD style!");
hudButton.setWidth(120);
hudButton.setHeight(20);
hudButton.setX(centerX - (hudButton.getWidth() / 2));
hudButton.setY(centerY / 2);
hudButton.connect(new Slot() {
@Override
public void activate() {
HudType nextHudType = playerProfile.getHudType().getNext();
SpoutHud spoutHud = playerProfile.getSpoutHud();
playerProfile.setHudType(nextHudType);
spoutHud.initializeXpBar();
spoutHud.updateXpBar();
hudButton.setText("HUD Type: " + nextHudType.toString());
hudButton.setDirty(true);
}
});
escapeButton = new McmmoButton("EXIT", null);
escapeButton.setWidth(60);
escapeButton.setHeight(20);
escapeButton.setX(centerX - (escapeButton.getWidth() / 2));
escapeButton.setY((centerY / 2) + (escapeButton.getHeight() * 2) + 5);
escapeButton.connect(new Slot() {
@Override
public void activate() {
spoutPlayer.getMainScreen().closePopup();
}
});
attachWidget(mcMMO.p, hudButton);
attachWidget(mcMMO.p, titleLabel);
attachWidget(mcMMO.p, escapeLabel);
attachWidget(mcMMO.p, escapeButton);
InGameHUD inGameHud = spoutPlayer.getMainScreen();
inGameHud.attachPopupScreen(this);
inGameHud.setDirty(true);
}
}

View File

@@ -1,58 +0,0 @@
package com.gmail.nossr50.datatypes.popups;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.getspout.spoutapi.gui.GenericLabel;
import org.getspout.spoutapi.gui.GenericPopup;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.buttons.ButtonEscape;
import com.gmail.nossr50.datatypes.buttons.ButtonHUDStyle;
public class PopupMMO extends GenericPopup {
private ButtonHUDStyle HUDButton = null;
private ButtonEscape EscapeButton = null;
private GenericLabel mcMMO_label = new GenericLabel();
private GenericLabel tip_escape = new GenericLabel();
private int center_x = 427 / 2;
private int center_y = 240 / 2;
public PopupMMO(Player player, PlayerProfile PP, mcMMO plugin) {
//240, 427 are the bottom right
mcMMO_label.setText(ChatColor.GOLD + "~mcMMO Menu~"); //TODO: Needs more locale
mcMMO_label.setX(center_x - 35);
mcMMO_label.setY((center_y / 2) - 20);
mcMMO_label.setDirty(true);
tip_escape.setText(ChatColor.GRAY + "Press ESCAPE to exit!"); //TODO: Needs more locale
tip_escape.setX(mcMMO_label.getX() - 15);
tip_escape.setY(mcMMO_label.getY() + 10);
tip_escape.setDirty(true);
HUDButton = new ButtonHUDStyle(PP);
HUDButton.setX(center_x - (HUDButton.getWidth() / 2));
HUDButton.setY(center_y / 2);
HUDButton.setDirty(true);
EscapeButton = new ButtonEscape();
EscapeButton.setX(center_x - (EscapeButton.getWidth() / 2));
EscapeButton.setY((center_y / 2) + (HUDButton.getHeight() * 2) + 5);
EscapeButton.setDirty(true);
this.attachWidget(plugin, HUDButton);
this.attachWidget(plugin, mcMMO_label);
this.attachWidget(plugin, tip_escape);
this.attachWidget(plugin, EscapeButton);
this.setDirty(true);
}
public void updateButtons(PlayerProfile PP) {
HUDButton.updateText(PP);
//PartyButton.updateText(PP);
this.setDirty(true);
}
}

View File

@@ -0,0 +1,320 @@
package com.gmail.nossr50.datatypes.popups;
import org.getspout.spoutapi.gui.Color;
import org.getspout.spoutapi.gui.GenericGradient;
import org.getspout.spoutapi.gui.GenericTexture;
import org.getspout.spoutapi.gui.InGameHUD;
import org.getspout.spoutapi.gui.RenderPriority;
import org.getspout.spoutapi.gui.Widget;
import org.getspout.spoutapi.player.SpoutPlayer;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.SpoutConfig;
import com.gmail.nossr50.datatypes.HudType;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.util.Misc;
public class XpBar {
private SpoutPlayer spoutPlayer;
private Widget xpBar;
private GenericGradient xpFill;
private GenericGradient xpBackground;
private GenericGradient xpIconBackground;
private GenericGradient xpIconBorder;
private GenericTexture xpIcon;
public XpBar(SpoutPlayer spoutPlayer, HudType hudType) {
this.spoutPlayer = spoutPlayer;
switch (hudType) {
case RETRO:
initializeXpBarRetro();
break;
case STANDARD:
initializeXpBarStandard();
break;
case SMALL:
initializeXpBarSmall();
break;
case DISABLED:
break;
}
spoutPlayer.getMainScreen().setDirty(true);
}
/**
* Initialize Retro XP bar.
*/
private void initializeXpBarRetro() {
Color border = new Color((float) SpoutConfig.getInstance().getRetroHUDXPBorderRed(), (float) SpoutConfig.getInstance().getRetroHUDXPBorderGreen(), (float) SpoutConfig.getInstance().getRetroHUDXPBorderBlue(), 1f);
Color green = new Color(0f, 1f, 0f, 1f);
Color background = new Color((float) SpoutConfig.getInstance().getRetroHUDXPBackgroundRed(), (float) SpoutConfig.getInstance().getRetroHUDXPBackgroundGreen(), (float) SpoutConfig.getInstance().getRetroHUDXPBackgroundBlue(), 1f);
xpBar = new GenericGradient();
xpFill = new GenericGradient();
xpBackground = new GenericGradient();
xpBar.setWidth(128);
xpBar.setHeight(4);
xpBar.setX(149);
xpBar.setY(10);
((GenericGradient) xpBar).setBottomColor(border);
((GenericGradient) xpBar).setTopColor(border);
xpBar.setPriority(RenderPriority.Highest);
spoutPlayer.getMainScreen().attachWidget(mcMMO.p, xpBar);
xpFill.setWidth(0);
xpFill.setHeight(2);
xpFill.setX(150);
xpFill.setY(11);
xpFill.setBottomColor(green);
xpFill.setTopColor(green);
xpFill.setPriority(RenderPriority.Lowest);
spoutPlayer.getMainScreen().attachWidget(mcMMO.p, xpFill);
xpBackground.setWidth(126);
xpBackground.setHeight(2);
xpBackground.setX(150);
xpBackground.setY(11);
xpBackground.setBottomColor(background);
xpBackground.setTopColor(background);
xpBackground.setPriority(RenderPriority.Low);
spoutPlayer.getMainScreen().attachWidget(mcMMO.p, xpBackground);
if (SpoutConfig.getInstance().getXPBarIconEnabled()) {
Color darkbg = new Color(0.2f, 0.2f, 0.2f, 1f);
xpIconBackground = new GenericGradient();
xpIconBorder = new GenericGradient();
xpIcon = new GenericTexture();
xpIconBackground.setBottomColor(darkbg);
xpIconBackground.setTopColor(darkbg);
xpIconBackground.setWidth(4);
xpIconBackground.setHeight(4);
xpIconBackground.setPriority(RenderPriority.High);
xpIconBackground.setX(142);
xpIconBackground.setY(10);
spoutPlayer.getMainScreen().attachWidget(mcMMO.p, xpIconBackground);
xpIconBorder.setBottomColor(border);
xpIconBorder.setTopColor(border);
xpIconBorder.setWidth(6);
xpIconBorder.setHeight(6);
xpIconBorder.setPriority(RenderPriority.Highest);
xpIconBorder.setX(141);
xpIconBorder.setY(9);
spoutPlayer.getMainScreen().attachWidget(mcMMO.p, xpIconBorder);
xpIcon.setWidth(6);
xpIcon.setHeight(6);
xpIcon.setX(141);
xpIcon.setY(9);
xpIcon.setPriority(RenderPriority.Normal);
xpIcon.setUrl("Icon_r.png");
spoutPlayer.getMainScreen().attachWidget(mcMMO.p, xpIcon);
}
}
/**
* Initialize Standard XP bar.
*/
private void initializeXpBarStandard() {
xpBar = new GenericTexture();
((GenericTexture) xpBar).setUrl("xpbar_inc000.png");
xpBar.setX(SpoutConfig.getInstance().getXPBarXPosition());
xpBar.setY(SpoutConfig.getInstance().getXPBarYPosition());
xpBar.setHeight(8);
xpBar.setWidth(256);
xpBar.setPriority(RenderPriority.Lowest);
spoutPlayer.getMainScreen().attachWidget(mcMMO.p, xpBar);
if (SpoutConfig.getInstance().getXPBarIconEnabled()) {
xpIcon = new GenericTexture();
xpIcon.setUrl("Icon.png");
xpIcon.setHeight(16);
xpIcon.setWidth(32);
xpIcon.setX(SpoutConfig.getInstance().getXPIconXPosition());
xpIcon.setY(SpoutConfig.getInstance().getXPIconYPosition());
xpIcon.setPriority(RenderPriority.High);
spoutPlayer.getMainScreen().attachWidget(mcMMO.p, xpIcon);
}
}
/**
* Initialize Small XP bar.
*/
private void initializeXpBarSmall() {
xpBar = new GenericTexture();
((GenericTexture)xpBar).setUrl("xpbar_inc000.png");
xpBar.setX(427 / 2 - 64);
xpBar.setY(SpoutConfig.getInstance().getXPBarYPosition());
xpBar.setHeight(4);
xpBar.setWidth(128);
xpBar.setPriority(RenderPriority.Lowest);
spoutPlayer.getMainScreen().attachWidget(mcMMO.p, xpBar);
if (SpoutConfig.getInstance().getXPBarIconEnabled()) {
xpIcon = new GenericTexture();
xpIcon.setUrl("Icon.png");
xpIcon.setHeight(8);
xpIcon.setWidth(16);
xpIcon.setX(427 / 2 - (8 + 64));
xpIcon.setY(SpoutConfig.getInstance().getXPIconYPosition() + 2);
xpIcon.setPriority(RenderPriority.High);
spoutPlayer.getMainScreen().attachWidget(mcMMO.p, xpIcon);
}
}
/**
* Update the XP bar.
*
* @param skillType
* @param playerProfile
*/
public void update(SkillType skillType, PlayerProfile playerProfile) {
switch (playerProfile.getHudType()) {
case RETRO:
updateXpBarRetro(skillType, playerProfile);
break;
case STANDARD:
case SMALL:
updateXpBarStandard(skillType, playerProfile);
break;
case DISABLED:
break;
}
}
/**
* Update XP bar for Standard & Small styles.
*
* @param skillType
* @param playerProfile
*/
private void updateXpBarStandard(SkillType skillType, PlayerProfile playerProfile) {
xpIcon.setUrl(Misc.getCapitalized(skillType.toString()) + ".png");
((GenericTexture) xpBar).setUrl(getUrlBar(getXpInc(playerProfile.getSkillXpLevel(skillType), playerProfile.getXpToLevel(skillType), HudType.STANDARD)));
spoutPlayer.getMainScreen().setDirty(true);
}
/**
* Update XP bar for Retro styles.
*
* @param skillType
*/
private void updateXpBarRetro(SkillType skillType, PlayerProfile playerProfile) {
Color color = getRetroColor(skillType);
xpIcon.setUrl(Misc.getCapitalized(skillType.toString()) + "_r.png");
xpFill.setBottomColor(color);
xpFill.setTopColor(color);
xpFill.setWidth(getXpInc(playerProfile.getSkillXpLevel(skillType), playerProfile.getXpToLevel(skillType), HudType.RETRO));
spoutPlayer.getMainScreen().setDirty(true);
}
private static Color getRetroColor(SkillType type) {
switch (type) {
case ACROBATICS:
return new Color((float) SpoutConfig.getInstance().getRetroHUDAcrobaticsRed(), (float) SpoutConfig.getInstance().getRetroHUDAcrobaticsGreen(), (float) SpoutConfig.getInstance().getRetroHUDAcrobaticsBlue(), 1f);
case ARCHERY:
return new Color((float) SpoutConfig.getInstance().getRetroHUDArcheryRed(), (float) SpoutConfig.getInstance().getRetroHUDArcheryGreen(), (float) SpoutConfig.getInstance().getRetroHUDArcheryBlue(), 1f);
case AXES:
return new Color((float) SpoutConfig.getInstance().getRetroHUDAxesRed(), (float) SpoutConfig.getInstance().getRetroHUDAxesGreen(), (float) SpoutConfig.getInstance().getRetroHUDAxesBlue(), 1f);
case EXCAVATION:
return new Color((float) SpoutConfig.getInstance().getRetroHUDExcavationRed(), (float) SpoutConfig.getInstance().getRetroHUDExcavationGreen(), (float) SpoutConfig.getInstance().getRetroHUDExcavationBlue(), 1f);
case HERBALISM:
return new Color((float) SpoutConfig.getInstance().getRetroHUDHerbalismRed(), (float) SpoutConfig.getInstance().getRetroHUDHerbalismGreen(), (float) SpoutConfig.getInstance().getRetroHUDHerbalismBlue(), 1f);
case MINING:
return new Color((float) SpoutConfig.getInstance().getRetroHUDMiningRed(), (float) SpoutConfig.getInstance().getRetroHUDMiningGreen(), (float) SpoutConfig.getInstance().getRetroHUDMiningBlue(), 1f);
case REPAIR:
return new Color((float) SpoutConfig.getInstance().getRetroHUDRepairRed(), (float) SpoutConfig.getInstance().getRetroHUDRepairGreen(), (float) SpoutConfig.getInstance().getRetroHUDRepairBlue(), 1f);
case SWORDS:
return new Color((float) SpoutConfig.getInstance().getRetroHUDSwordsRed(), (float) SpoutConfig.getInstance().getRetroHUDSwordsGreen(), (float) SpoutConfig.getInstance().getRetroHUDSwordsBlue(), 1f);
case TAMING:
return new Color((float) SpoutConfig.getInstance().getRetroHUDTamingRed(), (float) SpoutConfig.getInstance().getRetroHUDTamingGreen(), (float) SpoutConfig.getInstance().getRetroHUDTamingBlue(), 1f);
case UNARMED:
return new Color((float) SpoutConfig.getInstance().getRetroHUDUnarmedRed(), (float) SpoutConfig.getInstance().getRetroHUDUnarmedGreen(), (float) SpoutConfig.getInstance().getRetroHUDUnarmedBlue(), 1f);
case WOODCUTTING:
return new Color((float) SpoutConfig.getInstance().getRetroHUDWoodcuttingRed(), (float) SpoutConfig.getInstance().getRetroHUDWoodcuttingGreen(), (float) SpoutConfig.getInstance().getRetroHUDWoodcuttingBlue(), 1f);
case FISHING:
return new Color((float) SpoutConfig.getInstance().getRetroHUDFishingRed(), (float) SpoutConfig.getInstance().getRetroHUDFishingGreen(), (float) SpoutConfig.getInstance().getRetroHUDFishingBlue(), 1f);
default:
return new Color(0.3f, 0.3f, 0.75f, 1f);
}
}
private static String getUrlBar(Integer number) {
char[] num = number.toString().toCharArray();
switch (num.length) {
case 1:
return "xpbar_inc00" + number + ".png";
case 2:
return "xpbar_inc0" + number + ".png";
default:
return "xpbar_inc" + number + ".png";
}
}
private static Integer getXpInc(int skillXp, int xpToLevel, HudType hudType) {
double percentage = (double) skillXp / xpToLevel;
double inc;
switch (hudType) {
case RETRO:
inc = 0.0079365079365079;
break;
case STANDARD:
inc = 0.0039370078740157;
break;
default:
return 1;
}
return (int) (percentage / inc);
}
public void removeWidgets() {
InGameHUD inGameHud = spoutPlayer.getMainScreen();
if (xpBar != null) inGameHud.removeWidget(xpBar);
if (xpFill != null) inGameHud.removeWidget(xpFill);
if (xpBackground != null) inGameHud.removeWidget(xpBackground);
if (xpIconBackground != null) inGameHud.removeWidget(xpIconBackground);
if (xpIconBorder != null) inGameHud.removeWidget(xpIconBorder);
if (xpIcon != null) inGameHud.removeWidget(xpIcon);
}
}

View File

@@ -28,6 +28,7 @@ import com.gmail.nossr50.datatypes.ToolType;
import com.gmail.nossr50.events.fake.FakeBlockBreakEvent;
import com.gmail.nossr50.events.fake.FakeBlockDamageEvent;
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
import com.gmail.nossr50.runnables.StickyPistonTracker;
import com.gmail.nossr50.skills.gathering.Excavation;
import com.gmail.nossr50.skills.gathering.Herbalism;
import com.gmail.nossr50.skills.gathering.Mining;
@@ -99,11 +100,9 @@ public class BlockListener implements Listener {
*/
@EventHandler(priority = EventPriority.MONITOR)
public void onBlockPistonRetract(BlockPistonRetractEvent event) {
Block block = event.getRetractLocation().getBlock();
if (event.isSticky() && mcMMO.placeStore.isTrue(block)) {
mcMMO.placeStore.setFalse(block);
mcMMO.placeStore.setTrue(event.getBlock().getRelative(event.getDirection()));
if (event.isSticky()) {
//Needed only because under some circumstances Minecraft doesn't move the block
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new StickyPistonTracker(event), 0);
}
}
@@ -154,27 +153,32 @@ public class BlockListener implements Listener {
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
if (event instanceof FakeBlockBreakEvent) {
return;
}
Player player = event.getPlayer();
PlayerProfile PP = Users.getProfile(player);
PlayerProfile profile = Users.getProfile(player);
if (profile == null) {
return;
}
Block block = event.getBlock();
ItemStack inHand = player.getItemInHand();
Config configInstance = Config.getInstance();
Permissions permInstance = Permissions.getInstance();
if (event instanceof FakeBlockBreakEvent) {
return;
}
/* HERBALISM */
if (BlockChecks.canBeGreenTerra(block)) {
/* Green Terra */
if (PP.getToolPreparationMode(ToolType.HOE) && permInstance.greenTerra(player)) {
if (profile.getToolPreparationMode(ToolType.HOE) && permInstance.greenTerra(player)) {
Skills.abilityCheck(player, SkillType.HERBALISM);
}
/* Triple drops */
if (PP.getAbilityMode(AbilityType.GREEN_TERRA)) {
if (profile.getAbilityMode(AbilityType.GREEN_TERRA)) {
Herbalism.herbalismProcCheck(block, player, event, plugin);
}
@@ -206,15 +210,8 @@ public class BlockListener implements Listener {
WoodCutting.woodcuttingBlockCheck(player, block);
}
if (PP.getAbilityMode(AbilityType.TREE_FELLER) && permInstance.treeFeller(player) && ItemChecks.isAxe(inHand)) {
if (ModChecks.isCustomTool(inHand)) {
if (ModChecks.getToolFromItemStack(inHand).isAbilityEnabled()) {
WoodCutting.treeFeller(event);
}
}
else {
WoodCutting.treeFeller(event);
}
if (profile.getAbilityMode(AbilityType.TREE_FELLER) && permInstance.treeFeller(player) && ItemChecks.isAxe(inHand)) {
WoodCutting.treeFeller(event);
}
}
@@ -231,7 +228,7 @@ public class BlockListener implements Listener {
}
//Remove metadata when broken
if (mcMMO.placeStore.isTrue(block) && BlockChecks.shouldBeWatched(block)) {
if (BlockChecks.shouldBeWatched(block)) {
mcMMO.placeStore.setFalse(block);
}
@@ -271,7 +268,12 @@ public class BlockListener implements Listener {
final int LEAF_BLOWER_LEVEL = 100;
Player player = event.getPlayer();
PlayerProfile PP = Users.getProfile(player);
PlayerProfile profile = Users.getProfile(player);
if (profile == null) {
return;
}
ItemStack inHand = player.getItemInHand();
Block block = event.getBlock();
Material material = block.getType();
@@ -283,54 +285,39 @@ public class BlockListener implements Listener {
* ABILITY PREPARATION CHECKS
*/
if (BlockChecks.abilityBlockCheck(block)) {
if (PP.getToolPreparationMode(ToolType.HOE) && (BlockChecks.canBeGreenTerra(block) || BlockChecks.makeMossy(block))) {
if (profile.getToolPreparationMode(ToolType.HOE) && (BlockChecks.canBeGreenTerra(block) || BlockChecks.makeMossy(block))) {
Skills.abilityCheck(player, SkillType.HERBALISM);
}
else if (PP.getToolPreparationMode(ToolType.AXE) && BlockChecks.isLog(block) && permInstance.treeFeller(player)) { //TODO: Why are we checking the permissions here?
else if (profile.getToolPreparationMode(ToolType.AXE) && BlockChecks.isLog(block) && permInstance.treeFeller(player)) { //TODO: Why are we checking the permissions here?
Skills.abilityCheck(player, SkillType.WOODCUTTING);
}
else if (PP.getToolPreparationMode(ToolType.PICKAXE) && BlockChecks.canBeSuperBroken(block)) {
else if (profile.getToolPreparationMode(ToolType.PICKAXE) && BlockChecks.canBeSuperBroken(block)) {
Skills.abilityCheck(player, SkillType.MINING);
}
else if (PP.getToolPreparationMode(ToolType.SHOVEL) && BlockChecks.canBeGigaDrillBroken(block)) {
else if (profile.getToolPreparationMode(ToolType.SHOVEL) && BlockChecks.canBeGigaDrillBroken(block)) {
Skills.abilityCheck(player, SkillType.EXCAVATION);
}
else if (PP.getToolPreparationMode(ToolType.FISTS) && (BlockChecks.canBeGigaDrillBroken(block) || material.equals(Material.SNOW))) {
else if (profile.getToolPreparationMode(ToolType.FISTS) && (BlockChecks.canBeGigaDrillBroken(block) || material.equals(Material.SNOW))) {
Skills.abilityCheck(player, SkillType.UNARMED);
}
}
/* TREE FELLER SOUNDS */
if (mcMMO.spoutEnabled && BlockChecks.isLog(block) && PP.getAbilityMode(AbilityType.TREE_FELLER)) {
if (mcMMO.spoutEnabled && BlockChecks.isLog(block) && profile.getAbilityMode(AbilityType.TREE_FELLER)) {
SpoutSounds.playSoundForPlayer(SoundEffect.FIZZ, player, block.getLocation());
}
/*
* ABILITY TRIGGER CHECKS
*/
if (PP.getAbilityMode(AbilityType.GREEN_TERRA) && permInstance.greenTerra(player) && BlockChecks.makeMossy(block)) {
if (ModChecks.isCustomTool(inHand)) {
if (ModChecks.getToolFromItemStack(inHand).isAbilityEnabled()) {
Herbalism.greenTerra(player, block);
}
}
else {
Herbalism.greenTerra(player, block);
}
if (profile.getAbilityMode(AbilityType.GREEN_TERRA) && permInstance.greenTerra(player) && BlockChecks.makeMossy(block)) {
Herbalism.greenTerra(player, block);
}
else if (PP.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER) && Skills.triggerCheck(player, block, AbilityType.GIGA_DRILL_BREAKER)) {
else if (profile.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER) && Skills.triggerCheck(player, block, AbilityType.GIGA_DRILL_BREAKER)) {
if (configInstance.getExcavationRequiresTool()) {
if (ItemChecks.isShovel(inHand)) {
if (ModChecks.isCustomTool(inHand)) {
if (ModChecks.getToolFromItemStack(inHand).isAbilityEnabled()) {
event.setInstaBreak(true);
Excavation.gigaDrillBreaker(player, block);
}
}
else {
event.setInstaBreak(true);
Excavation.gigaDrillBreaker(player, block);
}
event.setInstaBreak(true);
Excavation.gigaDrillBreaker(player, block);
}
}
else {
@@ -338,7 +325,7 @@ public class BlockListener implements Listener {
Excavation.gigaDrillBreaker(player, block);
}
}
else if (PP.getAbilityMode(AbilityType.BERSERK) && Skills.triggerCheck(player, block, AbilityType.BERSERK)) {
else if (profile.getAbilityMode(AbilityType.BERSERK) && Skills.triggerCheck(player, block, AbilityType.BERSERK)) {
if (inHand.getType().equals(Material.AIR)) {
FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player);
plugin.getServer().getPluginManager().callEvent(armswing);
@@ -350,19 +337,11 @@ public class BlockListener implements Listener {
SpoutSounds.playSoundForPlayer(SoundEffect.POP, player, block.getLocation());
}
}
else if (PP.getAbilityMode(AbilityType.SUPER_BREAKER) && Skills.triggerCheck(player, block, AbilityType.SUPER_BREAKER)) {
else if (profile.getAbilityMode(AbilityType.SUPER_BREAKER) && Skills.triggerCheck(player, block, AbilityType.SUPER_BREAKER)) {
if (configInstance.getMiningRequiresTool()) {
if (ItemChecks.isPickaxe(inHand)) {
if (ModChecks.isCustomTool(inHand)) {
if (ModChecks.getToolFromItemStack(inHand).isAbilityEnabled()) {
event.setInstaBreak(true);
Mining.superBreakerBlockCheck(player, block);
}
}
else {
event.setInstaBreak(true);
Mining.superBreakerBlockCheck(player, block);
}
event.setInstaBreak(true);
Mining.superBreakerBlockCheck(player, block);
}
}
else {
@@ -370,7 +349,7 @@ public class BlockListener implements Listener {
Mining.superBreakerBlockCheck(player, block);
}
}
else if (PP.getSkillLevel(SkillType.WOODCUTTING) >= LEAF_BLOWER_LEVEL && (material.equals(Material.LEAVES) || (configInstance.getBlockModsEnabled() && ModChecks.isCustomLeafBlock(block)))) {
else if (profile.getSkillLevel(SkillType.WOODCUTTING) >= LEAF_BLOWER_LEVEL && (material.equals(Material.LEAVES) || (configInstance.getBlockModsEnabled() && ModChecks.isCustomLeafBlock(block)))) {
if (Skills.triggerCheck(player, block, AbilityType.LEAF_BLOWER)) {
if (configInstance.getWoodcuttingRequiresTool()) {
if (ItemChecks.isAxe(inHand)) {

View File

@@ -75,11 +75,19 @@ public class EntityListener implements Listener {
}
}
if (attacker instanceof Player && defender instanceof Player) {
if (PartyManager.getInstance().inSameParty((Player) defender, (Player) attacker)) {
event.setCancelled(true);
if (defender instanceof Player) {
Player defendingPlayer = (Player) defender;
if (!defendingPlayer.isOnline()) {
return;
}
if (attacker instanceof Player) {
if (PartyManager.getInstance().inSameParty(defendingPlayer, (Player) attacker)) {
event.setCancelled(true);
return;
}
}
}
/* Check for invincibility */
@@ -115,9 +123,18 @@ public class EntityListener implements Listener {
if (lEntity instanceof Player) {
/* Check for invincibility */
Player player = (Player) entity;
PlayerProfile PP = Users.getProfile(player);
if (PP.getGodMode()) {
if (!player.isOnline()) {
return;
}
PlayerProfile profile = Users.getProfile(player);
if (profile == null) {
return;
}
if (profile.getGodMode()) {
event.setCancelled(true);
return;
}
@@ -132,7 +149,7 @@ public class EntityListener implements Listener {
}
if (event.getDamage() >= 1) {
PP.actualizeRecentlyHurt();
profile.actualizeRecentlyHurt();
}
}
} else if (lEntity instanceof Tameable) {
@@ -225,7 +242,7 @@ public class EntityListener implements Listener {
public void onFoodLevelChange(FoodLevelChangeEvent event) {
if (event.getEntity() instanceof Player) {
Player player = (Player) event.getEntity();
PlayerProfile PP = Users.getProfile(player);
PlayerProfile profile = Users.getProfile(player);
int currentFoodLevel = player.getFoodLevel();
int newFoodLevel = event.getFoodLevel();
@@ -242,7 +259,7 @@ public class EntityListener implements Listener {
if (newFoodLevel > currentFoodLevel) {
Material food = player.getItemInHand().getType();
int herbLevel = PP.getSkillLevel(SkillType.HERBALISM);
int herbLevel = profile.getSkillLevel(SkillType.HERBALISM);
int foodChange = newFoodLevel - currentFoodLevel;
int rankChange = 0;
@@ -299,7 +316,7 @@ public class EntityListener implements Listener {
Player player = (Player) event.getOwner();
if (Permissions.getInstance().taming(player) && !event.getEntity().hasMetadata("mcmmoSummoned")) {
PlayerProfile PP = Users.getProfile(player);
PlayerProfile profile = Users.getProfile(player);
EntityType type = event.getEntityType();
int xp = 0;
@@ -316,7 +333,7 @@ public class EntityListener implements Listener {
break;
}
Skills.xpProcessing(player, PP, SkillType.TAMING, xp);
Skills.xpProcessing(player, profile, SkillType.TAMING, xp);
}
}
}

View File

@@ -22,10 +22,8 @@ public class HardcoreListener implements Listener {
Player player = event.getEntity(); //Note this returns a Player object for this subevent
if (!Permissions.getInstance().hardcoremodeBypass(player)) {
if (player.getKiller() instanceof Player) {
if (Config.getInstance().getHardcoreVampirismEnabled()) {
Hardcore.invokeVampirism(player.getKiller(), player);
}
if (Config.getInstance().getHardcoreVampirismEnabled()) {
Hardcore.invokeVampirism(player.getKiller(), player);
}
Hardcore.invokeStatPenalty(player);

View File

@@ -3,13 +3,14 @@ package com.gmail.nossr50.listeners;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.event.player.PlayerFishEvent.State;
@@ -36,7 +37,6 @@ import com.gmail.nossr50.skills.gathering.BlastMining;
import com.gmail.nossr50.skills.gathering.Fishing;
import com.gmail.nossr50.skills.gathering.Herbalism;
import com.gmail.nossr50.skills.taming.TamingManager;
import com.gmail.nossr50.spout.SpoutStuff;
import com.gmail.nossr50.util.BlockChecks;
import com.gmail.nossr50.util.Item;
import com.gmail.nossr50.util.Permissions;
@@ -58,18 +58,22 @@ public class PlayerListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerWorldChangeEvent(PlayerChangedWorldEvent event) {
Player player = event.getPlayer();
PlayerProfile PP = Users.getProfile(player);
PlayerProfile profile = Users.getProfile(player);
if (PP.getGodMode()) {
if (profile == null) {
return;
}
if (profile.getGodMode()) {
if (!Permissions.getInstance().mcgod(player)) {
PP.toggleGodMode();
profile.toggleGodMode();
player.sendMessage(LocaleLoader.getString("Commands.GodMode.Forbidden"));
}
}
if (PP.inParty()) {
if (profile.inParty()) {
if (!Permissions.getInstance().party(player)) {
PP.removeParty();
profile.removeParty();
player.sendMessage(LocaleLoader.getString("Party.Forbidden"));
}
}
@@ -93,6 +97,10 @@ public class PlayerListener implements Listener {
break;
case CAUGHT_ENTITY:
if (!(event.getCaught() instanceof LivingEntity)) {
return;
}
if (Users.getProfile(player).getSkillLevel(SkillType.FISHING) >= 150 && Permissions.getInstance().shakeMob(player)) {
Fishing.shakeMob(event);
}
@@ -111,7 +119,13 @@ public class PlayerListener implements Listener {
*/
@EventHandler(ignoreCancelled = true)
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
if (Users.getProfile(event.getPlayer()).getAbilityMode(AbilityType.BERSERK)) {
PlayerProfile profile = Users.getProfile(event.getPlayer());
if (profile == null) {
return;
}
if (profile.getAbilityMode(AbilityType.BERSERK)) {
event.setCancelled(true);
}
}
@@ -123,7 +137,7 @@ public class PlayerListener implements Listener {
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerLogin(PlayerLoginEvent event) {
Users.addUser(event.getPlayer()).actualizeRespawnATS();
Users.addUser(event.getPlayer()).getProfile().actualizeRespawnATS();
}
/**
@@ -137,11 +151,6 @@ public class PlayerListener implements Listener {
/* GARBAGE COLLECTION */
//Remove Spout Stuff
if (mcMMO.spoutEnabled && SpoutStuff.playerHUDs.containsKey(player)) {
SpoutStuff.playerHUDs.remove(player);
}
//Bleed it out
BleedTimer.bleedOut(player);
}
@@ -189,14 +198,18 @@ public class PlayerListener implements Listener {
}
//THIS IS VERY BAD WAY TO DO THINGS, NEED BETTER WAY
if (XprateCommand.xpevent) {
if (XprateCommand.isXpEventRunning()) {
player.sendMessage(LocaleLoader.getString("XPRate.Event", new Object[] {Config.getInstance().xpGainMultiplier}));
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerRespawn(PlayerRespawnEvent event) {
Users.getProfile(event.getPlayer()).actualizeRespawnATS();
PlayerProfile profile = Users.getProfile(event.getPlayer());
if (profile != null) {
profile.actualizeRespawnATS();
}
}
/**
@@ -316,12 +329,16 @@ public class PlayerListener implements Listener {
* @param event The event to watch
*/
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerChat(PlayerChatEvent event) {
public void onPlayerChat(AsyncPlayerChatEvent event) {
Player player = event.getPlayer();
PlayerProfile PP = Users.getProfile(player);
PlayerProfile profile = Users.getProfile(player);
if (PP.getPartyChatMode()) {
Party party = PP.getParty();
if (profile == null) {
return;
}
if (profile.getPartyChatMode()) {
Party party = profile.getParty();
if (party == null) {
player.sendMessage("You're not in a party, type /p to leave party chat mode."); //TODO: Use mcLocale
@@ -347,7 +364,7 @@ public class PlayerListener implements Listener {
event.setCancelled(true);
}
else if (PP.getAdminChatMode()) {
else if (profile.getAdminChatMode()) {
String playerName = player.getName();
McMMOAdminChatEvent chatEvent = new McMMOAdminChatEvent(playerName, event.getMessage());
plugin.getServer().getPluginManager().callEvent(chatEvent);
@@ -360,9 +377,9 @@ public class PlayerListener implements Listener {
plugin.getLogger().info("[A]<" + playerName + "> " + chatEvent.getMessage());
for (Player p : plugin.getServer().getOnlinePlayers()) {
if (Permissions.getInstance().adminChat(player) || player.isOp()) {
p.sendMessage(prefix + chatEvent.getMessage());
for (Player otherPlayer : plugin.getServer().getOnlinePlayers()) {
if (Permissions.getInstance().adminChat(otherPlayer) || otherPlayer.isOp()) {
otherPlayer.sendMessage(prefix + chatEvent.getMessage());
}
}

View File

@@ -7,28 +7,20 @@ import org.getspout.spoutapi.event.input.KeyPressedEvent;
import org.getspout.spoutapi.event.screen.ButtonClickEvent;
import org.getspout.spoutapi.event.screen.ScreenCloseEvent;
import org.getspout.spoutapi.event.spout.SpoutCraftEnableEvent;
import org.getspout.spoutapi.gui.Button;
import org.getspout.spoutapi.gui.ScreenType;
import org.getspout.spoutapi.player.SpoutPlayer;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.SpoutConfig;
import com.gmail.nossr50.datatypes.HUDType;
import com.gmail.nossr50.datatypes.HUDmmo;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.SpoutHud;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.buttons.ButtonEscape;
import com.gmail.nossr50.datatypes.buttons.ButtonHUDStyle;
import com.gmail.nossr50.datatypes.buttons.ButtonPartyToggle;
import com.gmail.nossr50.datatypes.popups.PopupMMO;
import com.gmail.nossr50.datatypes.buttons.McmmoButton;
import com.gmail.nossr50.datatypes.popups.Menu;
import com.gmail.nossr50.spout.SpoutStuff;
import com.gmail.nossr50.util.Users;
public class SpoutListener implements Listener {
private final mcMMO plugin;
public SpoutListener(mcMMO plugin) {
this.plugin = plugin;
}
/**
* Monitor SpoutCraftEnable events.
*
@@ -36,19 +28,16 @@ public class SpoutListener implements Listener {
*/
@EventHandler
public void onSpoutCraftEnable(SpoutCraftEnableEvent event) {
SpoutPlayer sPlayer = event.getPlayer();
PlayerProfile PPs = Users.getProfile(sPlayer);
SpoutPlayer spoutPlayer = event.getPlayer();
McMMOPlayer mcMMOPlayer = Users.getPlayer(spoutPlayer);
PlayerProfile profile = mcMMOPlayer.getProfile();
//TODO: Add custom titles based on skills
if (SpoutConfig.getInstance().getShowPowerLevel()) {
sPlayer.setTitle(sPlayer.getName()+ "\n" + ChatColor.YELLOW + "P" + ChatColor.GOLD + "lvl" + ChatColor.WHITE+"." + ChatColor.GREEN + String.valueOf(PPs.getPowerLevel()));
spoutPlayer.setTitle(spoutPlayer.getName() + "\n" + ChatColor.YELLOW + "P" + ChatColor.GOLD + "lvl" + ChatColor.WHITE+"." + ChatColor.GREEN + String.valueOf(mcMMOPlayer.getPowerLevel()));
}
if (sPlayer.isSpoutCraftEnabled()) {
SpoutStuff.playerHUDs.put(sPlayer, new HUDmmo(sPlayer, plugin)); //Setup Party HUD stuff
PPs.toggleSpoutEnabled();
}
profile.setSpoutHud(new SpoutHud(mcMMOPlayer)); //Setup Party HUD stuff
}
/**
@@ -58,48 +47,10 @@ public class SpoutListener implements Listener {
*/
@EventHandler
public void onButtonClick(ButtonClickEvent event) {
SpoutPlayer sPlayer = event.getPlayer();
PlayerProfile PP = Users.getProfile(sPlayer);
Button button = event.getButton();
if (event.getButton() instanceof ButtonHUDStyle) {
if (SpoutStuff.playerHUDs.containsKey(sPlayer)) {
SpoutStuff.playerHUDs.get(sPlayer).resetHUD();
SpoutStuff.playerHUDs.remove(sPlayer);
switch (PP.getHUDType()) {
case RETRO:
PP.setHUDType(HUDType.STANDARD);
break;
case STANDARD:
PP.setHUDType(HUDType.SMALL);
break;
case SMALL:
PP.setHUDType(HUDType.DISABLED);
break;
case DISABLED:
PP.setHUDType(HUDType.RETRO);
break;
default:
break;
}
SpoutStuff.playerHUDs.put(sPlayer, new HUDmmo(sPlayer, plugin));
SpoutStuff.playerScreens.get(sPlayer).updateButtons(PP);
}
}
else if (event.getButton() instanceof ButtonEscape) {
sPlayer.getMainScreen().closePopup();
}
else if (event.getButton() instanceof ButtonPartyToggle) {
PP.togglePartyHUD();
ButtonPartyToggle bpt = (ButtonPartyToggle) event.getButton();
bpt.updateText(PP);
SpoutStuff.playerHUDs.get(sPlayer).resetHUD();
SpoutStuff.playerHUDs.get(sPlayer).initializeHUD(sPlayer);
if (button instanceof McmmoButton) {
((McmmoButton) button).activate();
}
}
@@ -110,8 +61,11 @@ public class SpoutListener implements Listener {
*/
@EventHandler
public void onScreenClose(ScreenCloseEvent event) {
if (event.getScreen() instanceof PopupMMO) {
SpoutStuff.playerScreens.remove(event.getPlayer());
if (event.getScreen() instanceof Menu) {
SpoutPlayer spoutPlayer = event.getPlayer();
Users.getProfile(spoutPlayer).getSpoutHud().onMenuClose();
spoutPlayer.getMainScreen().setDirty(true);
}
}
@@ -122,23 +76,17 @@ public class SpoutListener implements Listener {
*/
@EventHandler
public void onKeyPressedEvent(KeyPressedEvent event) {
SpoutPlayer sPlayer = event.getPlayer();
SpoutPlayer spoutPlayer = event.getPlayer();
if (!sPlayer.isSpoutCraftEnabled() || sPlayer.getMainScreen().getActivePopup() != null || event.getScreenType() != ScreenType.GAME_SCREEN) {
if (spoutPlayer.getMainScreen().getActivePopup() != null || event.getScreenType() != ScreenType.GAME_SCREEN) {
return;
}
if (event.getKey() == SpoutStuff.keypress) {
if (!SpoutStuff.playerScreens.containsKey(sPlayer)) {
PopupMMO mmoPop = new PopupMMO(sPlayer, Users.getProfile(sPlayer), plugin);
SpoutHud spoutHud = Users.getProfile(spoutPlayer).getSpoutHud();
SpoutStuff.playerScreens.put(sPlayer, mmoPop);
sPlayer.getMainScreen().attachPopupScreen(SpoutStuff.playerScreens.get(sPlayer));
sPlayer.getMainScreen().setDirty(true);
}
else {
sPlayer.getMainScreen().attachPopupScreen(SpoutStuff.playerScreens.get(sPlayer));
sPlayer.getMainScreen().setDirty(true);
if (!spoutHud.isMenuOpened()) {
spoutHud.openMenu();
}
}
}

View File

@@ -4,7 +4,6 @@ import java.io.File;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.ChunkUnloadEvent;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.event.world.WorldSaveEvent;
@@ -31,13 +30,8 @@ public class WorldListener implements Listener {
mcMMO.placeStore.saveWorld(event.getWorld());
}
@EventHandler
public void onChunkLoad(ChunkLoadEvent event) {
mcMMO.placeStore.chunkLoaded(event.getChunk().getX(), event.getChunk().getZ(), event.getChunk().getWorld());
}
@EventHandler
public void onChunkUnload(ChunkUnloadEvent event) {
mcMMO.placeStore.chunkUnloaded(event.getChunk().getX(), event.getChunk().getZ(), event.getChunk().getWorld());
mcMMO.placeStore.chunkUnloaded(event.getChunk().getX(), event.getChunk().getZ(), event.getWorld());
}
}

View File

@@ -9,7 +9,6 @@ import java.util.List;
import net.shatteredlands.shatt.backup.ZipLibrary;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;
@@ -22,6 +21,7 @@ import com.gmail.nossr50.commands.general.InspectCommand;
import com.gmail.nossr50.commands.general.McstatsCommand;
import com.gmail.nossr50.commands.general.MmoeditCommand;
import com.gmail.nossr50.commands.general.MmoupdateCommand;
import com.gmail.nossr50.commands.general.SkillResetCommand;
import com.gmail.nossr50.commands.general.XprateCommand;
import com.gmail.nossr50.commands.mc.McabilityCommand;
import com.gmail.nossr50.commands.mc.MccCommand;
@@ -52,11 +52,11 @@ import com.gmail.nossr50.commands.spout.MchudCommand;
import com.gmail.nossr50.commands.spout.XplockCommand;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.HiddenConfig;
import com.gmail.nossr50.config.RepairConfigManager;
import com.gmail.nossr50.config.TreasuresConfig;
import com.gmail.nossr50.config.mods.CustomArmorConfig;
import com.gmail.nossr50.config.mods.CustomBlocksConfig;
import com.gmail.nossr50.config.mods.CustomToolsConfig;
import com.gmail.nossr50.config.repair.RepairConfigManager;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.listeners.BlockListener;
import com.gmail.nossr50.listeners.EntityListener;
@@ -66,6 +66,7 @@ import com.gmail.nossr50.listeners.WorldListener;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.runnables.BleedTimer;
import com.gmail.nossr50.runnables.ChunkletUnloader;
import com.gmail.nossr50.runnables.SaveTimer;
import com.gmail.nossr50.runnables.SkillMonitor;
import com.gmail.nossr50.runnables.SpoutStart;
@@ -91,8 +92,7 @@ public class mcMMO extends JavaPlugin {
private HashMap<String, String> aliasMap = new HashMap<String, String>(); //Alias - Command
private HashMap<Integer, String> tntTracker = new HashMap<Integer, String>();
public static File versionFile;
public static Database database;
private static Database database;
public static mcMMO p;
public static ChunkletManager placeStore;
@@ -102,11 +102,11 @@ public class mcMMO extends JavaPlugin {
public static File mcmmo;
//File Paths
public static String mainDirectory;
public static String flatFileDirectory;
public static String usersFile;
public static String leaderboardDirectory;
public static String modDirectory;
private static String mainDirectory;
private static String flatFileDirectory;
private static String usersFile;
private static String leaderboardDirectory;
private static String modDirectory;
//Spout Check
public static boolean spoutEnabled;
@@ -127,17 +127,15 @@ public class mcMMO extends JavaPlugin {
List<Repairable> repairables = new ArrayList<Repairable>();
if (configInstance.getToolModsEnabled()) {
CustomToolsConfig.getInstance().load();
repairables.addAll(CustomToolsConfig.getInstance().getLoadedRepairables());
}
if (configInstance.getArmorModsEnabled()) {
CustomArmorConfig.getInstance().load();
repairables.addAll(CustomArmorConfig.getInstance().getLoadedRepairables());
}
if (configInstance.getBlockModsEnabled()) {
CustomBlocksConfig.getInstance().load();
CustomBlocksConfig.getInstance();
}
//Load repair configs, make manager, and register them at this time
@@ -150,16 +148,16 @@ public class mcMMO extends JavaPlugin {
Users.loadUsers();
}
PluginManager pm = getServer().getPluginManager();
PluginManager pluginManager = getServer().getPluginManager();
//Register events
pm.registerEvents(playerListener, this);
pm.registerEvents(blockListener, this);
pm.registerEvents(entityListener, this);
pm.registerEvents(worldListener, this);
pluginManager.registerEvents(playerListener, this);
pluginManager.registerEvents(blockListener, this);
pluginManager.registerEvents(entityListener, this);
pluginManager.registerEvents(worldListener, this);
if (configInstance.getHardcoreEnabled()) {
pm.registerEvents(hardcoreListener, this);
pluginManager.registerEvents(hardcoreListener, this);
}
PluginDescriptionFile pdfFile = getDescription();
@@ -183,12 +181,14 @@ public class mcMMO extends JavaPlugin {
//Schedule Spout Activation 1 second after start-up
scheduler.scheduleSyncDelayedTask(this, new SpoutStart(this), 20);
//Periodic save timer (Saves every 10 minutes)
//Periodic save timer (Saves every 10 minutes by default)
scheduler.scheduleSyncRepeatingTask(this, new SaveTimer(this), 0, configInstance.getSaveInterval() * 1200);
//Regen & Cooldown timer (Runs every second)
scheduler.scheduleSyncRepeatingTask(this, new SkillMonitor(this), 0, 20);
//Bleed timer (Runs every two seconds)
scheduler.scheduleSyncRepeatingTask(this, new BleedTimer(), 0, 40);
//Chunklet unloader (Runs every 20 seconds by default)
scheduler.scheduleSyncRepeatingTask(this, new ChunkletUnloader(), 0, ChunkletUnloader.RUN_INTERVAL * 20);
registerCommands();
@@ -198,7 +198,7 @@ public class mcMMO extends JavaPlugin {
Graph graph = metrics.createGraph("Percentage of servers using timings");
if (pm.useTimings()) {
if (pluginManager.useTimings()) {
graph.addPlotter(new Metrics.Plotter("Enabled") {
@Override
public int getValue() {
@@ -224,10 +224,6 @@ public class mcMMO extends JavaPlugin {
// Get our ChunkletManager
placeStore = ChunkletManagerFactory.getChunkletManager();
for (World world : getServer().getWorlds()) {
placeStore.loadWorld(world);
}
}
/**
@@ -284,20 +280,11 @@ public class mcMMO extends JavaPlugin {
*/
@Override
public void onDisable() {
//Make sure to save player information if the server shuts down
for (PlayerProfile playerProfile : Users.getProfiles().values()) {
playerProfile.save();
}
Users.saveAll(); //Make sure to save player information if the server shuts down
PartyManager.getInstance().saveParties();
getServer().getScheduler().cancelTasks(this); //This removes our tasks
//Save our metadata
placeStore.saveAll();
//Cleanup empty metadata stores
placeStore.cleanUp();
placeStore.saveAll(); //Save our metadata
placeStore.cleanUp(); //Cleanup empty metadata stores
//Remove other tasks BEFORE starting the Backup, or we just cancel it straight away.
try {
@@ -379,6 +366,10 @@ public class mcMMO extends JavaPlugin {
getCommand("mcstats").setExecutor(new McstatsCommand());
}
if (configInstance.getCommandSkillResetEnabled()) {
getCommand("skillreset").setExecutor(new SkillResetCommand());
}
//Party commands
if (configInstance.getCommandAcceptEnabled()) {
getCommand("accept").setExecutor(new AcceptCommand(this));
@@ -418,7 +409,7 @@ public class mcMMO extends JavaPlugin {
}
if (configInstance.getCommandInspectEnabled()) {
getCommand("inspect").setExecutor(new InspectCommand(this));
getCommand("inspect").setExecutor(new InspectCommand());
}
if (configInstance.getCommandXPRateEnabled()) {
@@ -432,7 +423,7 @@ public class mcMMO extends JavaPlugin {
getCommand("xplock").setExecutor(new XplockCommand());
}
getCommand("mchud").setExecutor(new MchudCommand(this));
getCommand("mchud").setExecutor(new MchudCommand());
}
/**
@@ -493,4 +484,29 @@ public class mcMMO extends JavaPlugin {
public void removeFromTNTTracker(int tntID) {
tntTracker.remove(tntID);
}
public static String getMainDirectory() {
return mainDirectory;
}
public static String getFlatFileDirectory() {
return flatFileDirectory;
}
public static String getUsersFile() {
return usersFile;
}
public static String getLeaderboardDirectory() {
return leaderboardDirectory;
}
public static String getModDirectory() {
return modDirectory;
}
public static Database getPlayerDatabase() {
return database;
}
}

View File

@@ -41,8 +41,17 @@ public class PartyManager {
* @return true if they are in the same party, false otherwise
*/
public boolean inSameParty(Player firstPlayer, Player secondPlayer) {
if (Users.getProfile(firstPlayer).getParty() == null || Users.getProfile(secondPlayer).getParty() == null
|| !Users.getProfile(firstPlayer).getParty().equals(Users.getProfile(secondPlayer).getParty())) {
PlayerProfile firstProfile = Users.getProfile(firstPlayer);
PlayerProfile secondProfile = Users.getProfile(secondPlayer);
if (firstProfile == null || secondProfile == null) {
return false;
}
Party firstParty = firstProfile.getParty();
Party secondParty = secondProfile.getParty();
if (firstParty == null || secondParty == null || firstParty != secondParty) {
return false;
}

View File

@@ -34,7 +34,7 @@ public class BleedTimer implements Runnable {
for (Entry<LivingEntity, Integer> entry : bleedList.entrySet()) {
LivingEntity entity = entry.getKey();
if (entry.getValue() <= 0 || entity.isDead() || entity == null) {
if (entry.getValue() <= 0 || entity.isDead()) {
remove(entity);
break;
}

View File

@@ -0,0 +1,58 @@
package com.gmail.nossr50.runnables;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.Chunk;
import org.bukkit.World;
import com.gmail.nossr50.mcMMO;
public class ChunkletUnloader implements Runnable {
private static Map<Chunk, Integer> unloadedChunks = new HashMap<Chunk, Integer>();
private static int minimumInactiveTime = 60; //Should be a multiple of RUN_INTERVAL for best performance
public static final int RUN_INTERVAL = 20;
public static void addToList(Chunk chunk) {
//Unfortunately we can't use Map.contains() because Chunks are always new objects
//This method isn't efficient enough for me
for (Chunk otherChunk : unloadedChunks.keySet()) {
if (chunk.getX() == otherChunk.getX() && chunk.getZ() == otherChunk.getZ()) {
return;
}
}
unloadedChunks.put(chunk, 0);
}
public static void addToList(int cx, int cz, World world) {
addToList(world.getChunkAt(cx, cz));
}
@Override
public void run() {
for (Iterator<Entry<Chunk, Integer>> it = unloadedChunks.entrySet().iterator() ; it.hasNext() ; ) {
Entry<Chunk, Integer> entry = it.next();
Chunk chunk = entry.getKey();
if (!chunk.isLoaded()) {
int inactiveTime = entry.getValue() + RUN_INTERVAL;
//Chunklets are unloaded only if their chunk has been unloaded for minimumInactiveTime
if (inactiveTime >= minimumInactiveTime) {
mcMMO.placeStore.unloadChunk(chunk.getX(), chunk.getZ(), chunk.getWorld());
it.remove();
continue;
}
unloadedChunks.put(entry.getKey(), inactiveTime);
}
else {
//Just remove the entry if the chunk has been reloaded.
it.remove();
}
}
}
}

View File

@@ -9,15 +9,15 @@ import com.gmail.nossr50.util.Skills;
public class GainXp implements Runnable {
private Player player = null;
private PlayerProfile PP = null;
private PlayerProfile profile = null;
private double baseXp = 0;
private SkillType skillType = null;
private LivingEntity target = null;
private int baseHealth = 0;
public GainXp(Player player, PlayerProfile PP, SkillType skillType, double baseXp, LivingEntity target) {
public GainXp(Player player, PlayerProfile profile, SkillType skillType, double baseXp, LivingEntity target) {
this.player = player;
this.PP = PP;
this.profile = profile;
this.skillType = skillType;
this.baseXp = baseXp;
this.target = target;
@@ -39,6 +39,6 @@ public class GainXp implements Runnable {
damage += health;
}
Skills.xpProcessing(player, PP, skillType, (int) (damage * baseXp));
Skills.xpProcessing(player, profile, skillType, (int) (damage * baseXp));
}
}

View File

@@ -10,11 +10,11 @@ import com.gmail.nossr50.datatypes.SkillType;
public class GreenThumbTimer implements Runnable {
private Block block;
private PlayerProfile PP;
private PlayerProfile profile;
public GreenThumbTimer(Block block, PlayerProfile PP) {
public GreenThumbTimer(Block block, PlayerProfile profile) {
this.block = block;
this.PP = PP;
this.profile = profile;
}
@Override
@@ -22,14 +22,14 @@ public class GreenThumbTimer implements Runnable {
block.setType(Material.CROPS);
//This replants the wheat at a certain stage in development based on Herbalism Skill
if (!PP.getAbilityMode(AbilityType.GREEN_TERRA)) {
if (PP.getSkillLevel(SkillType.HERBALISM) >= 600) {
if (!profile.getAbilityMode(AbilityType.GREEN_TERRA)) {
if (profile.getSkillLevel(SkillType.HERBALISM) >= 600) {
block.setData(CropState.MEDIUM.getData());
}
else if (PP.getSkillLevel(SkillType.HERBALISM) >= 400) {
else if (profile.getSkillLevel(SkillType.HERBALISM) >= 400) {
block.setData(CropState.SMALL.getData());
}
else if (PP.getSkillLevel(SkillType.HERBALISM) >= 200) {
else if (profile.getSkillLevel(SkillType.HERBALISM) >= 200) {
block.setData(CropState.VERY_SMALL.getData());
}
else {

View File

@@ -1,21 +1,24 @@
package com.gmail.nossr50.runnables;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.util.Users;
public class ProfileSaveTask implements Runnable {
private McMMOPlayer mcMMOPlayer;
private PlayerProfile playerProfile;
public ProfileSaveTask(PlayerProfile playerProfile) {
this.playerProfile = playerProfile;
public ProfileSaveTask(McMMOPlayer mcMMOPlayer) {
this.mcMMOPlayer = mcMMOPlayer;
this.playerProfile = mcMMOPlayer.getProfile();
}
@Override
public void run() {
playerProfile.save();
if (!playerProfile.getPlayer().isOnline()) {
Users.getProfiles().remove(playerProfile);
if (!mcMMOPlayer.getPlayer().isOnline()) {
Users.remove(playerProfile.getPlayerName());
}
}
}

View File

@@ -5,6 +5,7 @@ import java.io.FileReader;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.util.Database;
import com.gmail.nossr50.util.Misc;
public class SQLConversionTask implements Runnable {
@@ -17,7 +18,8 @@ public class SQLConversionTask implements Runnable {
@Override
public void run() {
String location = mcMMO.usersFile;
Database database = mcMMO.getPlayerDatabase();
String location = mcMMO.getUsersFile();
try {
FileReader file = new FileReader(location);
@@ -164,7 +166,7 @@ public class SQLConversionTask implements Runnable {
}
//Check to see if the user is in the DB
id = mcMMO.database.getInt("SELECT id FROM "
id = database.getInt("SELECT id FROM "
+ tablePrefix
+ "users WHERE user = '" + playerName + "'");
@@ -172,11 +174,11 @@ public class SQLConversionTask implements Runnable {
theCount++;
//Update the skill values
mcMMO.database.write("UPDATE "
database.write("UPDATE "
+ tablePrefix
+ "users SET lastlogin = " + 0
+ " WHERE id = " + id);
mcMMO.database.write("UPDATE "
database.write("UPDATE "
+ tablePrefix
+ "skills SET "
+ " taming = taming+" + Misc.getInt(taming)
@@ -192,7 +194,7 @@ public class SQLConversionTask implements Runnable {
+ ", acrobatics = acrobatics+" + Misc.getInt(acrobatics)
+ ", fishing = fishing+" + Misc.getInt(fishing)
+ " WHERE user_id = " + id);
mcMMO.database.write("UPDATE "
database.write("UPDATE "
+ tablePrefix
+ "experience SET "
+ " taming = " + Misc.getInt(tamingXP)
@@ -213,32 +215,32 @@ public class SQLConversionTask implements Runnable {
theCount++;
//Create the user in the DB
mcMMO.database.write("INSERT INTO "
database.write("INSERT INTO "
+ tablePrefix
+ "users (user, lastlogin) VALUES ('"
+ playerName + "',"
+ System.currentTimeMillis() / 1000 + ")");
id = mcMMO.database.getInt("SELECT id FROM "
id = database.getInt("SELECT id FROM "
+ tablePrefix
+ "users WHERE user = '"
+ playerName + "'");
mcMMO.database.write("INSERT INTO "
database.write("INSERT INTO "
+ tablePrefix
+ "skills (user_id) VALUES (" + id + ")");
mcMMO.database.write("INSERT INTO "
database.write("INSERT INTO "
+ tablePrefix
+ "experience (user_id) VALUES (" + id
+ ")");
//Update the skill values
mcMMO.database.write("UPDATE "
database.write("UPDATE "
+ tablePrefix
+ "users SET lastlogin = " + 0
+ " WHERE id = " + id);
mcMMO.database.write("UPDATE "
database.write("UPDATE "
+ tablePrefix
+ "users SET party = '" + party
+ "' WHERE id = " + id);
mcMMO.database.write("UPDATE "
database.write("UPDATE "
+ tablePrefix
+ "skills SET "
+ " taming = taming+" + Misc.getInt(taming)
@@ -254,7 +256,7 @@ public class SQLConversionTask implements Runnable {
+ ", acrobatics = acrobatics+" + Misc.getInt(acrobatics)
+ ", fishing = fishing+" + Misc.getInt(fishing)
+ " WHERE user_id = " + id);
mcMMO.database.write("UPDATE "
database.write("UPDATE "
+ tablePrefix
+ "experience SET "
+ " taming = " + Misc.getInt(tamingXP)

View File

@@ -3,7 +3,6 @@ package com.gmail.nossr50.runnables;
import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.util.Database;
import com.gmail.nossr50.util.Users;
@@ -19,11 +18,9 @@ public class SQLReconnect implements Runnable {
if (!Database.isConnected()) {
Database.connect();
if (Database.isConnected()) {
for (PlayerProfile playerProfile : Users.getProfiles().values()) {
playerProfile.save(); //Save all profiles
}
Users.saveAll(); //Save all profiles
Users.clearAll(); //Clear the profiles
Users.clearUsers(); //Clear the profiles
for (Player player : plugin.getServer().getOnlinePlayers()) {
Users.addUser(player); //Add in new profiles, forcing them to 'load' again from MySQL
}

View File

@@ -3,7 +3,7 @@ package com.gmail.nossr50.runnables;
import org.bukkit.scheduler.BukkitScheduler;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.Users;
@@ -20,8 +20,8 @@ public class SaveTimer implements Runnable {
int count = 1;
BukkitScheduler bukkitScheduler = plugin.getServer().getScheduler();
for (PlayerProfile playerProfile : Users.getProfiles().values()) {
bukkitScheduler.scheduleSyncDelayedTask(plugin, new ProfileSaveTask(playerProfile), count);
for (McMMOPlayer mcMMOPlayer : Users.getPlayers().values()) {
bukkitScheduler.scheduleSyncDelayedTask(plugin, new ProfileSaveTask(mcMMOPlayer), count);
count++;
}

View File

@@ -22,14 +22,14 @@ public class SkillMonitor implements Runnable {
for (Player player : plugin.getServer().getOnlinePlayers()) {
PlayerProfile PP = Users.getProfile(player);
PlayerProfile profile = Users.getProfile(player);
/*
* MONITOR SKILLS
*/
for (SkillType skill : SkillType.values()) {
if (skill.getTool() != null && skill.getAbility() != null) {
Skills.monitorSkill(player, PP, curTime, skill);
Skills.monitorSkill(player, profile, curTime, skill);
}
}
@@ -38,7 +38,7 @@ public class SkillMonitor implements Runnable {
*/
for (AbilityType ability : AbilityType.values()) {
if (ability.getCooldown() > 0 ) {
Skills.watchCooldown(player, PP, curTime, ability);
Skills.watchCooldown(player, profile, ability);
}
}
}

View File

@@ -32,6 +32,9 @@ public class SpoutStart implements Runnable{
FileManager FM = SpoutManager.getFileManager();
FM.addToPreLoginCache(plugin, SpoutStuff.getFiles());
//Handle spout players after a /reload
SpoutStuff.reloadSpoutPlayers();
}
}
}

View File

@@ -0,0 +1,27 @@
package com.gmail.nossr50.runnables;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.event.block.BlockPistonRetractEvent;
import com.gmail.nossr50.mcMMO;
public class StickyPistonTracker implements Runnable {
BlockPistonRetractEvent event;
public StickyPistonTracker(BlockPistonRetractEvent event) {
this.event = event;
}
@Override
public void run() {
Block originalBlock = event.getRetractLocation().getBlock();
if (originalBlock.getType() == Material.AIR && mcMMO.placeStore.isTrue(originalBlock)) {
Block newBlock = originalBlock.getRelative(event.getDirection().getOppositeFace());
mcMMO.placeStore.setFalse(originalBlock);
mcMMO.placeStore.setTrue(newBlock);
}
}
}

View File

@@ -32,7 +32,13 @@ public class AcrobaticsManager {
RollEventHandler eventHandler = new RollEventHandler(this, event);
if (Acrobatics.getRandom().nextInt(1000) <= eventHandler.skillModifier && !eventHandler.isFatal(eventHandler.modifiedDamage)) {
int randomChance = 1000;
if (player.hasPermission("mcmmo.perks.lucky.acrobatics")) {
randomChance = (int) (randomChance * 0.75);
}
if (Acrobatics.getRandom().nextInt(randomChance) <= eventHandler.skillModifier && !eventHandler.isFatal(eventHandler.modifiedDamage)) {
eventHandler.modifyEventDamage();
eventHandler.sendAbilityMessage();
eventHandler.processXPGain(eventHandler.damage * Acrobatics.ROLL_XP_MODIFIER);
@@ -54,7 +60,13 @@ public class AcrobaticsManager {
DodgeEventHandler eventHandler = new DodgeEventHandler(this, event);
if (Acrobatics.getRandom().nextInt(4000) <= eventHandler.skillModifier && !eventHandler.isFatal(eventHandler.modifiedDamage)) {
int randomChance = 4000;
if (player.hasPermission("mcmmo.perks.lucky.acrobatics")) {
randomChance = (int) (randomChance * 0.75);
}
if (Acrobatics.getRandom().nextInt(randomChance) <= eventHandler.skillModifier && !eventHandler.isFatal(eventHandler.modifiedDamage)) {
eventHandler.modifyEventDamage();
eventHandler.sendAbilityMessage();
eventHandler.processXPGain(eventHandler.damage * Acrobatics.DODGE_XP_MODIFIER);

View File

@@ -16,10 +16,12 @@ public class DodgeEventHandler extends AcrobaticsEventHandler {
calculateModifiedDamage();
}
@Override
protected void calculateSkillModifier() {
this.skillModifier = Misc.skillCheck(manager.getSkillLevel(), Acrobatics.DODGE_MAX_BONUS_LEVEL);
}
@Override
protected void calculateModifiedDamage() {
int modifiedDamage = damage / 2;
@@ -30,14 +32,17 @@ public class DodgeEventHandler extends AcrobaticsEventHandler {
this.modifiedDamage = modifiedDamage;
}
@Override
protected void modifyEventDamage() {
event.setDamage(modifiedDamage);
}
@Override
protected void sendAbilityMessage() {
player.sendMessage(LocaleLoader.getString("Acrobatics.Combat.Proc"));
}
@Override
protected void processXPGain(int xp) {
PlayerProfile profile = manager.getProfile();

View File

@@ -21,6 +21,7 @@ public class RollEventHandler extends AcrobaticsEventHandler {
calculateModifiedDamage();
}
@Override
protected void calculateSkillModifier() {
int skillModifer = manager.getSkillLevel();
@@ -32,6 +33,7 @@ public class RollEventHandler extends AcrobaticsEventHandler {
this.skillModifier = skillModifer;
}
@Override
protected void calculateModifiedDamage() {
int modifiedDamage = damage - damageThreshold;
@@ -42,6 +44,7 @@ public class RollEventHandler extends AcrobaticsEventHandler {
this.modifiedDamage = modifiedDamage;
}
@Override
protected void modifyEventDamage() {
event.setDamage(modifiedDamage);
@@ -51,6 +54,7 @@ public class RollEventHandler extends AcrobaticsEventHandler {
}
@Override
protected void sendAbilityMessage() {
if (isGraceful) {
player.sendMessage(LocaleLoader.getString("Acrobatics.Ability.Proc"));
@@ -61,6 +65,7 @@ public class RollEventHandler extends AcrobaticsEventHandler {
}
@Override
protected void processXPGain(int xpGain) {
Skills.xpProcessing(player, manager.getProfile(), SkillType.ACROBATICS, xpGain);
}

View File

@@ -34,7 +34,13 @@ public class ArcheryManager {
ArrowTrackingEventHandler eventHandler = new ArrowTrackingEventHandler(this, livingEntity);
if (Archery.getRandom().nextInt(1000) < eventHandler.skillModifier) {
int randomChance = 1000;
if (player.hasPermission("mcmmo.perks.lucky.archery")) {
randomChance = (int) (randomChance * 0.75);
}
if (Archery.getRandom().nextInt(randomChance) < eventHandler.skillModifier) {
eventHandler.addToTracker();
}
}
@@ -52,7 +58,13 @@ public class ArcheryManager {
DazeEventHandler eventHandler = new DazeEventHandler(this, event, defender);
if (Archery.getRandom().nextInt(2000) < eventHandler.skillModifier) {
int randomChance = 2000;
if (player.hasPermission("mcmmo.perks.lucky.archery")) {
randomChance = (int) (randomChance * 0.75);
}
if (Archery.getRandom().nextInt(randomChance) < eventHandler.skillModifier) {
eventHandler.handleDazeEffect();
eventHandler.sendAbilityMessages();
}

View File

@@ -5,14 +5,15 @@ import org.bukkit.entity.LivingEntity;
import com.gmail.nossr50.mcMMO;
public class TrackedEntity {
public class TrackedEntity implements Runnable {
private LivingEntity livingEntity;
private int arrowCount;
private int previousTicksLived;
private int taskId;
public TrackedEntity(LivingEntity livingEntity) {
this.livingEntity = livingEntity;
new CheckTrackedEntityExistence(this);
taskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(mcMMO.p, this, 12000, 12000);
}
//LivingEntity.isDead() isn't a reliable way to know if an entity is still active
@@ -23,10 +24,9 @@ public class TrackedEntity {
if (currentTicksLived == previousTicksLived) {
return false;
}
else {
previousTicksLived = currentTicksLived;
return true;
}
previousTicksLived = currentTicksLived;
return true;
}
public LivingEntity getLivingEntity() {
@@ -41,23 +41,11 @@ public class TrackedEntity {
arrowCount++;
}
private class CheckTrackedEntityExistence implements Runnable {
private TrackedEntity trackedEntity;
private int taskId;
public CheckTrackedEntityExistence(TrackedEntity trackedEntity) {
this.trackedEntity = trackedEntity;
//Check if the entity is still active every 10 minutes
taskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(mcMMO.p, this, 12000, 12000);
}
@Override
public void run() {
if (!trackedEntity.isActive()) {
Archery.removeFromTracker(trackedEntity);
Bukkit.getScheduler().cancelTask(taskId);
}
@Override
public void run() {
if (!isActive()) {
Archery.removeFromTracker(this);
Bukkit.getScheduler().cancelTask(taskId);
}
}
}

View File

@@ -71,11 +71,17 @@ public class Axes {
final double PVP_MODIFIER = 1.5;
final int PVE_MODIFIER = 2;
PlayerProfile PPa = Users.getProfile(attacker);
int skillLevel = PPa.getSkillLevel(SkillType.AXES);
PlayerProfile attackerProfile = Users.getProfile(attacker);
int skillLevel = attackerProfile.getSkillLevel(SkillType.AXES);
int skillCheck = Misc.skillCheck(skillLevel, MAX_BONUS_LEVEL);
if (random.nextInt(2000) <= skillCheck && !entity.isDead()){
int randomChance = 2000;
if (attacker.hasPermission("mcmmo.perks.lucky.axes")) {
randomChance = (int) (randomChance * 0.75);
}
if (random.nextInt(randomChance) <= skillCheck && !entity.isDead()){
int damage = event.getDamage();
if (entity instanceof Player){
@@ -139,7 +145,13 @@ public class Axes {
return;
}
if (random.nextInt(100) <= GREATER_IMPACT_CHANCE) {
int randomChance = 100;
if (attacker.hasPermission("mcmmo.perks.lucky.axes")) {
randomChance = (int) (randomChance * 0.75);
}
if (random.nextInt(randomChance) <= GREATER_IMPACT_CHANCE) {
event.setDamage(event.getDamage() + 2);
target.setVelocity(attacker.getLocation().getDirection().normalize().multiply(GREATER_IMPACT_MULTIPLIER));
attacker.sendMessage(LocaleLoader.getString("Axes.Combat.GI.Proc"));

View File

@@ -9,7 +9,6 @@ import java.util.Random;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.entity.EntityDamageEvent;
@@ -243,9 +242,9 @@ public class BlastMining {
* @param plugin mcMMO plugin instance
*/
public static void detonate(PlayerInteractEvent event, Player player, mcMMO plugin) {
PlayerProfile PP = Users.getProfile(player);
PlayerProfile profile = Users.getProfile(player);
if (PP.getSkillLevel(SkillType.MINING) < 125)
if (profile.getSkillLevel(SkillType.MINING) < 125)
return;
Block block = event.getClickedBlock();
@@ -280,8 +279,8 @@ public class BlastMining {
AbilityType ability = AbilityType.BLAST_MINING;
/* Check Cooldown */
if (!Skills.cooldownOver(PP.getSkillDATS(ability) * TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) {
player.sendMessage(LocaleLoader.getString("Skills.TooTired") + ChatColor.YELLOW + " (" + Skills.calculateTimeLeft(PP.getSkillDATS(ability) * TIME_CONVERSION_FACTOR, ability.getCooldown()) + "s)");
if (!Skills.cooldownOver(profile.getSkillDATS(ability) * TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) {
player.sendMessage(LocaleLoader.getString("Skills.TooTired") + ChatColor.YELLOW + " (" + Skills.calculateTimeLeft(profile.getSkillDATS(ability) * TIME_CONVERSION_FACTOR, ability.getCooldown()) + "s)");
return;
}
@@ -304,7 +303,7 @@ public class BlastMining {
/* Disable the original one */
block.setType(Material.AIR);
PP.setSkillDATS(ability, System.currentTimeMillis()); //Save DATS for Blast Mining
PP.setAbilityInformed(ability, false);
profile.setSkillDATS(ability, System.currentTimeMillis()); //Save DATS for Blast Mining
profile.setAbilityInformed(ability, false);
}
}

View File

@@ -38,10 +38,10 @@ public class Excavation {
*/
public static void excavationProcCheck(Block block, Player player) {
Material type = block.getType();
Location loc = block.getLocation();
Location location = block.getLocation();
PlayerProfile PP = Users.getProfile(player);
int skillLevel = PP.getSkillLevel(SkillType.EXCAVATION);
PlayerProfile profile = Users.getProfile(player);
int skillLevel = profile.getSkillLevel(SkillType.EXCAVATION);
ArrayList<ItemStack> is = new ArrayList<ItemStack>();
List<ExcavationTreasure> treasures = new ArrayList<ExcavationTreasure>();
@@ -91,7 +91,13 @@ public class Excavation {
for (ExcavationTreasure treasure : treasures) {
if (skillLevel >= treasure.getDropLevel()) {
if (random.nextDouble() * 100 <= treasure.getDropChance()) {
int randomChance = 100;
if (player.hasPermission("mcmmo.perks.lucky.excavation")) {
randomChance = (int) (randomChance * 0.75);
}
if (random.nextDouble() * randomChance <= treasure.getDropChance()) {
xp += treasure.getXp();
is.add(treasure.getDrop());
}
@@ -101,12 +107,12 @@ public class Excavation {
//Drop items
for (ItemStack x : is) {
if (x != null) {
Misc.dropItem(loc, x);
Misc.dropItem(location, x);
}
}
}
Skills.xpProcessing(player, PP, SkillType.EXCAVATION, xp);
Skills.xpProcessing(player, profile, SkillType.EXCAVATION, xp);
}
/**
@@ -118,7 +124,7 @@ public class Excavation {
public static void gigaDrillBreaker(Player player, Block block) {
Skills.abilityDurabilityLoss(player.getItemInHand(), Config.getInstance().getAbilityToolDamage());
if (!mcMMO.placeStore.isTrue(block)) {
if (!mcMMO.placeStore.isTrue(block) || !Misc.blockBreakSimulate(block, player, true)) {
FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player);
mcMMO.p.getServer().getPluginManager().callEvent(armswing);

View File

@@ -37,11 +37,11 @@ public class Fishing {
/**
* Get the player's current fishing loot tier.
*
* @param PP The profile of the player
* @param profile The profile of the player
* @return the player's current fishing rank
*/
public static int getFishingLootTier(PlayerProfile PP) {
int level = PP.getSkillLevel(SkillType.FISHING);
public static int getFishingLootTier(PlayerProfile profile) {
int level = profile.getSkillLevel(SkillType.FISHING);
int fishingTier;
if (level >= Config.getInstance().getFishingTierLevelsTier5()) {
@@ -70,11 +70,11 @@ public class Fishing {
* @param event The event to modify
*/
private static void getFishingResults(Player player, PlayerFishEvent event) {
PlayerProfile PP = Users.getProfile(player);
PlayerProfile profile = Users.getProfile(player);
List<FishingTreasure> rewards = new ArrayList<FishingTreasure>();
Item theCatch = (Item) event.getCaught();
switch (getFishingLootTier(PP)) {
switch (getFishingLootTier(profile)) {
case 1:
rewards = TreasuresConfig.getInstance().fishingRewardsTier1;
break;
@@ -102,8 +102,14 @@ public class Fishing {
if (Config.getInstance().getFishingDropsEnabled() && rewards.size() > 0 && Permissions.getInstance().fishingTreasures(player)) {
FishingTreasure treasure = rewards.get(random.nextInt(rewards.size()));
if (random.nextDouble() * 100 <= treasure.getDropChance()) {
Users.getProfile(player).addXP(SkillType.FISHING, treasure.getXp());
int randomChance = 100;
if (player.hasPermission("mcmmo.perks.lucky.fishing")) {
randomChance = (int) (randomChance * 0.75);
}
if (random.nextDouble() * randomChance <= treasure.getDropChance()) {
Users.getPlayer(player).addXP(SkillType.FISHING, treasure.getXp());
theCatch.setItemStack(treasure.getDrop());
}
}
@@ -117,7 +123,7 @@ public class Fishing {
theCatch.getItemStack().setDurability((short) (random.nextInt(maxDurability))); //Change durability to random value
}
Skills.xpProcessing(player, PP, SkillType.FISHING, Config.getInstance().getFishingBaseXP());
Skills.xpProcessing(player, profile, SkillType.FISHING, Config.getInstance().getFishingBaseXP());
}
/**
@@ -127,7 +133,7 @@ public class Fishing {
*/
public static void processResults(PlayerFishEvent event) {
Player player = event.getPlayer();
PlayerProfile PP = Users.getProfile(player);
PlayerProfile profile = Users.getProfile(player);
getFishingResults(player, event);
Item theCatch = (Item) event.getCaught();
@@ -138,8 +144,15 @@ public class Fishing {
ItemStack fishingResults = theCatch.getItemStack();
player.sendMessage(LocaleLoader.getString("Fishing.ItemFound"));
if (ItemChecks.isArmor(fishingResults) || ItemChecks.isTool(fishingResults)) {
if (random.nextInt(100) <= ENCHANTMENT_CHANCE && Permissions.getInstance().fishingMagic(player)) {
int randomChance = 100;
if (player.hasPermission("mcmmo.perks.lucky.fishing")) {
randomChance = (int) (randomChance * 0.75);
}
if (random.nextInt(randomChance) <= ENCHANTMENT_CHANCE && Permissions.getInstance().fishingMagic(player)) {
for (Enchantment newEnchant : Enchantment.values()) {
if (newEnchant.canEnchantItem(fishingResults)) {
Map<Enchantment, Integer> resultEnchantments = fishingResults.getEnchantments();
@@ -151,7 +164,7 @@ public class Fishing {
}
/* Actual chance to have an enchantment is related to your fishing skill */
if (random.nextInt(15) < Fishing.getFishingLootTier(PP)) {
if (random.nextInt(15) < Fishing.getFishingLootTier(profile)) {
enchanted = true;
int randomEnchantLevel = random.nextInt(newEnchant.getMaxLevel()) + 1;
@@ -178,99 +191,105 @@ public class Fishing {
* @param event The event to modify
*/
public static void shakeMob(PlayerFishEvent event) {
final int DROP_NUMBER = random.nextInt(100);
int randomChance = 100;
if (event.getPlayer().hasPermission("mcmmo.perks.lucky.fishing")) {
randomChance = (int) (randomChance * 0.75);
}
final int DROP_NUMBER = random.nextInt(randomChance);
LivingEntity le = (LivingEntity) event.getCaught();
EntityType type = le.getType();
Location loc = le.getLocation();
Location location = le.getLocation();
switch (type) {
case BLAZE:
Misc.dropItem(loc, new ItemStack(Material.BLAZE_ROD));
Misc.dropItem(location, new ItemStack(Material.BLAZE_ROD));
break;
case CAVE_SPIDER:
if (DROP_NUMBER > 50) {
Misc.dropItem(loc, new ItemStack(Material.SPIDER_EYE));
Misc.dropItem(location, new ItemStack(Material.SPIDER_EYE));
}
else {
Misc.dropItem(loc, new ItemStack(Material.STRING));
Misc.dropItem(location, new ItemStack(Material.STRING));
}
break;
case CHICKEN:
if (DROP_NUMBER > 66) {
Misc.dropItem(loc, new ItemStack(Material.FEATHER));
Misc.dropItem(location, new ItemStack(Material.FEATHER));
}
else if (DROP_NUMBER > 33) {
Misc.dropItem(loc, new ItemStack(Material.RAW_CHICKEN));
Misc.dropItem(location, new ItemStack(Material.RAW_CHICKEN));
}
else {
Misc.dropItem(loc, new ItemStack(Material.EGG));
Misc.dropItem(location, new ItemStack(Material.EGG));
}
break;
case COW:
if (DROP_NUMBER > 99) {
Misc.dropItem(loc, new ItemStack(Material.MILK_BUCKET));
Misc.dropItem(location, new ItemStack(Material.MILK_BUCKET));
}
else if (DROP_NUMBER > 50) {
Misc.dropItem(loc, new ItemStack(Material.LEATHER));
Misc.dropItem(location, new ItemStack(Material.LEATHER));
}
else {
Misc.dropItem(loc, new ItemStack(Material.RAW_BEEF));
Misc.dropItem(location, new ItemStack(Material.RAW_BEEF));
}
break;
case CREEPER:
Misc.dropItem(loc, new ItemStack(Material.SULPHUR));
Misc.dropItem(location, new ItemStack(Material.SULPHUR));
break;
case ENDERMAN:
Misc.dropItem(loc, new ItemStack(Material.ENDER_PEARL));
Misc.dropItem(location, new ItemStack(Material.ENDER_PEARL));
break;
case GHAST:
if (DROP_NUMBER > 50) {
Misc.dropItem(loc, new ItemStack(Material.SULPHUR));
Misc.dropItem(location, new ItemStack(Material.SULPHUR));
}
else {
Misc.dropItem(loc, new ItemStack(Material.GHAST_TEAR));
Misc.dropItem(location, new ItemStack(Material.GHAST_TEAR));
}
break;
case MAGMA_CUBE:
Misc.dropItem(loc, new ItemStack(Material.MAGMA_CREAM));
Misc.dropItem(location, new ItemStack(Material.MAGMA_CREAM));
break;
case MUSHROOM_COW:
if (DROP_NUMBER > 99) {
Misc.dropItem(loc, new ItemStack(Material.MILK_BUCKET));
Misc.dropItem(location, new ItemStack(Material.MILK_BUCKET));
}
else if (DROP_NUMBER > 98) {
Misc.dropItem(loc, new ItemStack(Material.MUSHROOM_SOUP));
Misc.dropItem(location, new ItemStack(Material.MUSHROOM_SOUP));
}
else if (DROP_NUMBER > 66) {
Misc.dropItem(loc, new ItemStack(Material.LEATHER));
Misc.dropItem(location, new ItemStack(Material.LEATHER));
}
else if (DROP_NUMBER > 33) {
Misc.dropItem(loc, new ItemStack(Material.RAW_BEEF));
Misc.dropItem(location, new ItemStack(Material.RAW_BEEF));
}
else {
Misc.dropItems(loc, new ItemStack(Material.RED_MUSHROOM), 3);
Misc.dropItems(location, new ItemStack(Material.RED_MUSHROOM), 3);
}
break;
case PIG:
Misc.dropItem(loc, new ItemStack(Material.PORK));
Misc.dropItem(location, new ItemStack(Material.PORK));
break;
case PIG_ZOMBIE:
if (DROP_NUMBER > 50) {
Misc.dropItem(loc, new ItemStack(Material.ROTTEN_FLESH));
Misc.dropItem(location, new ItemStack(Material.ROTTEN_FLESH));
}
else {
Misc.dropItem(loc, new ItemStack(Material.GOLD_NUGGET));
Misc.dropItem(location, new ItemStack(Material.GOLD_NUGGET));
}
break;
@@ -284,48 +303,48 @@ public class Fishing {
ItemStack theWool = wool.toItemStack();
theWool.setAmount(1 + random.nextInt(6));
Misc.dropItem(loc, theWool);
Misc.dropItem(location, theWool);
sheep.setSheared(true);
}
break;
case SKELETON:
if (DROP_NUMBER > 50) {
Misc.dropItem(loc, new ItemStack(Material.BONE));
Misc.dropItem(location, new ItemStack(Material.BONE));
}
else {
Misc.dropItems(loc, new ItemStack(Material.ARROW), 3);
Misc.dropItems(location, new ItemStack(Material.ARROW), 3);
}
break;
case SLIME:
Misc.dropItem(loc, new ItemStack(Material.SLIME_BALL));
Misc.dropItem(location, new ItemStack(Material.SLIME_BALL));
break;
case SNOWMAN:
if (DROP_NUMBER > 99) {
Misc.dropItem(loc, new ItemStack(Material.PUMPKIN));
Misc.dropItem(location, new ItemStack(Material.PUMPKIN));
}
else {
Misc.dropItems(loc, new ItemStack(Material.SNOW_BALL), 5);
Misc.dropItems(location, new ItemStack(Material.SNOW_BALL), 5);
}
break;
case SPIDER:
if (DROP_NUMBER > 50) {
Misc.dropItem(loc, new ItemStack(Material.SPIDER_EYE));
Misc.dropItem(location, new ItemStack(Material.SPIDER_EYE));
}
else {
Misc.dropItem(loc, new ItemStack(Material.STRING));
Misc.dropItem(location, new ItemStack(Material.STRING));
}
break;
case SQUID:
Misc.dropItem(loc, new ItemStack(Material.INK_SACK, 1, (short) 0, (byte) 0x0));
Misc.dropItem(location, new ItemStack(Material.INK_SACK, 1, (short) 0, (byte) 0x0));
break;
case ZOMBIE:
Misc.dropItem(loc, new ItemStack(Material.ROTTEN_FLESH));
Misc.dropItem(location, new ItemStack(Material.ROTTEN_FLESH));
break;
default:

View File

@@ -17,6 +17,7 @@ import com.gmail.nossr50.config.mods.CustomBlocksConfig;
import com.gmail.nossr50.datatypes.AbilityType;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.datatypes.mods.CustomBlock;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.runnables.GreenThumbTimer;
import com.gmail.nossr50.util.Misc;
@@ -74,15 +75,15 @@ public class Herbalism {
* @param plugin mcMMO plugin instance
*/
public static void herbalismProcCheck(final Block block, Player player, BlockBreakEvent event, mcMMO plugin) {
final PlayerProfile PP = Users.getProfile(player);
final PlayerProfile profile = Users.getProfile(player);
final int MAX_BONUS_LEVEL = 1000;
int herbLevel = PP.getSkillLevel(SkillType.HERBALISM);
int herbLevel = profile.getSkillLevel(SkillType.HERBALISM);
int id = block.getTypeId();
Material type = block.getType();
Byte data = block.getData();
Location loc = block.getLocation();
Location location = block.getLocation();
Material mat = null;
int xp = 0;
@@ -91,6 +92,12 @@ public class Herbalism {
boolean customPlant = false;
int randomChance = 1000;
if (player.hasPermission("mcmmo.perks.lucky.herbalism")) {
randomChance = (int) (randomChance * 0.75);
}
switch (type) {
case BROWN_MUSHROOM:
case RED_MUSHROOM:
@@ -106,7 +113,7 @@ public class Herbalism {
if (b.getType().equals(Material.CACTUS)) {
mat = Material.CACTUS;
if (!mcMMO.placeStore.isTrue(b)) {
if (herbLevel > MAX_BONUS_LEVEL || random.nextInt(1000) <= herbLevel) {
if (herbLevel > MAX_BONUS_LEVEL || random.nextInt(randomChance) <= herbLevel) {
catciDrops++;
}
xp += Config.getInstance().getHerbalismXPCactus();
@@ -162,7 +169,7 @@ public class Herbalism {
if (b.getType().equals(Material.SUGAR_CANE_BLOCK)) {
mat = Material.SUGAR_CANE;
if (!mcMMO.placeStore.isTrue(b)) {
if (herbLevel > MAX_BONUS_LEVEL || random.nextInt(1000) <= herbLevel) {
if (herbLevel > MAX_BONUS_LEVEL || random.nextInt(randomChance) <= herbLevel) {
caneDrops++;
}
xp += Config.getInstance().getHerbalismXPSugarCane();
@@ -207,88 +214,100 @@ public class Herbalism {
is = new ItemStack(mat);
}
if (herbLevel > MAX_BONUS_LEVEL || random.nextInt(1000) <= herbLevel) {
if (herbLevel > MAX_BONUS_LEVEL || random.nextInt(randomChance) <= herbLevel) {
Config configInstance = Config.getInstance();
switch (type) {
case BROWN_MUSHROOM:
if (configInstance.getBrownMushroomsDoubleDropsEnabled()) {
Misc.dropItem(loc, is);
Misc.dropItem(location, is);
}
break;
case CACTUS:
if (configInstance.getCactiDoubleDropsEnabled()) {
Misc.dropItems(loc, is, catciDrops);
Misc.dropItems(location, is, catciDrops);
}
break;
case CROPS:
if (configInstance.getWheatDoubleDropsEnabled()) {
Misc.dropItem(loc, is);
Misc.dropItem(location, is);
}
break;
case MELON_BLOCK:
if (configInstance.getMelonsDoubleDropsEnabled()) {
Misc.dropItems(loc, is, 3);
Misc.randomDropItems(loc, is, 50, 4);
Misc.dropItems(location, is, 3);
Misc.randomDropItems(location, is, 50, 4);
}
break;
case NETHER_WARTS:
if (configInstance.getNetherWartsDoubleDropsEnabled()) {
Misc.dropItems(loc, is, 2);
Misc.randomDropItems(loc, is, 50, 3);
Misc.dropItems(location, is, 2);
Misc.randomDropItems(location, is, 50, 3);
}
break;
case PUMPKIN:
if (configInstance.getPumpkinsDoubleDropsEnabled()) {
Misc.dropItem(loc, is);
Misc.dropItem(location, is);
}
break;
case RED_MUSHROOM:
if (configInstance.getRedMushroomsDoubleDropsEnabled()) {
Misc.dropItem(loc, is);
Misc.dropItem(location, is);
}
break;
case SUGAR_CANE_BLOCK:
if (configInstance.getSugarCaneDoubleDropsEnabled()) {
Misc.dropItems(loc, is, caneDrops);
Misc.dropItems(location, is, caneDrops);
}
break;
case VINE:
if (configInstance.getVinesDoubleDropsEnabled()) {
Misc.dropItem(loc, is);
Misc.dropItem(location, is);
}
break;
case WATER_LILY:
if (configInstance.getWaterLiliesDoubleDropsEnabled()) {
Misc.dropItem(loc, is);
Misc.dropItem(location, is);
}
break;
case YELLOW_FLOWER:
if (configInstance.getYellowFlowersDoubleDropsEnabled()) {
Misc.dropItem(loc, is);
Misc.dropItem(location, is);
}
break;
default:
if (customPlant) {
Misc.dropItem(loc, is);
CustomBlock customBlock = ModChecks.getCustomBlock(block);
int minimumDropAmount = customBlock.getMinimumDropAmount();
int maximumDropAmount = customBlock.getMaximumDropAmount();
is = customBlock.getItemDrop();
if (minimumDropAmount != maximumDropAmount) {
Misc.dropItems(location, is, minimumDropAmount);
Misc.randomDropItems(location, is, 50, maximumDropAmount - minimumDropAmount);
}
else {
Misc.dropItems(location, is, minimumDropAmount);
}
}
break;
}
}
}
Skills.xpProcessing(player, PP, SkillType.HERBALISM, xp);
Skills.xpProcessing(player, profile, SkillType.HERBALISM, xp);
}
/**
@@ -302,19 +321,25 @@ public class Herbalism {
private static void greenThumbWheat(Block block, Player player, BlockBreakEvent event, mcMMO plugin) {
final int MAX_BONUS_LEVEL = 1500;
PlayerProfile PP = Users.getProfile(player);
int herbLevel = PP.getSkillLevel(SkillType.HERBALISM);
PlayerProfile profile = Users.getProfile(player);
int herbLevel = profile.getSkillLevel(SkillType.HERBALISM);
PlayerInventory inventory = player.getInventory();
boolean hasSeeds = inventory.contains(Material.SEEDS);
Location loc = block.getLocation();
Location location = block.getLocation();
if (hasSeeds && PP.getAbilityMode(AbilityType.GREEN_TERRA) || hasSeeds && (herbLevel > MAX_BONUS_LEVEL || random.nextInt(1500) <= herbLevel)) {
int randomChance = 1500;
if (player.hasPermission("mcmmo.perks.lucky.herbalism")) {
randomChance = (int) (randomChance * 0.75);
}
if (hasSeeds && profile.getAbilityMode(AbilityType.GREEN_TERRA) || hasSeeds && (herbLevel > MAX_BONUS_LEVEL || random.nextInt(randomChance) <= herbLevel)) {
event.setCancelled(true);
Misc.dropItem(loc, new ItemStack(Material.WHEAT));
Misc.randomDropItems(loc, new ItemStack(Material.SEEDS), 50, 3);
Misc.dropItem(location, new ItemStack(Material.WHEAT));
Misc.randomDropItems(location, new ItemStack(Material.SEEDS), 50, 3);
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new GreenThumbTimer(block, PP), 1);
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new GreenThumbTimer(block, profile), 1);
inventory.removeItem(new ItemStack(Material.SEEDS));
player.updateInventory(); // Needed until replacement available
@@ -331,13 +356,19 @@ public class Herbalism {
public static void greenThumbBlocks(ItemStack is, Player player, Block block) {
final int MAX_BONUS_LEVEL = 1500;
PlayerProfile PP = Users.getProfile(player);
int skillLevel = PP.getSkillLevel(SkillType.HERBALISM);
PlayerProfile profile = Users.getProfile(player);
int skillLevel = profile.getSkillLevel(SkillType.HERBALISM);
int seeds = is.getAmount();
player.setItemInHand(new ItemStack(Material.SEEDS, seeds - 1));
if (skillLevel > MAX_BONUS_LEVEL || random.nextInt(1500) <= skillLevel) {
int randomChance = 1500;
if (player.hasPermission("mcmmo.perks.lucky.herbalism")) {
randomChance = (int) (randomChance * 0.75);
}
if (skillLevel > MAX_BONUS_LEVEL || random.nextInt(randomChance) <= skillLevel) {
greenTerraConvert(player, block);
}
else {

View File

@@ -15,6 +15,7 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.datatypes.mods.CustomBlock;
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
import com.gmail.nossr50.spout.SpoutSounds;
import com.gmail.nossr50.util.Misc;
@@ -32,7 +33,7 @@ public class Mining {
* @param block The block to process drops for
*/
private static void silkTouchDrops(Block block) {
Location loc = block.getLocation();
Location location = block.getLocation();
Material type = block.getType();
ItemStack item = new ItemStack(type);
Config configInstance = Config.getInstance();
@@ -50,44 +51,44 @@ public class Mining {
case COAL_ORE:
if (configInstance.getCoalDoubleDropsEnabled()) {
Misc.dropItem(loc, item);
Misc.dropItem(location, item);
}
break;
case DIAMOND_ORE:
if (configInstance.getDiamondDoubleDropsEnabled()) {
Misc.dropItem(loc, item);
Misc.dropItem(location, item);
}
break;
case GLOWING_REDSTONE_ORE:
case REDSTONE_ORE:
if (configInstance.getRedstoneDoubleDropsEnabled()) {
Misc.dropItem(loc, item);
Misc.dropItem(location, item);
}
break;
case GLOWSTONE:
if (configInstance.getGlowstoneDoubleDropsEnabled()) {
Misc.dropItem(loc, item);
Misc.dropItem(location, item);
}
break;
case LAPIS_ORE:
if (configInstance.getLapisDoubleDropsEnabled()) {
Misc.dropItem(loc, item);
Misc.dropItem(location, item);
}
break;
case STONE:
if (configInstance.getStoneDoubleDropsEnabled()) {
Misc.dropItem(loc, item);
Misc.dropItem(location, item);
}
break;
default:
if (ModChecks.isCustomMiningBlock(block)) {
Misc.dropItem(loc, item);
Misc.dropItem(location, new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()));
}
break;
}
@@ -100,7 +101,7 @@ public class Mining {
* @param block The block to process drops for
*/
public static void miningDrops(Block block) {
Location loc = block.getLocation();
Location location = block.getLocation();
Material type = block.getType();
ItemStack item = new ItemStack(type);
Config configInstance = Config.getInstance();
@@ -109,20 +110,20 @@ public class Mining {
case COAL_ORE:
if (configInstance.getCoalDoubleDropsEnabled()) {
item = new ItemStack(Material.COAL, 1, (short) 0, CoalType.COAL.getData());
Misc.dropItem(loc, item);
Misc.dropItem(location, item);
}
break;
case DIAMOND_ORE:
if (configInstance.getDiamondDoubleDropsEnabled()) {
item = new ItemStack(Material.DIAMOND);
Misc.dropItem(loc, item);
Misc.dropItem(location, item);
}
break;
case ENDER_STONE:
if (configInstance.getEndStoneDoubleDropsEnabled()) {
Misc.dropItem(loc, item);
Misc.dropItem(location, item);
}
break;
@@ -130,74 +131,85 @@ public class Mining {
case REDSTONE_ORE:
if (configInstance.getRedstoneDoubleDropsEnabled()) {
item = new ItemStack(Material.REDSTONE);
Misc.dropItems(loc, item, 4);
Misc.randomDropItem(loc, item, 50);
Misc.dropItems(location, item, 4);
Misc.randomDropItem(location, item, 50);
}
break;
case GLOWSTONE:
if (configInstance.getGlowstoneDoubleDropsEnabled()) {
item = new ItemStack(Material.GLOWSTONE_DUST);
Misc.dropItems(loc, item, 2);
Misc.randomDropItems(loc, item, 50, 2);
Misc.dropItems(location, item, 2);
Misc.randomDropItems(location, item, 50, 2);
}
break;
case GOLD_ORE:
if (configInstance.getGoldDoubleDropsEnabled()) {
Misc.dropItem(loc, item);
Misc.dropItem(location, item);
}
break;
case IRON_ORE:
if (configInstance.getIronDoubleDropsEnabled()) {
Misc.dropItem(loc, item);
Misc.dropItem(location, item);
}
break;
case LAPIS_ORE:
if (configInstance.getLapisDoubleDropsEnabled()) {
item = new ItemStack(Material.INK_SACK, 1, (short) 0, (byte) 0x4);
Misc.dropItems(loc, item, 4);
Misc.randomDropItems(loc, item, 50, 4);
Misc.dropItems(location, item, 4);
Misc.randomDropItems(location, item, 50, 4);
}
break;
case MOSSY_COBBLESTONE:
if (configInstance.getMossyCobblestoneDoubleDropsEnabled()) {
Misc.dropItem(loc, item);
Misc.dropItem(location, item);
}
break;
case NETHERRACK:
if (configInstance.getNetherrackDoubleDropsEnabled()) {
Misc.dropItem(loc, item);
Misc.dropItem(location, item);
}
break;
case OBSIDIAN:
if (configInstance.getObsidianDoubleDropsEnabled()) {
Misc.dropItem(loc, item);
Misc.dropItem(location, item);
}
break;
case SANDSTONE:
if (configInstance.getSandstoneDoubleDropsEnabled()) {
Misc.dropItem(loc, item);
Misc.dropItem(location, item);
}
break;
case STONE:
if (configInstance.getStoneDoubleDropsEnabled()) {
item = new ItemStack(Material.COBBLESTONE);
Misc.dropItem(loc, item);
Misc.dropItem(location, item);
}
break;
default:
if (ModChecks.isCustomMiningBlock(block)) {
CustomBlock customBlock = ModChecks.getCustomBlock(block);
int minimumDropAmount = customBlock.getMinimumDropAmount();
int maximumDropAmount = customBlock.getMaximumDropAmount();
item = ModChecks.getCustomBlock(block).getItemDrop();
Misc.dropItem(loc, item);
if (minimumDropAmount != maximumDropAmount) {
Misc.dropItems(location, item, minimumDropAmount);
Misc.randomDropItems(location, item, 50, maximumDropAmount - minimumDropAmount);
}
else {
Misc.dropItems(location, item, minimumDropAmount);
}
}
break;
}
@@ -210,7 +222,7 @@ public class Mining {
* @param block The block to award XP for
*/
public static void miningXP(Player player, Block block) {
PlayerProfile PP = Users.getProfile(player);
PlayerProfile profile = Users.getProfile(player);
Material type = block.getType();
int xp = 0;
@@ -275,7 +287,7 @@ public class Mining {
break;
}
Skills.xpProcessing(player, PP, SkillType.MINING, xp);
Skills.xpProcessing(player, profile, SkillType.MINING, xp);
}
/**
@@ -295,7 +307,13 @@ public class Mining {
int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.MINING);
int skillCheck = Misc.skillCheck(skillLevel, MAX_BONUS_LEVEL);
if (random.nextInt(1000) <= skillCheck && Permissions.getInstance().miningDoubleDrops(player)) {
int randomChance = 1000;
if (player.hasPermission("mcmmo.perks.lucky.mining")) {
randomChance = (int) (randomChance * 0.75);
}
if (random.nextInt(randomChance) <= skillCheck && Permissions.getInstance().miningDoubleDrops(player)) {
if (player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
silkTouchDrops(block);
}
@@ -322,7 +340,7 @@ public class Mining {
return;
}
if (mcMMO.placeStore.isTrue(block)) {
if (mcMMO.placeStore.isTrue(block) || Misc.blockBreakSimulate(block, player, true)) {
return;
}
@@ -379,6 +397,9 @@ public class Mining {
if (mcMMO.spoutEnabled) {
SpoutSounds.playSoundForPlayer(SoundEffect.POP, player, block.getLocation());
}
default:
return;
}
}
}

View File

@@ -41,12 +41,12 @@ public class WoodCutting {
public static void treeFeller(BlockBreakEvent event) {
Player player = event.getPlayer();
Block firstBlock = event.getBlock();
PlayerProfile PP = Users.getProfile(player);
PlayerProfile profile = Users.getProfile(player);
ArrayList<Block> toBeFelled = new ArrayList<Block>();
/* NOTE: Tree Feller will cut upwards like how you actually fell trees */
processTreeFelling(firstBlock, toBeFelled);
removeBlocks(toBeFelled, player, PP);
removeBlocks(toBeFelled, player, profile);
}
/**
@@ -54,9 +54,9 @@ public class WoodCutting {
*
* @param toBeFelled List of Blocks to be removed from the tree
* @param player The player using the ability
* @param PP The PlayerProfile of the player
* @param profile The PlayerProfile of the player
*/
private static void removeBlocks(ArrayList<Block> toBeFelled, Player player, PlayerProfile PP) {
private static void removeBlocks(ArrayList<Block> toBeFelled, Player player, PlayerProfile profile) {
if (toBeFelled.size() >= Config.getInstance().getTreeFellerThreshold()) {
player.sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFellerThreshold"));
return;
@@ -116,7 +116,18 @@ public class WoodCutting {
x.setData((byte) 0x0);
x.setType(Material.AIR);
Misc.dropItem(x.getLocation(), item);
int minimumDropAmount = block.getMinimumDropAmount();
int maximumDropAmount = block.getMaximumDropAmount();
item = block.getItemDrop();
if (minimumDropAmount != maximumDropAmount) {
Misc.dropItems(x.getLocation(), item, minimumDropAmount);
Misc.randomDropItems(x.getLocation(), item, 50, maximumDropAmount - minimumDropAmount);
}
else {
Misc.dropItems(x.getLocation(), item, minimumDropAmount);
}
}
else if (ModChecks.isCustomLeafBlock(x)) {
CustomBlock block = ModChecks.getCustomBlock(x);
@@ -202,7 +213,7 @@ public class WoodCutting {
}
if (Permissions.getInstance().woodcutting(player)) {
Skills.xpProcessing(player, PP, SkillType.WOODCUTTING, xp);
Skills.xpProcessing(player, profile, SkillType.WOODCUTTING, xp);
}
}
@@ -289,53 +300,68 @@ public class WoodCutting {
byte type = block.getData();
Material mat = Material.getMaterial(block.getTypeId());
Tree tree = (Tree) block.getState().getData();
TreeSpecies species = tree.getSpecies();
int randomChance = 1000;
if ((skillLevel > MAX_SKILL_LEVEL || random.nextInt(1000) <= skillLevel) && Permissions.getInstance().woodcuttingDoubleDrops(player)) {
if (player.hasPermission("mcmmo.perks.lucky.woodcutting")) {
randomChance = (int) (randomChance * 0.75);
}
if ((skillLevel > MAX_SKILL_LEVEL || random.nextInt(randomChance) <= skillLevel) && Permissions.getInstance().woodcuttingDoubleDrops(player)) {
Config configInstance = Config.getInstance();
ItemStack item;
Location location;
if (configInstance.getBlockModsEnabled() && ModChecks.isCustomLogBlock(block)) {
item = ModChecks.getCustomBlock(block).getItemDrop();
CustomBlock customBlock = ModChecks.getCustomBlock(block);
int minimumDropAmount = customBlock.getMinimumDropAmount();
int maximumDropAmount = customBlock.getMaximumDropAmount();
item = customBlock.getItemDrop();
location = block.getLocation();
Misc.dropItem(location, item);
return;
if (minimumDropAmount != maximumDropAmount) {
Misc.dropItems(location, item, minimumDropAmount);
Misc.randomDropItems(location, item, 50, maximumDropAmount - minimumDropAmount);
}
else {
Misc.dropItems(location, item, minimumDropAmount);
}
}
else {
item = new ItemStack(mat, 1, (short) 0, type);
location = block.getLocation();
}
/* Drop the block */
switch (species) {
case GENERIC:
if (configInstance.getOakDoubleDropsEnabled()) {
Misc.dropItem(location, item);
TreeSpecies species = TreeSpecies.getByData(type);
/* Drop the block */
switch (species) {
case GENERIC:
if (configInstance.getOakDoubleDropsEnabled()) {
Misc.dropItem(location, item);
}
break;
case REDWOOD:
if (configInstance.getSpruceDoubleDropsEnabled()) {
Misc.dropItem(location, item);
}
break;
case BIRCH:
if (configInstance.getBirchDoubleDropsEnabled()) {
Misc.dropItem(location, item);
}
break;
case JUNGLE:
if (configInstance.getJungleDoubleDropsEnabled()) {
Misc.dropItem(location, item);
}
break;
default:
break;
}
break;
case REDWOOD:
if (configInstance.getSpruceDoubleDropsEnabled()) {
Misc.dropItem(location, item);
}
break;
case BIRCH:
if (configInstance.getBirchDoubleDropsEnabled()) {
Misc.dropItem(location, item);
}
break;
case JUNGLE:
if (configInstance.getJungleDoubleDropsEnabled()) {
Misc.dropItem(location, item);
}
break;
default:
break;
}
}
}
@@ -347,9 +373,8 @@ public class WoodCutting {
* @param block The block being broken
*/
public static void woodcuttingBlockCheck(Player player, Block block) {
PlayerProfile PP = Users.getProfile(player);
PlayerProfile profile = Users.getProfile(player);
int xp = 0;
TreeSpecies species = TreeSpecies.getByData(block.getData());
if (mcMMO.placeStore.isTrue(block)) {
return;
@@ -359,6 +384,8 @@ public class WoodCutting {
xp = ModChecks.getCustomBlock(block).getXpGain();
}
else {
TreeSpecies species = TreeSpecies.getByData(block.getData());
switch (species) {
case GENERIC:
xp += Config.getInstance().getWoodcuttingXPOak();
@@ -382,7 +409,7 @@ public class WoodCutting {
}
WoodCutting.woodCuttingProcCheck(player, block);
Skills.xpProcessing(player, PP, SkillType.WOODCUTTING, xp);
Skills.xpProcessing(player, profile, SkillType.WOODCUTTING, xp);
}
/**

View File

@@ -31,18 +31,18 @@ public class Repair {
* Handle the XP gain for repair events.
*
* @param player Player repairing the item
* @param PP PlayerProfile of the repairing player
* @param profile PlayerProfile of the repairing player
* @param is Item being repaired
* @param durabilityBefore Durability of the item before repair
* @param modify Amount to modify the durability by
* @param boost True if the modifier is a boost, false if the modifier is a reduction
*/
protected static void xpHandler(Player player, PlayerProfile PP, short durabilityBefore, short durabilityAfter, double modify) {
protected static void xpHandler(Player player, PlayerProfile profile, short durabilityBefore, short durabilityAfter, double modify) {
short dif = (short) (durabilityBefore - durabilityAfter);
dif = (short) (dif * modify);
Skills.xpProcessing(player, PP, SkillType.REPAIR, dif * 10);
Skills.xpProcessing(player, profile, SkillType.REPAIR, dif * 10);
//CLANG CLANG
if (mcMMO.spoutEnabled) {
@@ -53,11 +53,11 @@ public class Repair {
/**
* Get current Arcane Forging rank.
*
* @param skillLevel The skill level of the player whose rank is being checked
* @param profile The PlayerProfile of the player to get the rank for
* @return The player's current Arcane Forging rank
*/
public static int getArcaneForgingRank(PlayerProfile PP) {
int skillLevel = PP.getSkillLevel(SkillType.REPAIR);
public static int getArcaneForgingRank(PlayerProfile profile) {
int skillLevel = profile.getSkillLevel(SkillType.REPAIR);
if (skillLevel >= configInstance.getArcaneForgingRankLevels4()) {
return 4;
@@ -104,12 +104,18 @@ public class Repair {
for (Entry<Enchantment, Integer> enchant : enchants.entrySet()) {
Enchantment enchantment = enchant.getKey();
if (random.nextInt(100) <= getEnchantChance(rank)) {
int randomChance = 100;
if (player.hasPermission("mcmmo.perks.lucky.repair")) {
randomChance = (int) (randomChance * 0.75);
}
if (random.nextInt(randomChance) <= getEnchantChance(rank)) {
int enchantLevel = enchant.getValue();
if (configInstance.getArcaneForgingDowngradeEnabled() && enchantLevel > 1) {
if (random.nextInt(100) <= getDowngradeChance(rank)) {
is.addEnchantment(enchantment, enchantLevel--);
is.addEnchantment(enchantment, --enchantLevel);
downgraded = true;
}
}
@@ -223,7 +229,13 @@ public class Repair {
int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.REPAIR);
if ((skillLevel > MAX_BONUS_LEVEL || random.nextInt(1000) <= skillLevel) && permInstance.repairBonus(player)) {
int randomChance = 1000;
if (player.hasPermission("mcmmo.perks.lucky.repair")) {
randomChance = (int) (randomChance * 0.75);
}
if ((skillLevel > MAX_BONUS_LEVEL || random.nextInt(randomChance) <= skillLevel) && permInstance.repairBonus(player)) {
player.sendMessage(LocaleLoader.getString("Repair.Skills.FeltEasy"));
return true;
}
@@ -238,21 +250,21 @@ public class Repair {
* @param anvilID The item ID of the anvil block
*/
public static void placedAnvilCheck(Player player, int anvilID) {
PlayerProfile PP = Users.getProfile(player);
PlayerProfile profile = Users.getProfile(player);
if (!PP.getPlacedAnvil()) {
if (!profile.getPlacedAnvil()) {
if (mcMMO.spoutEnabled) {
SpoutPlayer sPlayer = SpoutManager.getPlayer(player);
SpoutPlayer spoutPlayer = SpoutManager.getPlayer(player);
if (sPlayer.isSpoutCraftEnabled()) {
sPlayer.sendNotification("[mcMMO] Anvil Placed", "Right click to repair!", Material.getMaterial(anvilID)); //TODO: Use Locale
if (spoutPlayer.isSpoutCraftEnabled()) {
spoutPlayer.sendNotification("[mcMMO] Anvil Placed", "Right click to repair!", Material.getMaterial(anvilID)); //TODO: Use Locale
}
}
else {
player.sendMessage(LocaleLoader.getString("Repair.Listener.Anvil"));
}
PP.togglePlacedAnvil();
profile.togglePlacedAnvil();
}
}
}

View File

@@ -60,10 +60,10 @@ public class SimpleRepairManager implements RepairManager {
@Override
public void handleRepair(Player player, ItemStack item) {
// Load some variables for use
PlayerProfile PP = Users.getProfile(player);
PlayerProfile profile = Users.getProfile(player);
short startDurability = item.getDurability();
PlayerInventory inventory = player.getInventory();
int skillLevel = PP.getSkillLevel(SkillType.REPAIR);
int skillLevel = profile.getSkillLevel(SkillType.REPAIR);
Repairable repairable = repairables.get(item.getTypeId());
// Permissions checks on material and item types
@@ -147,7 +147,7 @@ public class SimpleRepairManager implements RepairManager {
removeOneFrom(inventory, repairItemLocation);
// Give out XP like candy
Repair.xpHandler(player, PP, startDurability, newDurability, repairable.getXpMultiplier());
Repair.xpHandler(player, profile, startDurability, newDurability, repairable.getXpMultiplier());
// Repair the item!
item.setDurability(newDurability);

View File

@@ -35,7 +35,13 @@ public class SwordsManager {
if (Combat.shouldBeAffected(player, defender)) {
BleedEventHandler eventHandler = new BleedEventHandler(this, defender);
if (Swords.getRandom().nextInt(1000) < eventHandler.skillModifier) {
int randomChance = 1000;
if (player.hasPermission("mcmmo.perks.lucky.swords")) {
randomChance = (int) (randomChance * 0.75);
}
if (Swords.getRandom().nextInt(randomChance) < eventHandler.skillModifier) {
eventHandler.addBleedTicks();
eventHandler.sendAbilityMessages();
}
@@ -52,7 +58,13 @@ public class SwordsManager {
if (eventHandler.isHoldingSword()) {
eventHandler.calculateSkillModifier();
if (Swords.getRandom().nextInt(2000) < eventHandler.skillModifier) {
int randomChance = 2000;
if (player.hasPermission("mcmmo.perks.lucky.swords")) {
randomChance = (int) (randomChance * 0.75);
}
if (Swords.getRandom().nextInt(randomChance) < eventHandler.skillModifier) {
eventHandler.dealDamage();
eventHandler.sendAbilityMessages();
}
@@ -66,7 +78,7 @@ public class SwordsManager {
SerratedStrikesEventHandler eventHandler = new SerratedStrikesEventHandler(this, target, damage);
eventHandler.applyAbilityEffects();
eventHandler.applyAbilityEffects();
}
protected int getSkillLevel() {

View File

@@ -55,8 +55,7 @@ public class CallOfTheWildEventHandler {
}
protected void spawnCreature() {
// LivingEntity entity = (LivingEntity) player.getWorld().spawnEntity(player.getLocation(), type);
LivingEntity entity = player.getWorld().spawnCreature(player.getLocation(), type);
LivingEntity entity = (LivingEntity) player.getWorld().spawnEntity(player.getLocation(), type);
entity.setMetadata("mcmmoSummoned", new FixedMetadataValue(mcMMO.p, true));
((Tameable) entity).setOwner(player);

View File

@@ -41,7 +41,13 @@ public class TamingManager {
}
if (skillLevel >= Taming.FAST_FOOD_SERVICE_ACTIVATION_LEVEL) {
if (Taming.getRandom().nextInt(100) < Taming.FAST_FOOD_SERVICE_ACTIVATION_CHANCE) {
int randomChance = 100;
if (player.hasPermission("mcmmo.perks.lucky.taming")) {
randomChance = (int) (randomChance * 0.75);
}
if (Taming.getRandom().nextInt(randomChance) < Taming.FAST_FOOD_SERVICE_ACTIVATION_CHANCE) {
FastFoodServiceEventHandler eventHandler = new FastFoodServiceEventHandler(wolf);
eventHandler.modifyHealth(damage);
@@ -78,7 +84,13 @@ public class TamingManager {
GoreEventHandler eventHandler = new GoreEventHandler(this, event);
if (Taming.getRandom().nextInt(1000) < eventHandler.skillModifier) {
int randomChance = 1000;
if (player.hasPermission("mcmmo.perks.lucky.taming")) {
randomChance = (int) (randomChance * 0.75);
}
if (Taming.getRandom().nextInt(randomChance) < eventHandler.skillModifier) {
eventHandler.modifyEventDamage();
eventHandler.applyBleed();
eventHandler.sendAbilityMessage();

View File

@@ -3,7 +3,9 @@ package com.gmail.nossr50.skills.unarmed;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Users;
public class IronGripEventHandler {
private UnarmedManager manager;
@@ -18,7 +20,7 @@ public class IronGripEventHandler {
}
protected void calculateSkillModifier() {
this.skillModifier = Misc.skillCheck(manager.getSkillLevel(), Unarmed.DISARM_MAX_BONUS_LEVEL);
this.skillModifier = Misc.skillCheck(Users.getProfile(defender).getSkillLevel(SkillType.UNARMED), Unarmed.IRON_GRIP_MAX_BONUS_LEVEL);
}
protected void sendAbilityMessages() {

View File

@@ -25,7 +25,7 @@ public class UnarmedBonusDamageEventHandler {
protected void modifyEventDamage() {
int damage = event.getDamage();
int unarmedBonus = (int) (damage + damageBonus);
int unarmedBonus = damage + damageBonus;
event.setDamage(damage + unarmedBonus);
}

View File

@@ -36,7 +36,13 @@ public class UnarmedManager {
if (eventHandler.isHoldingItem()) {
eventHandler.calculateSkillModifier();
if (Unarmed.getRandom().nextInt(3000) < eventHandler.skillModifier) {
int randomChance = 3000;
if (player.hasPermission("mcmmo.perks.lucky.unarmed")) {
randomChance = (int) (randomChance * 0.75);
}
if (Unarmed.getRandom().nextInt(randomChance) < eventHandler.skillModifier) {
if (!hasIronGrip(defender)) {
eventHandler.sendAbilityMessage();
eventHandler.handleDisarm();
@@ -58,7 +64,13 @@ public class UnarmedManager {
DeflectEventHandler eventHandler = new DeflectEventHandler(this, event);
if (Unarmed.getRandom().nextInt(2000) < eventHandler.skillModifier) {
int randomChance = 2000;
if (player.hasPermission("mcmmo.perks.lucky.unarmed")) {
randomChance = (int) (randomChance * 0.75);
}
if (Unarmed.getRandom().nextInt(randomChance) < eventHandler.skillModifier) {
eventHandler.cancelEvent();
eventHandler.sendAbilityMessage();
}
@@ -87,11 +99,19 @@ public class UnarmedManager {
* @return true if the defender was not disarmed, false otherwise
*/
private boolean hasIronGrip(Player defender) {
//TODO: Add permission for Iron Grip
if (!permissionsInstance.ironGrip(defender)) {
return false;
}
IronGripEventHandler eventHandler = new IronGripEventHandler(this, defender);
if (Unarmed.getRandom().nextInt(1000) < eventHandler.skillModifier) {
int randomChance = 1000;
if (defender.hasPermission("mcmmo.perks.lucky.unarmed")) {
randomChance = (int) (randomChance * 0.75);
}
if (Unarmed.getRandom().nextInt(randomChance) < eventHandler.skillModifier) {
eventHandler.sendAbilityMessages();
return true;
}

View File

@@ -19,10 +19,10 @@ public class SpoutSounds {
* @param location The location the sound should come from
*/
public static void playSoundForPlayer(SoundEffect effect, Player player, Location location) {
SoundManager SM = SpoutManager.getSoundManager();
SpoutPlayer sPlayer = SpoutManager.getPlayer(player);
SoundManager soundManager = SpoutManager.getSoundManager();
SpoutPlayer spoutPlayer = SpoutManager.getPlayer(player);
SM.playSoundEffect(sPlayer, effect, location);
soundManager.playSoundEffect(spoutPlayer, effect, location);
}
/**
@@ -31,11 +31,11 @@ public class SpoutSounds {
* @param player The player who repaired an item
*/
public static void playRepairNoise(Player player, mcMMO plugin) {
SoundManager SM = SpoutManager.getSoundManager();
SpoutPlayer sPlayer = SpoutManager.getPlayer(player);
SoundManager soundManager = SpoutManager.getSoundManager();
SpoutPlayer spoutPlayer = SpoutManager.getPlayer(player);
//If this is pulling from online, why have it in the jar?
SM.playCustomSoundEffect(plugin, sPlayer, "repair.wav", false);
soundManager.playCustomSoundEffect(plugin, spoutPlayer, "repair.wav", false);
}
/**
@@ -44,10 +44,10 @@ public class SpoutSounds {
* @param player The player who leveled up
*/
protected static void playLevelUpNoise(Player player, mcMMO plugin) {
SoundManager SM = SpoutManager.getSoundManager();
SpoutPlayer sPlayer = SpoutManager.getPlayer(player);
SoundManager soundManager = SpoutManager.getSoundManager();
SpoutPlayer spoutPlayer = SpoutManager.getPlayer(player);
//If this is pulling from online, why have it in the jar?
SM.playCustomSoundEffect(plugin, sPlayer, "level.wav", false);
soundManager.playCustomSoundEffect(plugin, spoutPlayer, "level.wav", false);
}
}

View File

@@ -8,7 +8,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
@@ -16,15 +15,14 @@ import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.getspout.spoutapi.SpoutManager;
import org.getspout.spoutapi.event.spout.SpoutCraftEnableEvent;
import org.getspout.spoutapi.keyboard.Keyboard;
import org.getspout.spoutapi.player.SpoutPlayer;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.SpoutConfig;
import com.gmail.nossr50.datatypes.HUDmmo;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.datatypes.popups.PopupMMO;
import com.gmail.nossr50.listeners.SpoutListener;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Users;
@@ -32,17 +30,13 @@ import com.gmail.nossr50.util.Users;
public class SpoutStuff {
private static mcMMO plugin = mcMMO.p;
public final static String spoutDirectory = mcMMO.mainDirectory + "Resources" + File.separator;
public final static String spoutDirectory = mcMMO.getMainDirectory() + "Resources" + File.separator;
public final static String hudDirectory = spoutDirectory + "HUD" + File.separator;
public final static String hudStandardDirectory = hudDirectory + "Standard" + File.separator;
public final static String hudRetroDirectory = hudDirectory + "Retro" + File.separator;
public final static String soundDirectory = spoutDirectory + "Sound" + File.separator;
private final static SpoutListener spoutListener = new SpoutListener(plugin);
public static HashMap<Player, HUDmmo> playerHUDs = new HashMap<Player, HUDmmo>();
public static HashMap<SpoutPlayer, PopupMMO> playerScreens = new HashMap<SpoutPlayer, PopupMMO>();
private final static SpoutListener spoutListener = new SpoutListener();
public static Keyboard keypress;
/**
@@ -52,24 +46,24 @@ public class SpoutStuff {
* @param theFilePath The name of the file path
*/
private static void writeFile(String theFileName, String theFilePath) {
OutputStream os = null;
JarFile jar = null;
try {
File currentFile = new File(theFilePath + theFileName);
JarFile jar = new JarFile(mcMMO.mcmmo);
jar = new JarFile(mcMMO.mcmmo);
JarEntry entry = jar.getJarEntry("resources/" + theFileName);
InputStream is = jar.getInputStream(entry);
byte[] buf = new byte[2048];
int nbRead;
OutputStream os = new BufferedOutputStream(new FileOutputStream(currentFile));
os = new BufferedOutputStream(new FileOutputStream(currentFile));
while ((nbRead = is.read(buf)) != -1) {
os.write(buf, 0, nbRead);
}
os.flush();
os.close();
}
catch (FileNotFoundException e) {
e.printStackTrace();
@@ -77,6 +71,26 @@ public class SpoutStuff {
catch (IOException e) {
e.printStackTrace();
}
finally {
if (os != null) {
try {
os.flush();
os.close();
}
catch (IOException ex) {
ex.printStackTrace();
}
}
if (jar != null) {
try {
jar.close();
}
catch (IOException ex) {
ex.printStackTrace();
}
}
}
}
/**
@@ -199,30 +213,15 @@ public class SpoutStuff {
plugin.getServer().getPluginManager().registerEvents(spoutListener, plugin);
}
/**
* Gets a Spout player from a player name.
*
* @param playerName The player name
* @return the SpoutPlayer related to this player name, null if there's no player online with that name.
*/
public static SpoutPlayer getSpoutPlayer(String playerName) {
for (Player x : plugin.getServer().getOnlinePlayers()) {
if (x.getName().equalsIgnoreCase(playerName)) {
return SpoutManager.getPlayer(x);
}
}
return null;
}
/**
* Handle level-up notifications through Spout.
*
* @param skillType The skill that leveled up
* @param sPlayer The player that leveled up
* @param spoutPlayer The player that leveled up
*/
public static void levelUpNotification(SkillType skillType, SpoutPlayer sPlayer) {
PlayerProfile PP = Users.getProfile(sPlayer);
int notificationTier = getNotificationTier(PP.getSkillLevel(skillType));
public static void levelUpNotification(SkillType skillType, SpoutPlayer spoutPlayer) {
PlayerProfile profile = Users.getProfile(spoutPlayer);
int notificationTier = getNotificationTier(profile.getSkillLevel(skillType));
Material mat = null;
switch (skillType) {
@@ -538,8 +537,8 @@ public class SpoutStuff {
}
//TODO: Use Locale
sPlayer.sendNotification(ChatColor.GREEN + "Level Up!", ChatColor.YELLOW + Misc.getCapitalized(skillType.toString()) + ChatColor.DARK_AQUA + " (" + ChatColor.GREEN + PP.getSkillLevel(skillType) + ChatColor.DARK_AQUA + ")", mat);
SpoutSounds.playLevelUpNoise(sPlayer, plugin);
spoutPlayer.sendNotification(ChatColor.GREEN + "Level Up!", ChatColor.YELLOW + Misc.getCapitalized(skillType.toString()) + ChatColor.DARK_AQUA + " (" + ChatColor.GREEN + profile.getSkillLevel(skillType) + ChatColor.DARK_AQUA + ")", mat);
SpoutSounds.playLevelUpNoise(spoutPlayer, plugin);
}
/**
@@ -567,11 +566,21 @@ public class SpoutStuff {
}
/**
* Update a player's Spout XP bar.
*
* @param player The player whose bar to update
* Re-enable SpoutCraft for players after a /reload
*/
public static void updateXpBar(Player player) {
playerHUDs.get(player).updateXpBarDisplay(Users.getProfile(player).getHUDType(), player); //Is there a reason we can't just do HUDmmo.updateXpBarDisplay?
public static void reloadSpoutPlayers() {
for (SpoutPlayer spoutPlayer : SpoutManager.getPlayerManager().getOnlinePlayers()) {
SpoutCraftEnableEvent spoutCraftEnableEvent = new SpoutCraftEnableEvent(spoutPlayer);
mcMMO.p.getServer().getPluginManager().callEvent(spoutCraftEnableEvent);
}
}
public static void reloadSpoutPlayer(Player player) {
SpoutPlayer spoutPlayer = SpoutManager.getPlayer(player);
if (spoutPlayer != null) {
SpoutCraftEnableEvent spoutCraftEnableEvent = new SpoutCraftEnableEvent(spoutPlayer);
mcMMO.p.getServer().getPluginManager().callEvent(spoutCraftEnableEvent);
}
}
}

View File

@@ -71,6 +71,10 @@ public class BlockChecks {
* @return true if the block should allow ability activation, false otherwise
*/
public static boolean abilityBlockCheck(Block block) {
if (customBlocksEnabled && CustomBlocksConfig.getInstance().customAbilityBlocks.contains(new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()))) {
return false;
}
switch (block.getType()) {
case BED_BLOCK:
case BREWING_STAND:
@@ -92,13 +96,14 @@ public class BlockChecks {
case WOODEN_DOOR:
case WORKBENCH:
return false;
}
if (block.getTypeId() == Config.getInstance().getRepairAnvilId()) {
return false;
}
else {
return true;
default:
if (block.getTypeId() == Config.getInstance().getRepairAnvilId()) {
return false;
}
else {
return true;
}
}
}

View File

@@ -61,7 +61,7 @@ public class Combat {
case PLAYER:
Player attacker = (Player) event.getDamager();
ItemStack itemInHand = attacker.getItemInHand();
PlayerProfile PPa = Users.getProfile(attacker);
PlayerProfile attackerProfile = Users.getProfile(attacker);
if (ItemChecks.isSword(itemInHand)) {
if (targetIsPlayer || targetIsTamedPet) {
@@ -79,11 +79,11 @@ public class Combat {
swordsManager.bleedCheck(target);
if (PPa.getAbilityMode(AbilityType.SERRATED_STRIKES)) {
if (attackerProfile.getAbilityMode(AbilityType.SERRATED_STRIKES)) {
swordsManager.serratedStrikes(target, event.getDamage());
}
startGainXp(attacker, PPa, target, SkillType.SWORDS);
startGainXp(attacker, attackerProfile, target, SkillType.SWORDS);
}
else if (ItemChecks.isAxe(itemInHand) && permInstance.axes(attacker)) {
if (targetIsPlayer || targetIsTamedPet) {
@@ -109,11 +109,11 @@ public class Combat {
Axes.impact(attacker, target, event);
}
if (PPa.getAbilityMode(AbilityType.SKULL_SPLIITER) && permInstance.skullSplitter(attacker)) {
if (attackerProfile.getAbilityMode(AbilityType.SKULL_SPLIITER) && permInstance.skullSplitter(attacker)) {
applyAbilityAoE(attacker, target, event.getDamage() / 2, SkillType.AXES);
}
startGainXp(attacker, PPa, target, SkillType.AXES);
startGainXp(attacker, attackerProfile, target, SkillType.AXES);
}
else if (itemInHand.getType() == Material.AIR && permInstance.unarmed(attacker)) {
if (targetIsPlayer || targetIsTamedPet) {
@@ -131,7 +131,7 @@ public class Combat {
unarmedManager.bonusDamage(event);
if (PPa.getAbilityMode(AbilityType.BERSERK) && permInstance.berserk(attacker)) {
if (attackerProfile.getAbilityMode(AbilityType.BERSERK) && permInstance.berserk(attacker)) {
event.setDamage((int) (event.getDamage() * 1.5));
}
@@ -139,7 +139,7 @@ public class Combat {
unarmedManager.disarmCheck((Player) target);
}
startGainXp(attacker, PPa, target, SkillType.UNARMED);
startGainXp(attacker, attackerProfile, target, SkillType.UNARMED);
}
else if (itemInHand.getType() == Material.BONE && target instanceof Tameable) {
TamingManager tamingManager = new TamingManager(attacker);
@@ -148,6 +148,7 @@ public class Combat {
}
break;
case WOLF:
Wolf wolf = (Wolf) damager;
@@ -173,6 +174,7 @@ public class Combat {
}
break;
case ARROW:
LivingEntity shooter = ((Arrow) damager).getShooter();
@@ -190,7 +192,9 @@ public class Combat {
}
archeryCheck((Player) shooter, target, event);
break;
default:
break;
}
@@ -253,8 +257,8 @@ public class Combat {
}
if (target != shooter) {
PlayerProfile PP = Users.getProfile(shooter);
startGainXp(shooter, PP, target, SkillType.ARCHERY);
PlayerProfile profile = Users.getProfile(shooter);
startGainXp(shooter, profile, target, SkillType.ARCHERY);
}
}
@@ -323,12 +327,6 @@ public class Combat {
* @param type The type of skill being used
*/
public static void applyAbilityAoE(Player attacker, LivingEntity target, int damage, SkillType type) {
ItemStack inHand = attacker.getItemInHand();
if (ModChecks.isCustomTool(inHand) && !ModChecks.getToolFromItemStack(inHand).isAbilityEnabled()) {
return;
}
int numberOfTargets = Misc.getTier(attacker.getItemInHand()); //The higher the weapon tier, the more targets you hit
int damageAmount = damage;
@@ -382,11 +380,11 @@ public class Combat {
* Start the task that gives combat XP.
*
* @param attacker The attacking player
* @param PP The player's PlayerProfile
* @param profile The player's PlayerProfile
* @param target The defending entity
* @param skillType The skill being used
*/
public static void startGainXp(Player attacker, PlayerProfile PP, LivingEntity target, SkillType skillType) {
public static void startGainXp(Player attacker, PlayerProfile profile, LivingEntity target, SkillType skillType) {
double baseXP = 0;
if (target instanceof Player) {
@@ -476,7 +474,7 @@ public class Combat {
}
if (baseXP != 0) {
mcMMO.p.getServer().getScheduler().scheduleSyncDelayedTask(mcMMO.p, new GainXp(attacker, PP, skillType, baseXP, target), 0);
mcMMO.p.getServer().getScheduler().scheduleSyncDelayedTask(mcMMO.p, new GainXp(attacker, profile, skillType, baseXP, target), 0);
}
}

View File

@@ -16,9 +16,11 @@ import com.gmail.nossr50.runnables.SQLReconnect;
public class Database {
private static String connectionString = "jdbc:mysql://" + Config.getInstance().getMySQLServerName() + ":" + Config.getInstance().getMySQLServerPort() + "/" + Config.getInstance().getMySQLDatabaseName() + "?user=" + Config.getInstance().getMySQLUserName() + "&password=" + Config.getInstance().getMySQLUserPassword();
private static String tablePrefix = Config.getInstance().getMySQLTablePrefix();
private static Connection conn = null;
private static Config configInstance = Config.getInstance();
private static String connectionString = "jdbc:mysql://" + configInstance.getMySQLServerName() + ":" + configInstance.getMySQLServerPort() + "/" + configInstance.getMySQLDatabaseName() + "?user=" + configInstance.getMySQLUserName() + "&password=" + configInstance.getMySQLUserPassword();
private static String tablePrefix = configInstance.getMySQLTablePrefix();
private static Connection connection = null;
private static mcMMO plugin = null;
private static long reconnectTimestamp = 0;
@@ -46,10 +48,12 @@ public class Database {
public static void connect() {
try {
System.out.println("[mcMMO] Attempting connection to MySQL...");
Properties conProperties = new Properties();
conProperties.put("autoReconnect", "false");
conProperties.put("maxReconnects", "0");
conn = DriverManager.getConnection(connectionString, conProperties);
Properties connectionProperties = new Properties();
connectionProperties.put("autoReconnect", "false");
connectionProperties.put("maxReconnects", "0");
connection = DriverManager.getConnection(connectionString, connectionProperties);
System.out.println("[mcMMO] Connection to MySQL was a success!");
}
catch (SQLException ex) {
@@ -123,43 +127,53 @@ public class Database {
*/
public void checkDatabaseStructure(DatabaseUpdate update) {
String sql = null;
ResultSet rs = null;
HashMap<Integer, ArrayList<String>> Rows = new HashMap<Integer, ArrayList<String>>();
ResultSet resultSet;
HashMap<Integer, ArrayList<String>> rows = new HashMap<Integer, ArrayList<String>>();
switch (update) {
case BLAST_MINING:
sql = "SELECT * FROM `"+tablePrefix+"cooldowns` ORDER BY `"+tablePrefix+"cooldowns`.`blast_mining` ASC LIMIT 0 , 30";
sql = "SELECT * FROM `" + tablePrefix + "cooldowns` ORDER BY `" + tablePrefix + "cooldowns`.`blast_mining` ASC LIMIT 0 , 30";
break;
case FISHING:
sql = "SELECT * FROM `"+tablePrefix+"experience` ORDER BY `"+tablePrefix+"experience`.`fishing` ASC LIMIT 0 , 30";
sql = "SELECT * FROM `" + tablePrefix + "experience` ORDER BY `" + tablePrefix + "experience`.`fishing` ASC LIMIT 0 , 30";
break;
default:
break;
}
try {
PreparedStatement stmt = conn.prepareStatement(sql);
if (stmt.executeQuery() != null) {
stmt.executeQuery();
rs = stmt.getResultSet();
while (rs.next()) {
ArrayList<String> Col = new ArrayList<String>();
for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
Col.add(rs.getString(i));
}
Rows.put(rs.getRow(), Col);
PreparedStatement statement = connection.prepareStatement(sql);
resultSet = statement.executeQuery();
while (resultSet.next()) {
ArrayList<String> column = new ArrayList<String>();
for (int i = 1; i <= resultSet.getMetaData().getColumnCount(); i++) {
column.add(resultSet.getString(i));
}
rows.put(resultSet.getRow(), column);
}
statement.close();
}
catch (SQLException ex) {
if (update.equals(DatabaseUpdate.BLAST_MINING)) {
switch (update) {
case BLAST_MINING:
System.out.println("Updating mcMMO MySQL tables for Blast Mining...");
write("ALTER TABLE `"+tablePrefix + "cooldowns` ADD `blast_mining` int(32) NOT NULL DEFAULT '0' ;");
}
else if (update.equals(DatabaseUpdate.FISHING)) {
break;
case FISHING:
System.out.println("Updating mcMMO MySQL tables for Fishing...");
write("ALTER TABLE `"+tablePrefix + "skills` ADD `fishing` int(10) NOT NULL DEFAULT '0' ;");
write("ALTER TABLE `"+tablePrefix + "experience` ADD `fishing` int(10) NOT NULL DEFAULT '0' ;");
break;
default:
break;
}
}
}
@@ -173,8 +187,9 @@ public class Database {
public boolean write(String sql) {
if (isConnected()) {
try {
PreparedStatement stmt = conn.prepareStatement(sql);
stmt.executeUpdate();
PreparedStatement statement = connection.prepareStatement(sql);
statement.executeUpdate();
statement.close();
return true;
}
catch (SQLException ex) {
@@ -185,6 +200,7 @@ public class Database {
else {
attemptReconnect();
}
return false;
}
@@ -194,24 +210,23 @@ public class Database {
* @param sql SQL query to execute
* @return the value in the first row / first field
*/
public Integer getInt(String sql) {
ResultSet rs = null;
Integer result = 0;
public int getInt(String sql) {
ResultSet resultSet;
int result = 0;
if (isConnected()) {
try {
PreparedStatement stmt = conn.prepareStatement(sql);
stmt = conn.prepareStatement(sql);
if (stmt.executeQuery() != null) {
stmt.executeQuery();
rs = stmt.getResultSet();
if (rs.next()) {
result = rs.getInt(1);
}
else {
result = 0;
}
PreparedStatement statement = connection.prepareStatement(sql);
resultSet = statement.executeQuery();
if (resultSet.next()) {
result = resultSet.getInt(1);
}
else {
result = 0;
}
statement.close();
}
catch (SQLException ex) {
printErrors(ex);
@@ -220,6 +235,7 @@ public class Database {
else {
attemptReconnect();
}
return result;
}
@@ -229,12 +245,14 @@ public class Database {
* @return the boolean value for whether or not we are connected
*/
public static boolean isConnected() {
if(conn == null)
if (connection == null) {
return false;
}
try {
return conn.isValid(3);
} catch (SQLException e) {
return connection.isValid(3);
}
catch (SQLException e) {
return false;
}
}
@@ -244,10 +262,13 @@ public class Database {
* This will check for a connection being present or not to prevent unneeded reconnection attempts
*/
public static void attemptReconnect() {
if(reconnectTimestamp + 60000 < System.currentTimeMillis()) {
final int RECONNECT_WAIT_TICKS = 60000;
final int RECONNECT_DELAY_TICKS = 1200;
if (reconnectTimestamp + RECONNECT_WAIT_TICKS < System.currentTimeMillis()) {
System.out.println("[mcMMO] Connection to MySQL was lost! Attempting to reconnect in 60 seconds..."); //Only reconnect if another attempt hasn't been made recently
reconnectTimestamp = System.currentTimeMillis();
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new SQLReconnect(plugin), 1200);
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new SQLReconnect(plugin), RECONNECT_DELAY_TICKS);
}
}
@@ -258,23 +279,25 @@ public class Database {
* @return the rows in this SQL query
*/
public HashMap<Integer, ArrayList<String>> read(String sql) {
ResultSet rs = null;
HashMap<Integer, ArrayList<String>> Rows = new HashMap<Integer, ArrayList<String>>();
ResultSet resultSet;
HashMap<Integer, ArrayList<String>> rows = new HashMap<Integer, ArrayList<String>>();
if (isConnected()) {
try {
PreparedStatement stmt = conn.prepareStatement(sql);
if (stmt.executeQuery() != null) {
stmt.executeQuery();
rs = stmt.getResultSet();
while (rs.next()) {
ArrayList<String> Col = new ArrayList<String>();
for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
Col.add(rs.getString(i));
}
Rows.put(rs.getRow(), Col);
PreparedStatement statement = connection.prepareStatement(sql);
resultSet = statement.executeQuery();
while (resultSet.next()) {
ArrayList<String> column = new ArrayList<String>();
for (int i = 1; i <= resultSet.getMetaData().getColumnCount(); i++) {
column.add(resultSet.getString(i));
}
rows.put(resultSet.getRow(), column);
}
statement.close();
}
catch (SQLException ex) {
printErrors(ex);
@@ -283,7 +306,8 @@ public class Database {
else {
attemptReconnect();
}
return Rows;
return rows;
}
private static void printErrors(SQLException ex) {

View File

@@ -26,13 +26,13 @@ public class Item {
}
private static void chimaeraWing(Player player) {
PlayerProfile PP = Users.getProfile(player);
PlayerProfile profile = Users.getProfile(player);
ItemStack inHand = player.getItemInHand();
Block block = player.getLocation().getBlock();
int amount = inHand.getAmount();
if (Permissions.getInstance().chimaeraWing(player) && inHand.getTypeId() == Config.getInstance().getChimaeraItemId()) {
if (Skills.cooldownOver(PP.getRecentlyHurt(), 60, player) && amount >= Config.getInstance().getChimaeraCost()) {
if (Skills.cooldownOver(profile.getRecentlyHurt(), 60, player) && amount >= Config.getInstance().getChimaeraCost()) {
player.setItemInHand(new ItemStack(Config.getInstance().getChimaeraItemId(), amount - Config.getInstance().getChimaeraCost()));
for (int y = 1; block.getY() + y < player.getWorld().getMaxHeight(); y++) {
@@ -52,8 +52,8 @@ public class Item {
player.sendMessage(LocaleLoader.getString("Item.ChimaeraWing.Pass"));
}
else if (!Skills.cooldownOver(PP.getRecentlyHurt(), 60, player) && amount >= Config.getInstance().getChimaeraCost()) {
player.sendMessage(LocaleLoader.getString("Item.Injured.Wait", new Object[] {Skills.calculateTimeLeft(PP.getRecentlyHurt(), 60)}));
else if (!Skills.cooldownOver(profile.getRecentlyHurt(), 60, player) && amount >= Config.getInstance().getChimaeraCost()) {
player.sendMessage(LocaleLoader.getString("Item.Injured.Wait", new Object[] {Skills.calculateTimeLeft(profile.getRecentlyHurt(), 60)}));
}
else if (amount <= Config.getInstance().getChimaeraCost()) {
player.sendMessage(LocaleLoader.getString("Skills.NeedMore")+ " " + ChatColor.GRAY + Misc.prettyItemString(Config.getInstance().getChimaeraItemId()));

View File

@@ -15,8 +15,8 @@ import com.gmail.nossr50.datatypes.Tree;
public class Leaderboard {
private static mcMMO plugin = mcMMO.p;
private static String leaderboardsDirectory = mcMMO.leaderboardDirectory;
private final static String location = mcMMO.usersFile;
private static String leaderboardsDirectory = mcMMO.getLeaderboardDirectory();
private final static String location = mcMMO.getUsersFile();
/**
* Create the leaderboards.

View File

@@ -45,7 +45,7 @@ public class ModChecks {
* Get the custom block associated with an block.
*
* @param block The block to check
* @return the armor if it exists, null otherwise
* @return the block if it exists, null otherwise
*/
public static CustomBlock getCustomBlock(Block block) {
if (!blocksInstance.customItems.contains(new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()))) {

View File

@@ -228,6 +228,10 @@ public class Permissions {
return player.hasPermission("mcmmo.ability.unarmed.deflect");
}
public boolean ironGrip(Player player) {
return player.hasPermission("mcmmo.ability.unarmed.irongrip");
}
/*
* MCMMO.ABILITY.ARCHERY.*
*/
@@ -379,6 +383,11 @@ public class Permissions {
public boolean party(Player player) {
return player.hasPermission("mcmmo.commands.party");
}
public boolean skillReset(Player player) {
return player.hasPermission("mcmmo.skillreset");
}
/*
* MCMMO.CHAT.*

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