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

Compare commits

..

96 Commits

Author SHA1 Message Date
GJ
13111a8d1b Fixed a few small bugs with Smelting. 2013-02-28 17:32:36 -05:00
GJ
bbbba12e95 Small TamingManager changes. Halting the rest of the major changes for
now to prepare for 1.4.00 release.
2013-02-28 12:13:13 -05:00
GJ
fbd016f86d Cleaning up our UnarmedManager 2013-02-28 11:52:56 -05:00
GJ
10e7fe5560 Minor Spout cleanup. 2013-02-28 11:24:38 -05:00
GJ
d5bcb4346e This typo was causing the config value to never be read properly. Fixes
#691
2013-02-28 09:22:53 -05:00
GJ
213b4763e7 Check the perms for these commands in the commands, otherwise they don't
work in console because they don't default to OP. Fixes #715
2013-02-28 08:58:59 -05:00
TfT_02
886515400d It's a modifier, not a multiplier. 2013-02-28 11:29:04 +01:00
TfT_02
c900edb261 Fixed a bug where the near party member counter was off. Closes #745 2013-02-28 11:28:28 +01:00
GJ
8fb8c67148 SwordsManager cleaning 2013-02-27 23:18:17 -05:00
GJ
499411f6a2 SmeltingManager cleaning. 2013-02-27 18:28:20 -05:00
GJ
c3eaec513b GIANT Blast Mining update. Lots of new config options in advanced.yml 2013-02-27 15:45:15 -05:00
nossr50
a7f858ab03 Added new Tree Feller algorithm for Huge Red Mushroom 2013-02-27 11:51:44 -08:00
GJ
5ba4dc7b77 Leave some room. 2013-02-27 08:33:06 -05:00
GJ
bbcc8f918e Hire another manager in charge of Herbalism. 2013-02-27 08:33:05 -05:00
bm01
356c97cd67 Fixed CME in BleedTimer 2013-02-27 13:49:56 +01:00
GJ
0bdd5b219f Finish off FishingManager. 2013-02-26 23:31:00 -05:00
GJ
90368d4ece Minor cleanup 2013-02-26 22:42:47 -05:00
GJ
ec12303834 Straighten up PartyitemShare a bit. 2013-02-26 22:39:35 -05:00
GJ
294393bd1c Work on FishingManager. 2013-02-26 22:38:22 -05:00
GJ
4aaaf01ab5 Fix NPE for SpoutPlayers 2013-02-26 19:36:21 -05:00
NuclearW
cbbe436a69 Added party itemShare mode: EQUAL
Slightly cleaner way of handling equal item sharing.
Reset the item share modifier back to base when a player leaves the party
Added a new config file for the itemWeights
Removed the debug messages.
Added Lapis_Ore to itemweights.yml
Drop the item on the ground if the winningPlayer's inventory is full.
Unneccesary
Added a feature which allows the party leader to toggle item share categories....
That should be the rest.
ItemWeights to Item_Weights
2013-02-26 18:46:15 -05:00
GJ
18510ba851 Don't check the permissions here. 2013-02-26 18:26:52 -05:00
GJ
0201ed332f Quit passing this event around. 2013-02-26 18:21:14 -05:00
GJ
e46ed07b94 Goodbye, unused imports. 2013-02-26 18:12:40 -05:00
GJ
3db6762531 Javadoc updates. 2013-02-26 18:08:28 -05:00
GJ
f388948f04 Hire an Excavation manager. 2013-02-26 18:06:30 -05:00
GJ
4392e6b9ab Minor tweaks. 2013-02-26 16:06:13 -05:00
GJ
38c3891533 Minor JD fixes. 2013-02-26 16:00:15 -05:00
GJ
a28d673eb7 Reworking the AxeManager. 2013-02-26 15:59:16 -05:00
GJ
55138f1599 Managers control everything relating to players. 2013-02-26 12:38:17 -05:00
GJ
0cd07cf2fd The functions, they do nothing! 2013-02-26 12:03:37 -05:00
GJ
ae1eda915b Use an iterator rather than that stupid lock boolean. 2013-02-26 10:32:06 -05:00
GJ
38cd395171 Clean up the bleed list a bit. 2013-02-26 10:13:40 -05:00
GJ
3aec0e5ef4 Using UUID is safer. 2013-02-26 10:07:00 -05:00
GJ
56bd782625 Getting it through Bukkit is bad. 2013-02-26 10:02:25 -05:00
GJ
d8904827ec This should have the same effect. 2013-02-26 10:01:37 -05:00
GJ
f767edba93 Add SpoutHudAPI for other GUI-related plugins to tweak our XP Bar. 2013-02-26 09:53:01 -05:00
GJ
07a0f43825 Don't need that anymore. 2013-02-26 09:42:22 -05:00
GJ
ec8581a835 Pass less events. 2013-02-26 09:41:47 -05:00
GJ
f5290c3256 Name 'em all the same. 2013-02-26 08:22:08 -05:00
GJ
070189a7fd Don't need those anymore. 2013-02-26 08:19:55 -05:00
GJ
d409610a55 Move Roll checks into the manager. 2013-02-26 08:19:21 -05:00
GJ
d46b134dbb Don't pass our events around so much. 2013-02-25 18:00:15 -05:00
NuclearW
5026bdcbd4 Add new child.yml config for picking parents of child skills 2013-02-25 16:58:37 -05:00
GJ
3607d0b9a1 Eclipse - still being stupid. 2013-02-25 16:58:06 -05:00
GJ
21b8626366 Put our managers on payroll, rather than firing them at the end of
their shift.
2013-02-25 16:54:46 -05:00
NuclearW
4c10fdf34a Use Debug Filter here 2013-02-25 16:00:09 -05:00
GJ
8001a928ea Ensure one type of mushroom is held before checking Shroom Terra. Fixes
#734
2013-02-25 11:51:29 -05:00
GJ
26c2134484 That's not the right function... 2013-02-25 09:59:35 -05:00
GJ
2373ca82ba Added "Shroom Thumb" ability to Herbalism. Closes #724 2013-02-25 09:58:25 -05:00
GJ
3bd9a30055 Javadoc fix 2013-02-25 09:23:49 -05:00
GJ
52467075b4 Need to force updates here. 2013-02-25 09:18:53 -05:00
GJ
9888fe6e09 We now need to watch these species too. 2013-02-25 08:02:35 -05:00
GJ
19068dee03 Fix Tree Feller not working but still awarding XP. 2013-02-25 08:01:06 -05:00
TfT_02
ca8204d8f4 Display 'leader' alias instead of 'owner' in /party help 2013-02-25 13:56:24 +01:00
TfT_02
35139815a6 Added alias for /party owner: "/party leader" 2013-02-25 13:42:11 +01:00
GJ
da1e03cbfc Eclipse is dumb and wasn't including these two files for some reason. 2013-02-25 07:30:06 -05:00
GJ
219667965f Add a few checks to prevent a player from joining a party more than
once.
2013-02-25 07:23:18 -05:00
GJ
ec8221610a Add a few more checks for sanity on the new ability buffs. 2013-02-24 23:57:30 -05:00
GJ
afe28d54c6 Fix Herbalism not replanting crops properly. 2013-02-24 23:49:55 -05:00
GJ
1eb225cae1 Stages are capped at 4. 2013-02-24 16:35:33 -05:00
GJ
e716e38386 Dividing by 4 was wrong. 2013-02-24 16:31:01 -05:00
GJ
1fe471b005 Fix Green Thumb not removing seeds when only one was left. Also fixed
Green Thumb not working on Cobblestone.
2013-02-24 15:32:33 -05:00
GJ
5cd542002e Only remove seed on greenThumb - Green Terra's already had the seed
removed the first time.
2013-02-24 14:04:54 -05:00
GJ
a485308fca Yes, we do. 2013-02-24 13:57:33 -05:00
GJ
9659ef65b9 Remove unused imports. 2013-02-24 13:57:33 -05:00
NuclearW
214079a3cd Configuration options for particles 2013-02-24 13:56:24 -05:00
GJ
e9dcb31002 Fixed issue with async chatting. Closes #731 2013-02-24 13:25:55 -05:00
NuclearW
3b05bb96e3 Change for only advanced.yml and config.yml to be auto-updated 2013-02-24 00:18:01 -05:00
NuclearW
54ca6e78f5 Revert "Fixing an IllegalArgumentException related to custom repair configs."
This reverts commit 3036d4fa90.
2013-02-24 00:01:01 -05:00
GJ
9759224690 Changed our custom chat events to be async 2013-02-23 21:29:15 -05:00
GJ
20970e430c Remove unused imports. 2013-02-23 18:14:15 -05:00
GJ
38155e3af4 Use the same MetadataValue for both of these 2013-02-23 18:13:12 -05:00
Glitchfinder
3036d4fa90 Fixing an IllegalArgumentException related to custom repair configs. 2013-02-23 13:51:21 -08:00
GJ
aba662e3d0 Fix for exploiting new Super Breaker enchants using the anvil. 2013-02-23 15:25:49 -05:00
GJ
301914d94b Fix ClassCastException with trying to use Woodcutting on Mushrooms. 2013-02-23 15:03:39 -05:00
GJ
8d16c06739 Don't make a new metadata value for every block every time. 2013-02-23 00:29:25 -05:00
NuclearW
7e1eeb66d6 Use -U if you want snapshot updates 2013-02-23 00:05:28 -05:00
NuclearW
920bdde135 NuclearW is a mean person who hates other peoples' code 2013-02-23 00:00:58 -05:00
shatteredbeam
1db9a554dc Added Graphs determining above or below default values for the global multiplier and the global curve modifier. 2013-02-22 20:54:15 -08:00
GJ
62aaad8707 Added "Holy Hound" ability to Taming 2013-02-22 18:47:34 -05:00
GJ
2fee9df625 Move more event handling back into the main listener to avoid passing
the event itself.
2013-02-22 17:55:31 -05:00
GJ
6c6ab4c96e We only need the block in here. 2013-02-22 17:55:30 -05:00
Glitchfinder
1d316f9420 Making the error reporting for enabling mcMMO more informative. 2013-02-22 11:10:35 -08:00
U-YUE\Sean
d2035f1816 Setting mcMMO to disable itself if it errors on load. Fixes most reloading errors. 2013-02-22 11:10:34 -08:00
U-YUE\Sean
fd821139bd Fixing an NPE related to the skillreset command. 2013-02-22 11:10:34 -08:00
U-YUE\Sean
7e6550d147 Unregistering events on disable. Should deal with edge cases regarding forced reloads. 2013-02-22 11:10:33 -08:00
GJ
e556b707c9 Fix for NPE when right/left clicking air. 2013-02-22 13:59:07 -05:00
GJ
9282b7bd15 Remove config caching from SkillTools.java 2013-02-22 13:53:16 -05:00
GJ
0d473d232e Remove config caching from CombatTools.java 2013-02-22 13:47:54 -05:00
GJ
f9ad8ffe93 This check was unneeded, we already verify that the player is, in fact,
a player before this check is ever called.
2013-02-22 13:40:36 -05:00
GJ
e85a0f6cfc Change Acrobatics roll handling to take event.getDamage() instead of the
event. Also adds a few new config options in advanced.yml for further
customizing roll behavior.
2013-02-22 13:39:47 -05:00
GJ
63974f3968 Passing the event is bad - pass just event.getDamage() instead. 2013-02-22 12:10:15 -05:00
NuclearW
3b07d4055a Added config option to make .new config files instead over writing over old ones when updating 2013-02-22 11:59:56 -05:00
NuclearW
d052d7a3ce Change from using Block to BlockState in many locations
Convert Herbalism ability to use BlockState instead of Block.
Move all block checks back to BlockChecks.
Don't need this if we're using BlockState
Convert Excavation to BlockState. We don't need to return booleans here
because we never edit the block state.Switch ModCheck.getCustomBlock to use BlockState
More work on the conversion to BlockState
More conversion to BlockState
Better way to handle mining drops, I believe.
Remove useless imports.
A test of making the diff look nicer
BlockChecks diff cleanup
Herbalism diff cleanup
Gotta update the block states here.
Moar blockstate.
Little more blockState stuff.
Even more blockstate.
2013-02-22 11:23:46 -05:00
GJ
513a9212e4 Back to active development. 2013-02-22 11:17:43 -05:00
127 changed files with 4154 additions and 4014 deletions

View File

@@ -36,6 +36,14 @@ Version 1.4.00-dev
+ Added config option to disable automatic zip backups.
+ Added particle effects for many abilities.
+ Added '/mcnotify' command to toggle ability notifications on/off
+ Added ability for config files to automatically update with new keys, and prune out old ones
+ Added config option to make .new config files instead over writing over old ones when updating
+ Added "Holy Hound" ability to Taming
+ Added "Shroom Thumb" ability to Herbalism
+ Added child.yml config file to choose parents for child skills
+ Added '/party itemshare <NONE | EQUAL | RANDOM>' command to choose party item share mode
+ Added '/party itemshare <loot | mining | herbalism | woodcutting> <true | false>' command to control items that are shared
+ Added itemweights.yml file to determine which items are more valuable for party itemshare
= Fixed Green Thumb on wheat not working properly at rank 4
= Fixed Green Thumb and Green Terra consuming twice the amount of seed needed
= Fixed Green Terra not also checking Green Thumb permissions
@@ -70,6 +78,8 @@ Version 1.4.00-dev
= Fixed a bug where a new party leader wasn't appointed, after the previous party leader left
= Fixed a bug where Disarm and Deflect had wrong values
= Fixed Magic Hunter (Fishing ability) favoring certain enchants
! Changed our custom chat events to be async
! Changed some config value key names regarding double drops and XP - make sure you copy any custom values to your new config after updating.
! Changed Green Terra blocks to be determined via permissions instead of the config file
! Config files are now backed up even when running in SQL mode
! Changed /p and /a to use /partychat and /adminchat as the default command name. The use of /p, /pc, /a, and /ac is still supported.

17
pom.xml
View File

@@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.gmail.nossr50.mcMMO</groupId>
<artifactId>mcMMO</artifactId>
<version>1.4.00-beta4</version>
<version>1.4.00-dev5</version>
<name>mcMMO</name>
<url>https://github.com/mcMMO-Dev/mcMMO</url>
<issueManagement>
@@ -129,29 +129,14 @@
</build>
<repositories>
<repository>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
<id>bukkit-repo</id>
<url>http://repo.bukkit.org/content/groups/public/</url>
</repository>
<repository>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
<id>spout-repo</id>
<url>http://nexus.spout.org/content/groups/public/</url>
</repository>
<repository>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
<id>Plugin MetricsExtension</id>
<url>http://repo.turt2live.com</url>
</repository>

View File

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

View File

@@ -14,8 +14,8 @@ import com.gmail.nossr50.party.Party;
public final class ChatManager {
public ChatManager () {}
public static void handleAdminChat(Plugin plugin, String playerName, String displayName, String message) {
McMMOAdminChatEvent chatEvent = new McMMOAdminChatEvent(plugin, playerName, displayName, message);
public static void handleAdminChat(Plugin plugin, String playerName, String displayName, String message, boolean isAsync) {
McMMOAdminChatEvent chatEvent = new McMMOAdminChatEvent(plugin, playerName, displayName, message, isAsync);
mcMMO.p.getServer().getPluginManager().callEvent(chatEvent);
if (chatEvent.isCancelled()) {
@@ -36,10 +36,14 @@ public final class ChatManager {
handleAdminChat(plugin, senderName, senderName, message);
}
public static void handlePartyChat(Plugin plugin, Party party, String playerName, String displayName, String message) {
public static void handleAdminChat(Plugin plugin, String playerName, String displayName, String message) {
handleAdminChat(plugin, playerName, displayName, message, false);
}
public static void handlePartyChat(Plugin plugin, Party party, String playerName, String displayName, String message, boolean isAsync) {
String partyName = party.getName();
McMMOPartyChatEvent chatEvent = new McMMOPartyChatEvent(plugin, playerName, displayName, partyName, message);
McMMOPartyChatEvent chatEvent = new McMMOPartyChatEvent(plugin, playerName, displayName, partyName, message, isAsync);
mcMMO.p.getServer().getPluginManager().callEvent(chatEvent);
if (chatEvent.isCancelled()) {
@@ -63,4 +67,8 @@ public final class ChatManager {
public static void handlePartyChat(Plugin plugin, Party party, String senderName, String message) {
handlePartyChat(plugin, party, senderName, senderName, message);
}
public static void handlePartyChat(Plugin plugin, Party party, String playerName, String displayName, String message) {
handlePartyChat(plugin, party, playerName, displayName, message, false);
}
}

View File

@@ -15,14 +15,12 @@ public class AdminChatCommand extends ChatCommand {
@Override
protected void handleChatSending(CommandSender sender, String[] args) {
String message = buildChatMessage(args, 0);
if (sender instanceof Player) {
Player player = (Player) sender;
ChatManager.handleAdminChat(mcMMO.p, player.getName(), player.getDisplayName(), message);
ChatManager.handleAdminChat(mcMMO.p, player.getName(), player.getDisplayName(), buildChatMessage(args, 0));
}
else {
ChatManager.handleAdminChat(mcMMO.p, LocaleLoader.getString("Commands.Chat.Console"), message);
ChatManager.handleAdminChat(mcMMO.p, LocaleLoader.getString("Commands.Chat.Console"), buildChatMessage(args, 0));
}
}
}

View File

@@ -253,7 +253,6 @@ public final class CommandRegistrationHelper {
public static void registerMcpurgeCommand() {
PluginCommand command = mcMMO.p.getCommand("mcpurge");
command.setDescription(LocaleLoader.getString("Commands.Description.mcpurge", Config.getInstance().getOldUsersCutoff()));
command.setPermission("mcmmo.commands.mcpurge");
command.setPermissionMessage(permissionsMessage);
command.setUsage(LocaleLoader.getString("Commands.Usage.0", "mcpurge"));
command.setExecutor(new McpurgeCommand());
@@ -262,7 +261,6 @@ public final class CommandRegistrationHelper {
public static void registerMcremoveCommand() {
PluginCommand command = mcMMO.p.getCommand("mcremove");
command.setDescription(LocaleLoader.getString("Commands.Description.mcremove"));
command.setPermission("mcmmo.commands.mcremove");
command.setPermissionMessage(permissionsMessage);
command.setUsage(LocaleLoader.getString("Commands.Usage.1", "mcremove", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">"));
command.setExecutor(new McremoveCommand());
@@ -271,7 +269,6 @@ public final class CommandRegistrationHelper {
public static void registerMmoupdateCommand() {
PluginCommand command = mcMMO.p.getCommand("mmoupdate");
command.setDescription(LocaleLoader.getString("Commands.Description.mmoupdate"));
command.setPermission("mcmmo.commands.mmoupdate");
command.setPermissionMessage(permissionsMessage);
command.setUsage(LocaleLoader.getString("Commands.Usage.0", "mmoupdate"));
command.setExecutor(new MmoupdateCommand());

View File

@@ -137,7 +137,7 @@ public class SkillresetCommand implements CommandExecutor {
continue;
}
if (!Permissions.skillresetOthers(sender, skill)) {
if (!Permissions.skillresetOthers(sender, skillType)) {
sender.sendMessage(command.getPermissionMessage());
continue;
}

View File

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

View File

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

View File

@@ -10,12 +10,11 @@ import com.gmail.nossr50.skills.utilities.AbilityType;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.StringUtils;
public class Config extends ConfigLoader {
public class Config extends AutoUpdateConfigLoader {
private static Config instance;
private Config() {
super("config.yml");
loadKeys();
}
public static Config getInstance() {
@@ -44,6 +43,8 @@ public class Config extends ConfigLoader {
public boolean getEventCallbackEnabled() { return config.getBoolean("General.Event_Callback", true); }
public boolean getBackupsEnabled() { return config.getBoolean("General.Generate_Backups", true); }
public boolean getVerboseLoggingEnabled() { return config.getBoolean("General.Verbose_Logging", false); }
public boolean getConfigOverwriteEnabled() { return config.getBoolean("General.Config_Update_Overwrite", true); }
public boolean getPartyDisplayNames() { return config.getBoolean("Commands.p.Use_Display_Names", true); }
public boolean getAdminDisplayNames() { return config.getBoolean("Commands.a.Use_Display_Names", true); }
@@ -104,6 +105,13 @@ public class Config extends ConfigLoader {
public int getChimaeraItemId() { return config.getInt("Items.Chimaera_Wing.Item_ID", 288); }
public boolean getChimaeraEnabled() { return config.getBoolean("Items.Chimaera_Wing.Enabled", true); }
/* Particles */
public boolean getAbilityActivationEffectEnabled() { return config.getBoolean("Particles.Ability_Activation", true); }
public boolean getAbilityDeactivationEffectEnabled() { return config.getBoolean("Particles.Ability_Deactivation", true); }
public boolean getDodgeEffectEnabled() { return config.getBoolean("Particles.Dodge", true); }
public boolean getBleedEffectEnabled() { return config.getBoolean("Particles.Bleed", true); }
public boolean getGreaterImpactEffectEnabled() { return config.getBoolean("Particles.Greater_Impact", true); }
/* PARTY SETTINGS */
public int getAutoPartyKickInterval() { return config.getInt("Party.AutoKick_Interval", 12); }
public int getAutoPartyKickTime() { return config.getInt("Party.Old_Party_Member_Cutoff", 7); }

View File

@@ -1,22 +1,14 @@
package com.gmail.nossr50.config;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.metrics.MetricsManager;
public abstract class ConfigLoader {
protected static final mcMMO plugin = mcMMO.p;
@@ -46,98 +38,6 @@ public abstract class ConfigLoader {
}
config = YamlConfiguration.loadConfiguration(configFile);
FileConfiguration internalConfig = YamlConfiguration.loadConfiguration(plugin.getResource(fileName));
Set<String> configKeys = config.getKeys(true);
Set<String> internalConfigKeys = internalConfig.getKeys(true);
boolean needSave = false;
Set<String> oldKeys = new HashSet<String>(configKeys);
oldKeys.removeAll(internalConfigKeys);
Set<String> newKeys = new HashSet<String>(internalConfigKeys);
newKeys.removeAll(configKeys);
// Don't need a re-save if we have old keys sticking around?
// Would be less saving, but less... correct?
if (!newKeys.isEmpty() || !oldKeys.isEmpty()) {
needSave = true;
}
for (String key : oldKeys) {
plugin.debug("Removing unused key: " + key);
config.set(key, null);
}
for (String key : newKeys) {
plugin.debug("Adding new key: " + key + " = " + internalConfig.get(key));
config.set(key, internalConfig.get(key));
}
if (needSave) {
// Get Bukkit's version of an acceptable config with new keys, and no old keys
String output = config.saveToString();
// Convert to the superior 4 space indentation
output = output.replace(" ", " ");
// Rip out Bukkit's attempt to save comments at the top of the file
while (output.indexOf('#') != -1) {
output = output.substring(output.indexOf('\n', output.indexOf('#'))+1);
}
// Read the internal config to get comments, then put them in the new one
try {
// Read internal
BufferedReader reader = new BufferedReader(new InputStreamReader(plugin.getResource(fileName)));
HashMap<String, String> comments = new HashMap<String, String>();
String temp = "";
String line;
while ((line = reader.readLine()) != null) {
if (line.contains("#")) {
temp += line + "\n";
}
else if (line.contains(":")) {
line = line.substring(0, line.indexOf(":") + 1);
if(!temp.isEmpty()) {
comments.put(line, temp);
temp = "";
}
}
}
// Dump to the new one
for (String key : comments.keySet()) {
if (output.indexOf(key) != -1) {
output = output.substring(0, output.indexOf(key)) + comments.get(key) + output.substring(output.indexOf(key));
}
}
}
catch (Exception e) {
e.printStackTrace();
}
// Save it
try {
BufferedWriter writer = new BufferedWriter(new FileWriter(new File(plugin.getDataFolder(), fileName)));
writer.write(output);
writer.flush();
writer.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
else {
for (String key : configKeys) {
if (!config.isConfigurationSection(key) && !config.get(key).equals(internalConfig.get(key))) {
MetricsManager.customConfig();
break;
}
}
}
}
protected abstract void loadKeys();

View File

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

View File

@@ -8,10 +8,16 @@ import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.database.Database;
import com.gmail.nossr50.database.Leaderboard;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
public class McpurgeCommand implements CommandExecutor{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!Permissions.mcpurge(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
switch (args.length) {
case 0:
if (Config.getInstance().getUseMySQL()) {

View File

@@ -8,10 +8,16 @@ import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.database.Database;
import com.gmail.nossr50.database.Leaderboard;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
public class McremoveCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!Permissions.mcremove(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
switch (args.length) {
case 1:
/* MySQL */

View File

@@ -9,11 +9,17 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.database.runnables.SQLConversionTask;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users;
public class MmoupdateCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!Permissions.mmoupdate(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
switch (args.length) {
case 0:
sender.sendMessage(LocaleLoader.getString("Commands.mmoupdate.Start"));

View File

@@ -1,5 +1,7 @@
package com.gmail.nossr50.datatypes;
import java.util.Set;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@@ -12,6 +14,7 @@ import com.gmail.nossr50.mods.datatypes.CustomTool;
import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.party.ShareHandler;
import com.gmail.nossr50.skills.child.FamilyTree;
import com.gmail.nossr50.skills.utilities.PerksUtils;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
@@ -28,6 +31,7 @@ public class McMMOPlayer {
private boolean ptpEnabled = true;
private boolean ptpConfirmRequired = Config.getInstance().getPTPCommandConfirmRequired();
private long ptpTimeout;
private int itemShareModifier;
private boolean partyChatMode;
private boolean adminChatMode;
@@ -66,10 +70,22 @@ public class McMMOPlayer {
* @param xp Experience amount to process
*/
public void beginXpGain(SkillType skillType, int xp) {
if (xp == 0) {
if (xp == 0) {
return;
}
if (skillType.isChildSkill()) {
Set<SkillType> parentSkills = FamilyTree.getParents(skillType);
for (SkillType parentSkill : parentSkills) {
if (Permissions.skillEnabled(player, parentSkill)) {
beginXpGain(parentSkill, xp / parentSkills.size());
}
}
return;
}
// Return if the experience has been shared
if (party != null && ShareHandler.handleXpShare(xp, this, skillType)) {
return;
@@ -242,6 +258,20 @@ public class McMMOPlayer {
ptpTimeout = (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR);
}
public int getItemShareModifier() {
if (itemShareModifier < 10) {
setItemShareModifier(10);
}
return itemShareModifier;
}
public void setItemShareModifier(int modifier) {
if (modifier < 10) {
modifier = 10;
}
itemShareModifier = modifier;
}
public boolean getAdminChatMode() {
return adminChatMode;
}

View File

@@ -6,10 +6,12 @@ import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.database.Database;
import com.gmail.nossr50.skills.child.FamilyTree;
import com.gmail.nossr50.skills.utilities.AbilityType;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.skills.utilities.ToolType;
@@ -902,13 +904,12 @@ public class PlayerProfile {
}
public int getChildSkillLevel(SkillType skillType) {
switch (skillType) {
case SMELTING:
return ((getSkillLevel(SkillType.MINING) / 4) + (getSkillLevel(SkillType.REPAIR) / 4)); //TODO: Make this cleaner somehow
default:
return 0;
Set<SkillType> parents = FamilyTree.getParents(skillType);
int sum = 0;
for (SkillType parent : parents) {
sum += Math.min(getSkillLevel(parent), 1000);
}
return sum / parents.size();
}
public int getSkillXpLevel(SkillType skillType) {

View File

@@ -9,4 +9,8 @@ public class McMMOAdminChatEvent extends McMMOChatEvent {
public McMMOAdminChatEvent(Plugin plugin, String sender, String displayName, String message) {
super(plugin, sender, displayName, message);
}
public McMMOAdminChatEvent(Plugin plugin, String sender, String displayName, String message, boolean isAsync) {
super(plugin, sender, displayName, message, isAsync);
}
}

View File

@@ -19,6 +19,14 @@ public abstract class McMMOChatEvent extends Event implements Cancellable {
this.message = message;
}
protected McMMOChatEvent(Plugin plugin, String sender, String displayName, String message, boolean isAsync) {
super(isAsync);
this.plugin = plugin;
this.sender = sender;
this.displayName = displayName;
this.message = message;
}
/**
* @return The plugin responsible for this event, note this can be null
*/

View File

@@ -13,6 +13,11 @@ public class McMMOPartyChatEvent extends McMMOChatEvent {
this.party = party;
}
public McMMOPartyChatEvent(Plugin plugin, String sender, String displayName, String party, String message, boolean isAsync) {
super(plugin, sender, displayName, message, isAsync);
this.party = party;
}
/**
* @return String name of the party the message will be sent to
*/

View File

@@ -6,7 +6,7 @@ import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@@ -17,7 +17,6 @@ import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.AdvancedConfig;
@@ -29,12 +28,12 @@ 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.excavation.Excavation;
import com.gmail.nossr50.skills.herbalism.Herbalism;
import com.gmail.nossr50.skills.SkillManagerStore;
import com.gmail.nossr50.skills.excavation.ExcavationManager;
import com.gmail.nossr50.skills.herbalism.HerbalismManager;
import com.gmail.nossr50.skills.mining.MiningManager;
import com.gmail.nossr50.skills.repair.Repair;
import com.gmail.nossr50.skills.repair.Salvage;
import com.gmail.nossr50.skills.smelting.SmeltingManager;
import com.gmail.nossr50.skills.unarmed.Unarmed;
import com.gmail.nossr50.skills.utilities.AbilityType;
import com.gmail.nossr50.skills.utilities.SkillTools;
@@ -61,13 +60,14 @@ public class BlockListener implements Listener {
*/
@EventHandler(priority = EventPriority.MONITOR)
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
List<Block> blocks = event.getBlocks();
BlockFace direction = event.getDirection();
Block futureEmptyBlock = event.getBlock().getRelative(direction); // Block that would be air after piston is finished
for (Block b : blocks) {
if (mcMMO.placeStore.isTrue(b)) {
b.getRelative(direction).setMetadata("pistonTrack", new FixedMetadataValue(plugin, true));
b.getRelative(direction).setMetadata(mcMMO.blockMetadataKey, mcMMO.metadataValue);
if (b.equals(futureEmptyBlock)) {
mcMMO.placeStore.setFalse(b);
}
@@ -75,9 +75,9 @@ public class BlockListener implements Listener {
}
for (Block b : blocks) {
if (b.getRelative(direction).hasMetadata("pistonTrack")) {
if (b.getRelative(direction).hasMetadata(mcMMO.blockMetadataKey)) {
mcMMO.placeStore.setTrue(b.getRelative(direction));
b.getRelative(direction).removeMetadata("pistonTrack", plugin);
b.getRelative(direction).removeMetadata(mcMMO.blockMetadataKey, plugin);
}
}
}
@@ -108,15 +108,15 @@ public class BlockListener implements Listener {
return;
}
Block block = event.getBlock();
BlockState blockState = event.getBlock().getState();
/* Check if the blocks placed should be monitored so they do not give out XP in the future */
if (BlockChecks.shouldBeWatched(block)) {
mcMMO.placeStore.setTrue(block);
if (BlockChecks.shouldBeWatched(blockState)) {
mcMMO.placeStore.setTrue(blockState);
}
if (Repair.anvilMessagesEnabled) {
int blockID = block.getTypeId();
int blockID = blockState.getTypeId();
if (blockID == Repair.anvilID) {
Repair.placedAnvilCheck(player, blockID);
@@ -146,13 +146,16 @@ public class BlockListener implements Listener {
McMMOPlayer mcMMOPlayer = Users.getPlayer(player);
PlayerProfile profile = mcMMOPlayer.getProfile();
Block block = event.getBlock();
BlockState blockState = event.getBlock().getState();
ItemStack heldItem = player.getItemInHand();
/* HERBALISM */
if (BlockChecks.canBeGreenTerra(block)) {
if (BlockChecks.affectedByGreenTerra(blockState)) {
HerbalismManager herbalismManager = SkillManagerStore.getInstance().getHerbalismManager(player.getName());
/* Green Terra */
if (profile.getToolPreparationMode(ToolType.HOE) && Permissions.greenTerra(player)) {
if (herbalismManager.canActivateAbility()) {
SkillTools.abilityCheck(player, SkillType.HERBALISM);
}
@@ -161,53 +164,57 @@ public class BlockListener implements Listener {
* Instead, we check it inside the drops handler.
*/
if (Permissions.skillEnabled(player, SkillType.HERBALISM)) {
Herbalism.herbalismProcCheck(block, mcMMOPlayer, plugin); //Double drops
if (profile.getAbilityMode(AbilityType.GREEN_TERRA)) {
Herbalism.herbalismProcCheck(block, mcMMOPlayer, plugin); //Triple drops
//Double drops
herbalismManager.herbalismBlockCheck(blockState);
//Triple drops
if (herbalismManager.canGreenTerraPlant()) {
herbalismManager.herbalismBlockCheck(blockState);
}
}
}
/* MINING */
else if (BlockChecks.canBeSuperBroken(block) && ItemChecks.isPickaxe(heldItem) && Permissions.skillEnabled(player, SkillType.MINING) && !mcMMO.placeStore.isTrue(block)) {
MiningManager miningManager = new MiningManager(mcMMOPlayer);
miningManager.miningBlockCheck(block);
else if (BlockChecks.affectedBySuperBreaker(blockState) && ItemChecks.isPickaxe(heldItem) && Permissions.skillEnabled(player, SkillType.MINING) && !mcMMO.placeStore.isTrue(blockState)) {
MiningManager miningManager = SkillManagerStore.getInstance().getMiningManager(player.getName());
miningManager.miningBlockCheck(blockState);
if (profile.getAbilityMode(AbilityType.SUPER_BREAKER)) {
miningManager.miningBlockCheck(block);
miningManager.miningBlockCheck(blockState);
}
}
/* WOOD CUTTING */
else if (BlockChecks.isLog(block) && Permissions.skillEnabled(player, SkillType.WOODCUTTING) && !mcMMO.placeStore.isTrue(block)) {
else if (BlockChecks.isLog(blockState) && Permissions.skillEnabled(player, SkillType.WOODCUTTING) && !mcMMO.placeStore.isTrue(blockState)) {
if (profile.getAbilityMode(AbilityType.TREE_FELLER) && Permissions.treeFeller(player) && ItemChecks.isAxe(heldItem)) {
Woodcutting.beginTreeFeller(mcMMOPlayer, block);
Woodcutting.beginTreeFeller(blockState, player);
}
else {
if (Config.getInstance().getWoodcuttingRequiresTool()) {
if (ItemChecks.isAxe(heldItem)) {
Woodcutting.beginWoodcutting(mcMMOPlayer, block);
Woodcutting.beginWoodcutting(player, blockState);
}
}
else {
Woodcutting.beginWoodcutting(mcMMOPlayer, block);
Woodcutting.beginWoodcutting(player, blockState);
}
}
}
/* EXCAVATION */
else if (BlockChecks.canBeGigaDrillBroken(block) && ItemChecks.isShovel(heldItem) && Permissions.skillEnabled(player, SkillType.EXCAVATION) && !mcMMO.placeStore.isTrue(block)) {
Excavation.excavationProcCheck(block, mcMMOPlayer);
else if (BlockChecks.affectedByGigaDrillBreaker(blockState) && ItemChecks.isShovel(heldItem) && Permissions.skillEnabled(player, SkillType.EXCAVATION) && !mcMMO.placeStore.isTrue(blockState)) {
ExcavationManager excavationManager = SkillManagerStore.getInstance().getExcavationManager(player.getName());
excavationManager.excavationBlockCheck(blockState);
if (profile.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER)) {
Excavation.gigaDrillBreaker(mcMMOPlayer, block);
excavationManager.gigaDrillBreaker(blockState);
}
}
/* Remove metadata from placed watched blocks */
if (BlockChecks.shouldBeWatched(block) && mcMMO.placeStore.isTrue(block)) {
mcMMO.placeStore.setFalse(block);
if (BlockChecks.shouldBeWatched(blockState) && mcMMO.placeStore.isTrue(blockState)) {
mcMMO.placeStore.setFalse(blockState);
}
}
@@ -228,15 +235,20 @@ public class BlockListener implements Listener {
return;
}
Block block = event.getBlock();
ItemStack heldItem = player.getItemInHand();
String playerName = player.getName();
BlockState blockState = event.getBlock().getState();
if (Permissions.hylianLuck(player) && ItemChecks.isSword(heldItem)) {
Herbalism.hylianLuck(block, player, event);
if (SkillManagerStore.getInstance().getHerbalismManager(playerName).canUseHylianLuck()) {
if (SkillManagerStore.getInstance().getHerbalismManager(playerName).processHylianLuck(blockState)) {
blockState.update(true);
event.setCancelled(true);
}
}
else if (BlockChecks.canBeFluxMined(block) && ItemChecks.isPickaxe(heldItem) && !heldItem.containsEnchantment(Enchantment.SILK_TOUCH) && Permissions.fluxMining(player) && !mcMMO.placeStore.isTrue(block)) {
SmeltingManager smeltingManager = new SmeltingManager(Users.getPlayer(player));
smeltingManager.fluxMining(event);
else if (SkillManagerStore.getInstance().getSmeltingManager(playerName).canUseFluxMining(blockState)) {
if (SkillManagerStore.getInstance().getSmeltingManager(playerName).processFluxMining(blockState)) {
blockState.update(true);
event.setCancelled(true);
}
}
}
@@ -258,14 +270,14 @@ public class BlockListener implements Listener {
}
PlayerProfile profile = Users.getPlayer(player).getProfile();
Block block = event.getBlock();
BlockState blockState = event.getBlock().getState();
/*
* ABILITY PREPARATION CHECKS
*
* We check permissions here before processing activation.
*/
if (BlockChecks.canActivateAbilities(block)) {
if (BlockChecks.canActivateAbilities(blockState)) {
ItemStack heldItem = player.getItemInHand();
if (HiddenConfig.getInstance().useEnchantmentBuffs()) {
@@ -274,24 +286,24 @@ public class BlockListener implements Listener {
}
}
else {
if ((profile.getAbilityMode(AbilityType.SUPER_BREAKER) && !BlockChecks.canBeSuperBroken(block)) || (profile.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER) && !BlockChecks.canBeGigaDrillBroken(block))) {
if ((profile.getAbilityMode(AbilityType.SUPER_BREAKER) && !BlockChecks.affectedBySuperBreaker(blockState)) || (profile.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER) && !BlockChecks.affectedByGigaDrillBreaker(blockState))) {
SkillTools.handleAbilitySpeedDecrease(player);
}
}
if (profile.getToolPreparationMode(ToolType.HOE) && ItemChecks.isHoe(heldItem) && (BlockChecks.canBeGreenTerra(block) || BlockChecks.canMakeMossy(block)) && Permissions.greenTerra(player)) {
if (profile.getToolPreparationMode(ToolType.HOE) && ItemChecks.isHoe(heldItem) && (BlockChecks.affectedByGreenTerra(blockState) || BlockChecks.canMakeMossy(blockState)) && Permissions.greenTerra(player)) {
SkillTools.abilityCheck(player, SkillType.HERBALISM);
}
else if (profile.getToolPreparationMode(ToolType.AXE) && ItemChecks.isAxe(heldItem) && BlockChecks.isLog(block) && Permissions.treeFeller(player)) {
else if (profile.getToolPreparationMode(ToolType.AXE) && ItemChecks.isAxe(heldItem) && BlockChecks.isLog(blockState) && Permissions.treeFeller(player)) {
SkillTools.abilityCheck(player, SkillType.WOODCUTTING);
}
else if (profile.getToolPreparationMode(ToolType.PICKAXE) && ItemChecks.isPickaxe(heldItem) && BlockChecks.canBeSuperBroken(block) && Permissions.superBreaker(player)) {
else if (profile.getToolPreparationMode(ToolType.PICKAXE) && ItemChecks.isPickaxe(heldItem) && BlockChecks.affectedBySuperBreaker(blockState) && Permissions.superBreaker(player)) {
SkillTools.abilityCheck(player, SkillType.MINING);
}
else if (profile.getToolPreparationMode(ToolType.SHOVEL) && ItemChecks.isShovel(heldItem) && BlockChecks.canBeGigaDrillBroken(block) && Permissions.gigaDrillBreaker(player)) {
else if (profile.getToolPreparationMode(ToolType.SHOVEL) && ItemChecks.isShovel(heldItem) && BlockChecks.affectedByGigaDrillBreaker(blockState) && Permissions.gigaDrillBreaker(player)) {
SkillTools.abilityCheck(player, SkillType.EXCAVATION);
}
else if (profile.getToolPreparationMode(ToolType.FISTS) && heldItem.getType() == Material.AIR && (BlockChecks.canBeGigaDrillBroken(block) || block.getType() == Material.SNOW || (block.getType() == Material.SMOOTH_BRICK && block.getData() == 0x0)) && Permissions.berserk(player)) {
else if (profile.getToolPreparationMode(ToolType.FISTS) && heldItem.getType() == Material.AIR && (BlockChecks.affectedByGigaDrillBreaker(blockState) || blockState.getType() == Material.SNOW || BlockChecks.affectedByBlockCracker(blockState) && Permissions.berserk(player))) {
SkillTools.abilityCheck(player, SkillType.UNARMED);
}
}
@@ -301,8 +313,8 @@ public class BlockListener implements Listener {
*
* We don't need to check permissions here because they've already been checked for the ability to even activate.
*/
if (profile.getAbilityMode(AbilityType.TREE_FELLER) && BlockChecks.isLog(block)) {
player.playSound(block.getLocation(), Sound.FIZZ, Misc.FIZZ_VOLUME, Misc.FIZZ_PITCH);
if (profile.getAbilityMode(AbilityType.TREE_FELLER) && BlockChecks.isLog(blockState)) {
player.playSound(blockState.getLocation(), Sound.FIZZ, Misc.FIZZ_VOLUME, Misc.FIZZ_PITCH);
}
}
@@ -323,45 +335,50 @@ public class BlockListener implements Listener {
return;
}
String playerName = player.getName();
McMMOPlayer mcMMOPlayer = Users.getPlayer(player);
PlayerProfile profile = mcMMOPlayer.getProfile();
ItemStack heldItem = player.getItemInHand();
Block block = event.getBlock();
BlockState blockState = block.getState();
/*
* ABILITY TRIGGER CHECKS
*
* We don't need to check permissions here because they've already been checked for the ability to even activate.
*/
if (profile.getAbilityMode(AbilityType.GREEN_TERRA) && BlockChecks.canMakeMossy(block)) {
Herbalism.greenTerra(player, block);
if (SkillManagerStore.getInstance().getHerbalismManager(playerName).canGreenTerraBlock(blockState)) {
if (SkillManagerStore.getInstance().getHerbalismManager(playerName).processGreenTerra(blockState)) {
blockState.update(true);
}
}
else if (profile.getAbilityMode(AbilityType.BERSERK)) {
if (SkillTools.triggerCheck(player, block, AbilityType.BERSERK)) {
if (heldItem.getType() == Material.AIR) {
FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player);
plugin.getServer().getPluginManager().callEvent(armswing);
plugin.getServer().getPluginManager().callEvent(new FakePlayerAnimationEvent(player));
event.setInstaBreak(true);
player.playSound(block.getLocation(), Sound.ITEM_PICKUP, Misc.POP_VOLUME, Misc.POP_PITCH);
}
}
// Another perm check for the cracked blocks activation
else if (BlockChecks.canBeCracked(block) && Permissions.blockCracker(player)) {
Unarmed.blockCracker(player, block);
else if (BlockChecks.affectedByBlockCracker(blockState) && Permissions.blockCracker(player)) {
if (Unarmed.blockCracker(player, blockState)) {
blockState.update();
}
}
}
else if ((profile.getSkillLevel(SkillType.WOODCUTTING) >= AdvancedConfig.getInstance().getLeafBlowUnlockLevel()) && BlockChecks.isLeaves(block)) {
else if ((profile.getSkillLevel(SkillType.WOODCUTTING) >= AdvancedConfig.getInstance().getLeafBlowUnlockLevel()) && BlockChecks.isLeaves(blockState)) {
if (SkillTools.triggerCheck(player, block, AbilityType.LEAF_BLOWER)) {
if (Config.getInstance().getWoodcuttingRequiresTool()) {
if (ItemChecks.isAxe(heldItem)) {
event.setInstaBreak(true);
Woodcutting.beginLeafBlower(player, block);
Woodcutting.beginLeafBlower(player, blockState);
}
}
else if (!(heldItem.getType() == Material.SHEARS)) {
event.setInstaBreak(true);
Woodcutting.beginLeafBlower(player, block);
Woodcutting.beginLeafBlower(player, blockState);
}
}
}

View File

@@ -1,6 +1,5 @@
package com.gmail.nossr50.listeners;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.AnimalTamer;
import org.bukkit.entity.Entity;
@@ -33,14 +32,13 @@ import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent;
import com.gmail.nossr50.events.fake.FakeEntityDamageEvent;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.skills.acrobatics.Acrobatics;
import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager;
import com.gmail.nossr50.skills.SkillManagerStore;
import com.gmail.nossr50.skills.archery.Archery;
import com.gmail.nossr50.skills.fishing.Fishing;
import com.gmail.nossr50.skills.herbalism.Herbalism;
import com.gmail.nossr50.skills.mining.MiningManager;
import com.gmail.nossr50.skills.runnables.BleedTimer;
import com.gmail.nossr50.skills.taming.TamingManager;
import com.gmail.nossr50.skills.taming.Taming;
import com.gmail.nossr50.skills.utilities.CombatTools;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
@@ -67,7 +65,7 @@ public class EntityListener implements Listener {
if (mcMMO.placeStore.isTrue(block) && !entity.hasMetadata(mcMMO.entityMetadataKey)) {
mcMMO.placeStore.setFalse(block);
entity.setMetadata(mcMMO.entityMetadataKey, mcMMO.entityMetadata);
entity.setMetadata(mcMMO.entityMetadataKey, mcMMO.metadataValue);
}
else if (entity.hasMetadata(mcMMO.entityMetadataKey)) {
mcMMO.placeStore.setTrue(block);
@@ -131,7 +129,7 @@ public class EntityListener implements Listener {
if (defender instanceof LivingEntity) {
LivingEntity livingDefender = (LivingEntity) defender;
if (!CombatTools.isInvincible(livingDefender, event)) {
if (!CombatTools.isInvincible(livingDefender, event.getDamage())) {
CombatTools.combatChecks(event, attacker, livingDefender);
}
}
@@ -157,9 +155,14 @@ public class EntityListener implements Listener {
DamageCause cause = event.getCause();
LivingEntity livingEntity = (LivingEntity) entity;
if (CombatTools.isInvincible(livingEntity, event.getDamage())) {
return;
}
if (livingEntity instanceof Player) {
Player player = (Player) entity;
// TODO: Is it even possible for the player to be off-line here?
if (!player.isOnline() || Misc.isNPCEntity(player)) {
return;
}
@@ -173,28 +176,102 @@ public class EntityListener implements Listener {
return;
}
if (!CombatTools.isInvincible(player, event)) {
if (cause == DamageCause.FALL && player.getItemInHand().getType() != Material.ENDER_PEARL && !(Acrobatics.afkLevelingDisabled && player.isInsideVehicle()) && Permissions.roll(player)) {
AcrobaticsManager acrobaticsManager = new AcrobaticsManager(mcMMOPlayer);
acrobaticsManager.rollCheck(event);
}
else if (cause == DamageCause.BLOCK_EXPLOSION && Permissions.demolitionsExpertise(player)) {
MiningManager miningManager = new MiningManager(mcMMOPlayer);
miningManager.demolitionsExpertise(event);
}
switch (cause) {
case FALL:
if (SkillManagerStore.getInstance().getAcrobaticsManager(player.getName()).canRoll()) {
event.setDamage(SkillManagerStore.getInstance().getAcrobaticsManager(player.getName()).rollCheck(event.getDamage()));
if (event.getDamage() >= 1) {
profile.actualizeRecentlyHurt();
if (event.getDamage() == 0) {
event.setCancelled(true);
return;
}
}
break;
case BLOCK_EXPLOSION:
MiningManager miningManager = SkillManagerStore.getInstance().getMiningManager(player.getName());
if (miningManager.canUseDemolitionsExpertise()) {
event.setDamage(miningManager.processDemolitionsExpertise(event.getDamage()));
if (event.getDamage() == 0) {
event.setCancelled(true);
return;
}
}
break;
default:
break;
}
if (event.getDamage() >= 1) {
profile.actualizeRecentlyHurt();
}
}
else if (livingEntity instanceof Tameable) {
Tameable pet = (Tameable) livingEntity;
AnimalTamer owner = pet.getOwner();
if ((!CombatTools.isInvincible(livingEntity, event)) && pet.isTamed() && owner instanceof Player && pet instanceof Wolf) {
TamingManager tamingManager = new TamingManager(Users.getPlayer((Player) owner));
tamingManager.preventDamage(event);
if (Taming.canPreventDamage(pet, owner)) {
Player player = (Player) owner;
Wolf wolf = (Wolf) pet;
switch (cause) {
case CONTACT:
case FIRE:
case LAVA:
if (Taming.canUseEnvironmentallyAware(player)) {
Taming.processEnvironmentallyAware(player, wolf, event.getDamage());
}
return;
case FALL:
if (Taming.canUseEnvironmentallyAware(player)) {
event.setCancelled(true);
}
return;
case ENTITY_ATTACK:
case PROJECTILE:
if (Taming.canUseThickFur(player)) {
event.setDamage(Taming.processThickFur(wolf, event.getDamage()));
if (event.getDamage() == 0) {
event.setCancelled(true);
}
}
return;
case FIRE_TICK:
if (Taming.canUseThickFur(player)) {
Taming.processThickFurFire(wolf);
}
return;
case MAGIC:
case POISON:
case WITHER:
if (Taming.canUseHolyHound(player)) {
Taming.processHolyHound(wolf, event.getDamage());
}
return;
case BLOCK_EXPLOSION:
case ENTITY_EXPLOSION:
case LIGHTNING:
if (Taming.canUseShockProof(player)) {
event.setDamage(Taming.processShockProof(wolf, event.getDamage()));
if (event.getDamage() == 0) {
event.setCancelled(true);
}
}
return;
default:
return;
}
}
}
}
@@ -224,17 +301,14 @@ public class EntityListener implements Listener {
*/
@EventHandler (priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onCreatureSpawn(CreatureSpawnEvent event) {
if (Misc.isSpawnerXPEnabled) {
return;
}
else if (event.getEntity() == null) {
if (Misc.isSpawnerXPEnabled || event.getEntity() == null) {
return;
}
SpawnReason reason = event.getSpawnReason();
if (reason == SpawnReason.SPAWNER || reason == SpawnReason.SPAWNER_EGG) {
event.getEntity().setMetadata(mcMMO.entityMetadataKey, mcMMO.entityMetadata);
event.getEntity().setMetadata(mcMMO.entityMetadataKey, mcMMO.metadataValue);
}
}
@@ -251,11 +325,10 @@ public class EntityListener implements Listener {
int id = entity.getEntityId();
if (plugin.tntIsTracked(id)) {
Player player = plugin.getTNTPlayer(id);
MiningManager miningManager = SkillManagerStore.getInstance().getMiningManager(plugin.getTNTPlayer(id).getName());
if (Permissions.biggerBombs(player)) {
MiningManager miningManager = new MiningManager(Users.getPlayer(player));
miningManager.biggerBombs(event);
if (miningManager.canUseBiggerBombs()) {
event.setRadius(miningManager.biggerBombs(event.getRadius()));
}
}
}
@@ -274,10 +347,12 @@ public class EntityListener implements Listener {
int id = entity.getEntityId();
if (plugin.tntIsTracked(id)) {
Player player = plugin.getTNTPlayer(id);
MiningManager miningManager = SkillManagerStore.getInstance().getMiningManager(plugin.getTNTPlayer(id).getName());
MiningManager miningManager = new MiningManager(Users.getPlayer(player));
miningManager.blastMiningDropProcessing(event);
if (miningManager.canUseBlastMining()) {
miningManager.blastMiningDropProcessing(event.getYield(), event.blockList());
event.setYield(0);
}
plugin.removeFromTNTTracker(id);
}
@@ -318,23 +393,31 @@ public class EntityListener implements Listener {
case GOLDEN_CARROT: /* RESTORES 3 HUNGER - RESTORES 5 1/2 HUNGER @ 1000 */
case MUSHROOM_SOUP: /* RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */
case PUMPKIN_PIE: /* RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */
Herbalism.farmersDiet(player, Herbalism.farmersDietRankLevel1, event);
break;
if (Permissions.farmersDiet(player)) {
event.setFoodLevel(SkillManagerStore.getInstance().getHerbalismManager(player.getName()).farmersDiet(Herbalism.farmersDietRankLevel1, newFoodLevel));
}
return;
case COOKIE: /* RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */
case MELON: /* RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
case POISONOUS_POTATO: /* RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
case POTATO_ITEM: /* RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */
Herbalism.farmersDiet(player, Herbalism.farmersDietRankLevel2, event);
break;
if (Permissions.farmersDiet(player)) {
event.setFoodLevel(SkillManagerStore.getInstance().getHerbalismManager(player.getName()).farmersDiet(Herbalism.farmersDietRankLevel2, newFoodLevel));
}
return;
case COOKED_FISH: /* RESTORES 2 1/2 HUNGER - RESTORES 5 HUNGER @ 1000 */
Fishing.beginFishermansDiet(player, Fishing.fishermansDietRankLevel1, event);
break;
if (Permissions.fishermansDiet(player)) {
event.setFoodLevel(SkillManagerStore.getInstance().getFishingManager(player.getName()).handleFishermanDiet(Fishing.fishermansDietRankLevel1, newFoodLevel));
}
return;
case RAW_FISH: /* RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
Fishing.beginFishermansDiet(player, Fishing.fishermansDietRankLevel2, event);
break;
if (Permissions.fishermansDiet(player)) {
event.setFoodLevel(SkillManagerStore.getInstance().getFishingManager(player.getName()).handleFishermanDiet(Fishing.fishermansDietRankLevel2, newFoodLevel));
}
return;
default:
return;
@@ -356,8 +439,11 @@ public class EntityListener implements Listener {
return;
}
TamingManager tamingManager = new TamingManager(Users.getPlayer(player));
tamingManager.awardTamingXP(event);
LivingEntity entity = event.getEntity();
if (entity != null && !entity.hasMetadata(mcMMO.entityMetadataKey)) {
SkillManagerStore.getInstance().getTamingManager(player.getName()).awardTamingXP(entity);
}
}
@EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = true)

View File

@@ -1,8 +1,8 @@
package com.gmail.nossr50.listeners;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Furnace;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@@ -10,16 +10,21 @@ import org.bukkit.event.Listener;
import org.bukkit.event.inventory.FurnaceBurnEvent;
import org.bukkit.event.inventory.FurnaceExtractEvent;
import org.bukkit.event.inventory.FurnaceSmeltEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.FurnaceInventory;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.skills.smelting.SmeltingManager;
import com.gmail.nossr50.skills.SkillManagerStore;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.ItemChecks;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users;
public class InventoryListener implements Listener{
@@ -31,37 +36,47 @@ public class InventoryListener implements Listener{
@EventHandler(priority = EventPriority.MONITOR)
public void onInventoryOpen(InventoryOpenEvent event) {
InventoryType inventoryType = event.getInventory().getType();
HumanEntity player = event.getPlayer();
if (inventoryType == InventoryType.FURNACE) {
FurnaceInventory inventory = (FurnaceInventory) event.getInventory();
Furnace furnace = inventory.getHolder();
if (Misc.isNPCEntity(player)) {
return;
}
Inventory inventory = event.getInventory();
if (inventory instanceof FurnaceInventory) {
Furnace furnace = (Furnace) inventory.getHolder();
if (furnace == null) {
return;
}
Block furnaceBlock = furnace.getBlock();
BlockState furnaceBlock = furnace.getBlock().getState();
if (furnace.getBurnTime() == 0 && !plugin.furnaceIsTracked(furnaceBlock)) {
plugin.addToOpenFurnaceTracker(furnaceBlock, event.getPlayer().getName());
plugin.addToOpenFurnaceTracker(furnaceBlock, player.getName());
}
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onInventoryClose(InventoryCloseEvent event) {
InventoryType inventoryType = event.getInventory().getType();
HumanEntity player = event.getPlayer();
if (inventoryType == InventoryType.FURNACE) {
FurnaceInventory inventory = (FurnaceInventory) event.getInventory();
Furnace furnace = inventory.getHolder();
if (Misc.isNPCEntity(player)) {
return;
}
Inventory inventory = event.getInventory();
if (inventory instanceof FurnaceInventory) {
Furnace furnace = (Furnace) inventory.getHolder();
if (furnace == null) {
return;
}
Block furnaceBlock = furnace.getBlock();
BlockState furnaceBlock = furnace.getBlock().getState();
if (furnace.getBurnTime() == 0 && plugin.furnaceIsTracked(furnaceBlock)) {
plugin.removeFromFurnaceTracker(furnaceBlock);
@@ -71,19 +86,20 @@ public class InventoryListener implements Listener{
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onFurnaceBurnEvent(FurnaceBurnEvent event) {
Block furnaceBlock = event.getBlock();
BlockState blockState = furnaceBlock.getState();
BlockState furnaceBlock = event.getBlock().getState();
if (furnaceBlock instanceof Furnace) {
ItemStack smelting = ((Furnace) furnaceBlock).getInventory().getSmelting();
if (blockState instanceof Furnace) {
FurnaceInventory inventory = ((Furnace) blockState).getInventory();
ItemStack smelting = inventory.getSmelting();
if (plugin.furnaceIsTracked(furnaceBlock) && smelting != null && ItemChecks.isSmeltable(smelting)) {
Player player = plugin.getFurnacePlayer(furnaceBlock);
if (player != null) {
SmeltingManager smeltingManager = new SmeltingManager(Users.getPlayer(player));
smeltingManager.fuelEfficiency(event);
if (!Misc.isNPCEntity(player)) {
return;
}
if (Permissions.fuelEfficiency(player)) {
event.setBurnTime(SkillManagerStore.getInstance().getSmeltingManager(player.getName()).fuelEfficiency(event.getBurnTime()));
}
}
}
@@ -91,19 +107,20 @@ public class InventoryListener implements Listener{
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onFurnaceSmeltEvent(FurnaceSmeltEvent event) {
Block furnaceBlock = event.getBlock();
BlockState blockState = furnaceBlock.getState();
BlockState furnaceBlock = event.getBlock().getState();
if (blockState instanceof Furnace) {
FurnaceInventory inventory = ((Furnace) blockState).getInventory();
ItemStack smelting = inventory.getSmelting();
if (furnaceBlock instanceof Furnace) {
ItemStack smelting = ((Furnace) furnaceBlock).getInventory().getSmelting();
if (plugin.furnaceIsTracked(furnaceBlock) && smelting != null && ItemChecks.isSmeltable(smelting)) {
Player player = plugin.getFurnacePlayer(furnaceBlock);
if (player != null) {
SmeltingManager smeltingManager = new SmeltingManager(Users.getPlayer(player));
smeltingManager.smeltProcessing(event);
if (!Misc.isNPCEntity(player)) {
return;
}
if (Permissions.skillEnabled(player, SkillType.SMELTING)) {
event.setResult(SkillManagerStore.getInstance().getSmeltingManager(player.getName()).smeltProcessing(event.getSource().getType(), event.getResult()));
}
}
}
@@ -111,21 +128,23 @@ public class InventoryListener implements Listener{
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onFurnaceExtractEvent(FurnaceExtractEvent event) {
Block furnaceBlock = event.getBlock();
BlockState blockState = furnaceBlock.getState();
BlockState furnaceBlock = event.getBlock().getState();
if (blockState instanceof Furnace) {
FurnaceInventory inventory = ((Furnace) blockState).getInventory();
ItemStack result = inventory.getResult();
if (furnaceBlock instanceof Furnace) {
ItemStack result = ((Furnace) furnaceBlock).getInventory().getResult();
if (plugin.furnaceIsTracked(furnaceBlock) && result != null && ItemChecks.isSmelted(result)) {
McMMOPlayer mcMMOPlayer = Users.getPlayer(event.getPlayer());
if (mcMMOPlayer.getPlayer().equals(plugin.getFurnacePlayer(furnaceBlock))) {
SmeltingManager smeltingManager = new SmeltingManager(mcMMOPlayer);
smeltingManager.vanillaXPBoost(event);
event.setExpToDrop(SkillManagerStore.getInstance().getSmeltingManager(event.getPlayer().getName()).vanillaXPBoost(event.getExpToDrop()));
}
}
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryClickEvent(InventoryClickEvent event) {
SkillTools.removeAbilityBuff(event.getCurrentItem());
}
}

View File

@@ -2,6 +2,7 @@ package com.gmail.nossr50.listeners;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity;
@@ -26,21 +27,18 @@ import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.chat.ChatManager;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.party.ShareHandler;
import com.gmail.nossr50.skills.fishing.Fishing;
import com.gmail.nossr50.skills.herbalism.Herbalism;
import com.gmail.nossr50.skills.mining.BlastMining;
import com.gmail.nossr50.skills.mining.MiningManager;
import com.gmail.nossr50.skills.SkillManagerStore;
import com.gmail.nossr50.skills.fishing.FishingManager;
import com.gmail.nossr50.skills.herbalism.HerbalismManager;
import com.gmail.nossr50.skills.repair.Repair;
import com.gmail.nossr50.skills.repair.Salvage;
import com.gmail.nossr50.skills.runnables.BleedTimer;
import com.gmail.nossr50.skills.taming.TamingManager;
import com.gmail.nossr50.skills.utilities.AbilityType;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
@@ -145,7 +143,10 @@ public class PlayerListener implements Listener {
if (playerProfile.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER) || playerProfile.getAbilityMode(AbilityType.SUPER_BREAKER)) {
event.setCancelled(true);
return;
}
SkillTools.removeAbilityBuff(event.getItemDrop().getItemStack());
}
/**
@@ -161,19 +162,22 @@ public class PlayerListener implements Listener {
return;
}
McMMOPlayer mcMMOPlayer = Users.getPlayer(player);
int skillLevel = mcMMOPlayer.getProfile().getSkillLevel(SkillType.FISHING);
FishingManager fishingManager = SkillManagerStore.getInstance().getFishingManager(player.getName());
switch (event.getState()) {
case CAUGHT_FISH:
Fishing.beginFishing(mcMMOPlayer, skillLevel, event);
fishingManager.handleFishing((Item) event.getCaught());
if (Permissions.vanillaXpBoost(player, SkillType.FISHING)) {
event.setExpToDrop(fishingManager.handleVanillaXpBoost(event.getExpToDrop()));
}
break;
case CAUGHT_ENTITY:
Entity entity = event.getCaught();
if (entity instanceof LivingEntity && skillLevel >= AdvancedConfig.getInstance().getShakeUnlockLevel() && Permissions.shake(player)) {
Fishing.beginShakeMob(player, (LivingEntity) entity, skillLevel);
if (fishingManager.canShake(entity)) {
fishingManager.shakeCheck((LivingEntity) entity);
}
break;
@@ -291,18 +295,21 @@ public class PlayerListener implements Listener {
player.updateInventory();
}
/* BLAST MINING CHECK */
else if (player.isSneaking() && Permissions.remoteDetonation(player) && heldItem.getTypeId() == BlastMining.detonatorID) {
MiningManager miningManager = new MiningManager(Users.getPlayer(player));
miningManager.detonate(event);
else if (SkillManagerStore.getInstance().getMiningManager(player.getName()).canDetonate()) {
if (blockID == Material.TNT.getId()) {
event.setCancelled(true); // Don't detonate the TNT if they're too close
}
else {
SkillManagerStore.getInstance().getMiningManager(player.getName()).remoteDetonation();
}
}
break;
case RIGHT_CLICK_AIR:
/* BLAST MINING CHECK */
if (player.isSneaking() && Permissions.remoteDetonation(player) && heldItem.getTypeId() == BlastMining.detonatorID) {
MiningManager miningManager = new MiningManager(Users.getPlayer(player));
miningManager.detonate(event);
if (SkillManagerStore.getInstance().getMiningManager(player.getName()).canDetonate()) {
SkillManagerStore.getInstance().getMiningManager(player.getName()).remoteDetonation();
}
break;
@@ -325,16 +332,17 @@ public class PlayerListener implements Listener {
return;
}
Block block = event.getClickedBlock();
ItemStack heldItem = player.getItemInHand();
switch (event.getAction()) {
case RIGHT_CLICK_BLOCK:
Block block = event.getClickedBlock();
BlockState blockState = block.getState();
/* ACTIVATION & ITEM CHECKS */
if (BlockChecks.canActivateAbilities(block)) {
if (SkillTools.abilitiesEnabled) {
if (BlockChecks.canActivateHerbalism(block)) {
if (BlockChecks.canActivateAbilities(blockState)) {
if (Config.getInstance().getAbilitiesEnabled()) {
if (BlockChecks.canActivateHerbalism(blockState)) {
SkillTools.activationCheck(player, SkillType.HERBALISM);
}
@@ -350,16 +358,28 @@ public class PlayerListener implements Listener {
}
/* GREEN THUMB CHECK */
if (heldItem.getType() == Material.SEEDS && BlockChecks.canMakeMossy(block)) {
Herbalism.greenThumbBlocks(heldItem, player, block);
HerbalismManager herbalismManager = SkillManagerStore.getInstance().getHerbalismManager(player.getName());
if (herbalismManager.canGreenThumbBlock(blockState)) {
player.setItemInHand(new ItemStack(Material.SEEDS, heldItem.getAmount() - 1));
if (herbalismManager.processGreenThumbBlocks(blockState) && SkillTools.blockBreakSimulate(block, player, false)) {
blockState.update(true);
}
}
/* SHROOM THUMB CHECK */
else if (herbalismManager.canUseShroomThumb(blockState)) {
if (herbalismManager.processShroomThumb(blockState) && SkillTools.blockBreakSimulate(block, player, false)) {
blockState.update(true);
}
}
break;
case RIGHT_CLICK_AIR:
/* ACTIVATION CHECKS */
if (SkillTools.abilitiesEnabled) {
if (Config.getInstance().getAbilitiesEnabled()) {
SkillTools.activationCheck(player, SkillType.AXES);
SkillTools.activationCheck(player, SkillType.EXCAVATION);
SkillTools.activationCheck(player, SkillType.HERBALISM);
@@ -382,12 +402,10 @@ public class PlayerListener implements Listener {
Material type = heldItem.getType();
if (type == Material.RAW_FISH) {
TamingManager tamingManager = new TamingManager(Users.getPlayer(player));
tamingManager.summonOcelot();
SkillManagerStore.getInstance().getTamingManager(player.getName()).summonOcelot();
}
else if (type == Material.BONE) {
TamingManager tamingManager = new TamingManager(Users.getPlayer(player));
tamingManager.summonWolf();
SkillManagerStore.getInstance().getTamingManager(player.getName()).summonWolf();
}
}
@@ -421,11 +439,11 @@ public class PlayerListener implements Listener {
return;
}
ChatManager.handlePartyChat(plugin, party, player.getName(), player.getDisplayName(), event.getMessage());
ChatManager.handlePartyChat(plugin, party, player.getName(), player.getDisplayName(), event.getMessage(), true);
event.setCancelled(true);
}
else if (mcMMOPlayer.getAdminChatMode()) {
ChatManager.handleAdminChat(plugin, player.getName(), player.getDisplayName(), event.getMessage());
ChatManager.handleAdminChat(plugin, player.getName(), player.getDisplayName(), event.getMessage(), true);
event.setCancelled(true);
}
}

View File

@@ -4,7 +4,7 @@ import java.io.File;
import java.util.ArrayList;
import org.bukkit.Chunk;
import org.bukkit.TreeType;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.BlockState;
import org.bukkit.event.EventHandler;
@@ -28,15 +28,11 @@ public class WorldListener implements Listener {
*/
@EventHandler (priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onStructureGrow(StructureGrowEvent event) {
TreeType species = event.getSpecies();
Location location = event.getLocation();
if (species == TreeType.BROWN_MUSHROOM || species == TreeType.RED_MUSHROOM) {
return;
}
if (mcMMO.placeStore.isTrue(event.getLocation().getBlock())) {
for (BlockState block : event.getBlocks()) {
mcMMO.placeStore.setFalse(block.getBlock());
if (mcMMO.placeStore.isTrue(location.getBlockX(), location.getBlockY(), location.getBlockZ(), location.getWorld())) {
for (BlockState blockState : event.getBlocks()) {
mcMMO.placeStore.setFalse(blockState);
}
}
}

View File

@@ -8,9 +8,11 @@ import java.util.List;
import net.shatteredlands.shatt.backup.ZipLibrary;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
@@ -42,6 +44,7 @@ import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.party.runnables.PartiesLoader;
import com.gmail.nossr50.party.runnables.PartyAutoKick;
import com.gmail.nossr50.runnables.SaveTimer;
import com.gmail.nossr50.skills.child.ChildConfig;
import com.gmail.nossr50.skills.repair.RepairManager;
import com.gmail.nossr50.skills.repair.RepairManagerFactory;
import com.gmail.nossr50.skills.repair.Repairable;
@@ -63,7 +66,7 @@ public class mcMMO extends JavaPlugin {
private final WorldListener worldListener = new WorldListener();
private HashMap<Integer, String> tntTracker = new HashMap<Integer, String>();
private HashMap<Block, String> furnaceTracker = new HashMap<Block, String>();
private HashMap<BlockState, String> furnaceTracker = new HashMap<BlockState, String>();
public static mcMMO p;
@@ -88,55 +91,71 @@ public class mcMMO extends JavaPlugin {
// XP Event Check
private boolean xpEventEnabled = false;
// Entity Metadata Values
public static FixedMetadataValue entityMetadata;
// Metadata Values
public static FixedMetadataValue metadataValue;
public final static String entityMetadataKey = "mcMMO: Spawned Entity";
public final static String blockMetadataKey = "mcMMO: Piston Tracking";
/**
* Things to be run when the plugin is enabled.
*/
@Override
public void onEnable() {
p = this;
getLogger().setFilter(new LogFilter(this));
entityMetadata = new FixedMetadataValue(mcMMO.p, true);
setupFilePaths();
setupSpout();
loadConfigFiles();
try {
p = this;
getLogger().setFilter(new LogFilter(this));
metadataValue = new FixedMetadataValue(this, true);
if (!Config.getInstance().getUseMySQL()) {
Users.loadUsers();
setupFilePaths();
setupSpout();
loadConfigFiles();
if (!Config.getInstance().getUseMySQL()) {
Users.loadUsers();
}
registerEvents();
// Setup the leader boards
if (Config.getInstance().getUseMySQL()) {
// TODO: Why do we have to check for a connection that hasn't be made yet?
Database.checkConnected();
Database.createStructure();
}
else {
Leaderboard.updateLeaderboards();
}
for (Player player : getServer().getOnlinePlayers()) {
Users.addUser(player); // In case of reload add all users back into PlayerProfile
}
getLogger().info("Version " + getDescription().getVersion() + " is enabled!");
scheduleTasks();
registerCommands();
MetricsManager.setup();
placeStore = ChunkManagerFactory.getChunkManager(); // Get our ChunkletManager
checkForUpdates();
if (Config.getInstance().getPTPCommandWorldPermissions()) {
Permissions.generateWorldTeleportPermissions();
}
}
catch (Throwable t) {
getLogger().severe("There was an error while enabling mcMMO!");
registerEvents();
if (!(t instanceof ExceptionInInitializerError)) {
t.printStackTrace();
}
else {
getLogger().info("Please do not replace the mcMMO jar while the server is running.");
}
// Setup the leader boards
if (Config.getInstance().getUseMySQL()) {
// TODO: Why do we have to check for a connection that hasn't be made yet?
Database.checkConnected();
Database.createStructure();
}
else {
Leaderboard.updateLeaderboards();
}
for (Player player : getServer().getOnlinePlayers()) {
Users.addUser(player); // In case of reload add all users back into PlayerProfile
}
getLogger().info("Version " + getDescription().getVersion() + " is enabled!");
scheduleTasks();
registerCommands();
MetricsManager.setup();
placeStore = ChunkManagerFactory.getChunkManager(); // Get our ChunkletManager
checkForUpdates();
if (Config.getInstance().getPTPCommandWorldPermissions()) {
Permissions.generateWorldTeleportPermissions();
Bukkit.getPluginManager().disablePlugin(this);
}
}
@@ -209,11 +228,16 @@ public class mcMMO extends JavaPlugin {
*/
@Override
public void onDisable() {
Users.saveAll(); // Make sure to save player information if the server shuts down
PartyManager.saveParties();
try {
Users.saveAll(); // Make sure to save player information if the server shuts down
PartyManager.saveParties();
placeStore.saveAll(); // Save our metadata
placeStore.cleanUp(); // Cleanup empty metadata stores
}
catch (NullPointerException e) {}
getServer().getScheduler().cancelTasks(this); // This removes our tasks
placeStore.saveAll(); // Save our metadata
placeStore.cleanUp(); // Cleanup empty metadata stores
HandlerList.unregisterAll(this); // Cancel event registrations
if (Config.getInstance().getBackupsEnabled()) {
// Remove other tasks BEFORE starting the Backup, or we just cancel it straight away.
@@ -223,6 +247,15 @@ public class mcMMO extends JavaPlugin {
catch (IOException e) {
getLogger().severe(e.toString());
}
catch (Throwable e) {
if (e instanceof NoClassDefFoundError) {
getLogger().severe("Backup class not found!");
getLogger().info("Please do not replace the mcMMO jar while the server is running.");
}
else {
getLogger().severe(e.toString());
}
}
}
getLogger().info("Was disabled."); //How informative!
@@ -234,8 +267,7 @@ public class mcMMO extends JavaPlugin {
TreasuresConfig.getInstance();
HiddenConfig.getInstance();
AdvancedConfig.getInstance();
new ChildConfig();
List<Repairable> repairables = new ArrayList<Repairable>();
@@ -410,19 +442,19 @@ public class mcMMO extends JavaPlugin {
tntTracker.remove(tntID);
}
public void addToOpenFurnaceTracker(Block furnace, String playerName) {
public void addToOpenFurnaceTracker(BlockState furnace, String playerName) {
furnaceTracker.put(furnace, playerName);
}
public boolean furnaceIsTracked(Block furnace) {
public boolean furnaceIsTracked(BlockState furnace) {
return furnaceTracker.containsKey(furnace);
}
public void removeFromFurnaceTracker(Block furnace) {
public void removeFromFurnaceTracker(BlockState furnace) {
furnaceTracker.remove(furnace);
}
public Player getFurnacePlayer(Block furnace) {
public Player getFurnacePlayer(BlockState furnace) {
return getServer().getPlayer(furnaceTracker.get(furnace));
}

View File

@@ -1,9 +1,8 @@
package com.gmail.nossr50.mods;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.mods.config.CustomArmorConfig;
@@ -47,23 +46,19 @@ public final class ModChecks {
/**
* Get the custom block associated with an block.
*
* @param block The block to check
* @param blockState The block to check
* @return the block if it exists, null otherwise
*/
public static CustomBlock getCustomBlock(Block block) {
if (!Config.getInstance().getBlockModsEnabled()) {
return null;
}
public static CustomBlock getCustomBlock(BlockState blockState) {
if (customBlocksEnabled) {
ItemStack item = blockState.getData().toItemStack();
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
if (!CustomBlocksConfig.getInstance().customItems.contains(item)) {
return null;
}
for (CustomBlock b : CustomBlocksConfig.getInstance().customBlocks) {
if ((b.getItemID() == block.getTypeId()) && (b.getDataValue() == block.getData())) {
return b;
if (CustomBlocksConfig.getInstance().customItems.contains(item)) {
for (CustomBlock block : CustomBlocksConfig.getInstance().customBlocks) {
if ((block.getItemID() == blockState.getTypeId()) && (block.getDataValue() == blockState.getRawData())) {
return block;
}
}
}
}
@@ -85,18 +80,42 @@ public final class ModChecks {
}
/**
* Check if a custom block is a mining block.
* Check if a custom block is a woodcutting block.
*
* @param block The block to check
* @return true if the block is custom, false otherwise
* @return true if the block represents a log, false otherwise
*/
public static boolean isCustomMiningBlock(Block block) {
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
public static boolean isCustomWoodcuttingBlock(BlockState blockState) {
if (customBlocksEnabled) {
ItemStack item = blockState.getData().toItemStack();
if (customBlocksEnabled && CustomBlocksConfig.getInstance().customMiningBlocks.contains(item)) {
for (CustomBlock b : CustomBlocksConfig.getInstance().customBlocks) {
if ((b.getItemID() == block.getTypeId()) && (b.getDataValue() == block.getData())) {
return true;
if (CustomBlocksConfig.getInstance().customWoodcuttingBlocks.contains(item)) {
for (CustomBlock block : CustomBlocksConfig.getInstance().customBlocks) {
if ((block.getItemID() == blockState.getTypeId()) && (block.getDataValue() == blockState.getRawData())) {
return true;
}
}
}
}
return false;
}
/**
* Check if a custom block should not activate abilites.
*
* @param block The block to check
* @return true if the block represents an ability block, false otherwise
*/
public static boolean isCustomAbilityBlock(BlockState blockState) {
if (customBlocksEnabled) {
ItemStack item = blockState.getData().toItemStack();
if (CustomBlocksConfig.getInstance().customAbilityBlocks.contains(item)) {
for (CustomBlock block : CustomBlocksConfig.getInstance().customBlocks) {
if ((block.getItemID() == blockState.getTypeId()) && (block.getDataValue() == blockState.getRawData())) {
return true;
}
}
}
}
@@ -110,13 +129,59 @@ public final class ModChecks {
* @param block The block to check
* @return true if the block is custom, false otherwise
*/
public static boolean isCustomExcavationBlock(Block block) {
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
public static boolean isCustomMiningBlock(BlockState blockState) {
if (customBlocksEnabled) {
ItemStack item = blockState.getData().toItemStack();
if (customBlocksEnabled && CustomBlocksConfig.getInstance().customExcavationBlocks.contains(item)) {
for (CustomBlock b : CustomBlocksConfig.getInstance().customBlocks) {
if ((b.getItemID() == block.getTypeId()) && (b.getDataValue() == block.getData())) {
return true;
if (CustomBlocksConfig.getInstance().customMiningBlocks.contains(item)) {
for (CustomBlock block : CustomBlocksConfig.getInstance().customBlocks) {
if ((block.getItemID() == blockState.getTypeId()) && (block.getDataValue() == blockState.getRawData())) {
return true;
}
}
}
}
return false;
}
/**
* Check if a custom block is an excavation block.
*
* @param block The block to check
* @return true if the block is custom, false otherwise
*/
public static boolean isCustomExcavationBlock(BlockState blockState) {
if (customBlocksEnabled) {
ItemStack item = blockState.getData().toItemStack();
if (CustomBlocksConfig.getInstance().customExcavationBlocks.contains(item)) {
for (CustomBlock block : CustomBlocksConfig.getInstance().customBlocks) {
if ((block.getItemID() == blockState.getTypeId()) && (block.getDataValue() == blockState.getRawData())) {
return true;
}
}
}
}
return false;
}
/**
* Check if a custom block is an herbalism block.
*
* @param blockState The block to check
* @return true if the block is custom, false otherwise
*/
public static boolean isCustomHerbalismBlock(BlockState blockState) {
if (customBlocksEnabled) {
ItemStack item = blockState.getData().toItemStack();
if (CustomBlocksConfig.getInstance().customHerbalismBlocks.contains(item)) {
for (CustomBlock block : CustomBlocksConfig.getInstance().customBlocks) {
if ((block.getItemID() == blockState.getTypeId()) && (block.getDataValue() == blockState.getRawData())) {
return true;
}
}
}
}
@@ -130,13 +195,15 @@ public final class ModChecks {
* @param block The block to check
* @return true if the block represents leaves, false otherwise
*/
public static boolean isCustomLeafBlock(Block block) {
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
public static boolean isCustomLeafBlock(BlockState blockState) {
if (customBlocksEnabled) {
ItemStack item = blockState.getData().toItemStack();
if (CustomBlocksConfig.getInstance().customLeaves.contains(item)) {
for (CustomBlock b : CustomBlocksConfig.getInstance().customBlocks) {
if ((b.getItemID() == block.getTypeId()) && (b.getDataValue() == block.getData())) {
return true;
if (CustomBlocksConfig.getInstance().customLeaves.contains(item)) {
for (CustomBlock block : CustomBlocksConfig.getInstance().customBlocks) {
if ((block.getItemID() == blockState.getTypeId()) && (block.getDataValue() == blockState.getRawData())) {
return true;
}
}
}
}
@@ -150,13 +217,15 @@ public final class ModChecks {
* @param block The block to check
* @return true if the block represents a log, false otherwise
*/
public static boolean isCustomLogBlock(Block block) {
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
public static boolean isCustomLogBlock(BlockState blockState) {
if (customBlocksEnabled) {
ItemStack item = blockState.getData().toItemStack();
if (CustomBlocksConfig.getInstance().customLogs.contains(item)) {
for (CustomBlock b : CustomBlocksConfig.getInstance().customBlocks) {
if ((b.getItemID() == block.getTypeId()) && (b.getDataValue() == block.getData())) {
return true;
if (CustomBlocksConfig.getInstance().customLogs.contains(item)) {
for (CustomBlock block : CustomBlocksConfig.getInstance().customBlocks) {
if ((block.getItemID() == blockState.getTypeId()) && (block.getDataValue() == blockState.getRawData())) {
return true;
}
}
}
}
@@ -167,16 +236,18 @@ public final class ModChecks {
/**
* Check if a custom block is an ore block.
*
* @param block The block to check
* @param blockState The block to check
* @return true if the block represents an ore, false otherwise
*/
public static boolean isCustomOreBlock(Block block) {
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
public static boolean isCustomOreBlock(BlockState blockState) {
if (customBlocksEnabled) {
ItemStack item = blockState.getData().toItemStack();
if (CustomBlocksConfig.getInstance().customOres.contains(item)) {
for (CustomBlock b : CustomBlocksConfig.getInstance().customBlocks) {
if ((b.getItemID() == block.getTypeId()) && (b.getDataValue() == block.getData())) {
return true;
if (CustomBlocksConfig.getInstance().customOres.contains(item)) {
for (CustomBlock block : CustomBlocksConfig.getInstance().customBlocks) {
if ((block.getItemID() == blockState.getTypeId()) && (block.getDataValue() == blockState.getRawData())) {
return true;
}
}
}
}

View File

@@ -14,6 +14,10 @@ public class Party {
private boolean locked;
private ShareHandler.ShareMode xpShareMode = ShareHandler.ShareMode.NONE;
private ShareHandler.ShareMode itemShareMode = ShareHandler.ShareMode.NONE;
private boolean shareLootDrops = true;
private boolean shareMiningDrops = true;
private boolean shareHerbalismDrops = true;
private boolean shareWoodcuttingDrops = true;
public List<OfflinePlayer> getMembers() {
return members;
@@ -47,6 +51,39 @@ public class Party {
return locked;
}
public boolean sharingLootDrops() {
return shareLootDrops;
}
public boolean sharingMiningDrops() {
return shareMiningDrops;
}
public boolean sharingHerbalismDrops() {
return shareHerbalismDrops;
}
public boolean sharingWoodcuttingDrops() {
return shareWoodcuttingDrops;
}
public List<String> getItemShareCategories() { //TODO Locale the category names!
List<String> shareCategories = new ArrayList<String>();
if (sharingLootDrops()) {
shareCategories.add("Loot");
}
if (sharingMiningDrops()) {
shareCategories.add("Mining");
}
if (sharingHerbalismDrops()) {
shareCategories.add("Herbalism");
}
if (sharingWoodcuttingDrops()) {
shareCategories.add("Woodcutting");
}
return shareCategories;
}
public void setName(String name) {
this.name = name;
}
@@ -78,4 +115,20 @@ public class Party {
public ShareHandler.ShareMode getItemShareMode() {
return itemShareMode;
}
public void setSharingLootDrops(boolean enabled) {
this.shareLootDrops = enabled;
}
public void setSharingMiningDrops(boolean enabled) {
this.shareMiningDrops = enabled;
}
public void setSharingHerbalismDrops(boolean enabled) {
this.shareHerbalismDrops = enabled;
}
public void setSharingWoodcuttingDrops(boolean enabled) {
this.shareWoodcuttingDrops = enabled;
}
}

View File

@@ -74,7 +74,7 @@ public final class PartyManager {
List<Player> nearMembers = new ArrayList<Player>();
if (party != null) {
for (Player member : party.getOnlineMembers()) {
if (player != member && Misc.isNear(player.getLocation(), member.getLocation(), range)) {
if (!player.getName().equals(member.getName()) && Misc.isNear(player.getLocation(), member.getLocation(), range)) {
nearMembers.add(member);
}
}
@@ -223,6 +223,7 @@ public final class PartyManager {
if (mcMMOPlayer != null) {
mcMMOPlayer.removeParty();
mcMMOPlayer.setItemShareModifier(10);
}
}
@@ -239,6 +240,7 @@ public final class PartyManager {
if (mcMMOPlayer != null) {
mcMMOPlayer.removeParty();
mcMMOPlayer.setItemShareModifier(10);
}
}
@@ -294,6 +296,10 @@ public final class PartyManager {
return;
}
if (mcMMOPlayer.getParty() == party) {
return;
}
player.sendMessage(LocaleLoader.getString("Commands.Party.Join", party.getName()));
addToParty(player, mcMMOPlayer, party);
}
@@ -339,6 +345,10 @@ public final class PartyManager {
public static void joinInvitedParty(Player player, McMMOPlayer mcMMOPlayer) {
Party invite = mcMMOPlayer.getPartyInvite();
if (mcMMOPlayer.getParty() == invite) {
return;
}
if (!parties.contains(invite)) {
parties.add(invite);
}
@@ -356,6 +366,10 @@ public final class PartyManager {
* @param party The party
*/
public static void addToParty(OfflinePlayer player, McMMOPlayer mcMMOPlayer, Party party) {
if (mcMMOPlayer.getParty() == party) {
return;
}
informPartyMembersJoin(player, party);
mcMMOPlayer.setParty(party);
party.getMembers().add(player);

View File

@@ -8,8 +8,10 @@ import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.ItemWeightsConfig;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.ItemChecks;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Users;
@@ -34,6 +36,9 @@ public final class ShareHandler {
private ShareHandler() {}
private static List<Player> nearMembers;
private static int partySize;
/**
* Distribute Xp amongst party members.
*
@@ -48,7 +53,7 @@ public final class ShareHandler {
switch (party.getXpShareMode()) {
case EQUAL:
Player player = mcMMOPlayer.getPlayer();
List<Player> nearMembers = PartyManager.getNearMembers(player, party, Config.getInstance().getPartyShareRange());
nearMembers = PartyManager.getNearMembers(player, party, Config.getInstance().getPartyShareRange());
if (nearMembers.isEmpty()) {
return false;
@@ -86,38 +91,95 @@ public final class ShareHandler {
Item item = event.getItem();
ItemStack itemStack = item.getItemStack();
Party party = mcMMOPlayer.getParty();
Player player = mcMMOPlayer.getPlayer();
Player winningPlayer = null;
ItemStack newStack = itemStack.clone();
newStack.setAmount(1);
if (ItemChecks.isMobDrop(itemStack) && !party.sharingLootDrops()) {
return false;
}
else if (ItemChecks.isMiningDrop(itemStack) && !party.sharingMiningDrops()) {
return false;
}
else if (ItemChecks.isHerbalismDrop(itemStack) && !party.sharingHerbalismDrops()) {
return false;
}
else if (ItemChecks.isWoodcuttingDrop(itemStack) && !party.sharingWoodcuttingDrops()) {
return false;
}
switch (party.getItemShareMode()) {
case EQUAL:
return false;
case RANDOM:
Player player = mcMMOPlayer.getPlayer();
List<Player> nearMembers = PartyManager.getNearMembers(player, party, Config.getInstance().getPartyShareRange());
McMMOPlayer mcMMOTarget;
nearMembers = PartyManager.getNearMembers(player, party, Config.getInstance().getPartyShareRange());
if (nearMembers.isEmpty()) {
return false;
}
int partySize = nearMembers.size() + 1;
nearMembers.add(player);
partySize = nearMembers.size();
event.setCancelled(true);
item.remove();
int itemWeight = ItemWeightsConfig.getInstance().getItemWeight(itemStack.getType());
for (int i = 0; i < itemStack.getAmount(); i++) {
int highestRoll = 0;
for (Player member : nearMembers) {
McMMOPlayer mcMMOMember = Users.getPlayer(member);
int itemShareModifier = mcMMOMember.getItemShareModifier();
int diceRoll = Misc.getRandom().nextInt(itemShareModifier);
if (diceRoll > highestRoll) {
highestRoll = diceRoll;
if (winningPlayer != null) {
McMMOPlayer mcMMOWinning = Users.getPlayer(winningPlayer);
mcMMOWinning.setItemShareModifier(mcMMOWinning.getItemShareModifier() + itemWeight);
}
winningPlayer = member;
}
else {
mcMMOMember.setItemShareModifier(itemShareModifier + itemWeight);
}
}
mcMMOTarget = Users.getPlayer(winningPlayer);
mcMMOTarget.setItemShareModifier(mcMMOTarget.getItemShareModifier() - itemWeight);
if (winningPlayer.getInventory().addItem(newStack).size() != 0) {
winningPlayer.getWorld().dropItemNaturally(winningPlayer.getLocation(), newStack);
}
winningPlayer.updateInventory();
}
return true;
case RANDOM:
nearMembers = PartyManager.getNearMembers(player, party, Config.getInstance().getPartyShareRange());
if (nearMembers.isEmpty()) {
return false;
}
partySize = nearMembers.size() + 1;
event.setCancelled(true);
item.remove();
Player targetPlayer;
ItemStack newStack = itemStack.clone();
newStack.setAmount(1);
//TODO Improve this, if possible make this faster.
for (int i = 0; i < itemStack.getAmount(); i++) {
int randomMember = Misc.getRandom().nextInt(partySize);
if (randomMember >= nearMembers.size()) {
targetPlayer = player;
winningPlayer = player;
} else {
targetPlayer = nearMembers.get(randomMember);
winningPlayer = nearMembers.get(randomMember);
}
targetPlayer.getInventory().addItem(newStack);
targetPlayer.updateInventory();
if (winningPlayer.getInventory().addItem(newStack).size() != 0) {
winningPlayer.getWorld().dropItemNaturally(winningPlayer.getLocation(), newStack);
}
winningPlayer.updateInventory();
}
return true;
case NONE:
@@ -125,5 +187,4 @@ public final class ShareHandler {
return false;
}
}
}
}

View File

@@ -17,7 +17,7 @@ public class PartyHelpCommand implements CommandExecutor {
sender.sendMessage(LocaleLoader.getString("Party.Help.4", "/party <lock|unlock>"));
sender.sendMessage(LocaleLoader.getString("Party.Help.5", "/party password"));
sender.sendMessage(LocaleLoader.getString("Party.Help.6", "/party kick"));
sender.sendMessage(LocaleLoader.getString("Party.Help.7", "/party owner"));
sender.sendMessage(LocaleLoader.getString("Party.Help.7", "/party leader"));
sender.sendMessage(LocaleLoader.getString("Party.Help.8", "/party disband"));
return true;

View File

@@ -12,6 +12,7 @@ import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.party.ShareHandler;
import com.gmail.nossr50.util.Users;
public class PartyInfoCommand implements CommandExecutor {
@@ -51,6 +52,7 @@ public class PartyInfoCommand implements CommandExecutor {
private void displayShareModeInfo() {
boolean xpShareEnabled = Config.getInstance().getExpShareEnabled();
boolean itemShareEnabled = Config.getInstance().getItemShareEnabled();
boolean itemSharingActive = playerParty.getItemShareMode() != ShareHandler.ShareMode.NONE;
if (!xpShareEnabled && !itemShareEnabled) {
return;
@@ -73,6 +75,9 @@ public class PartyInfoCommand implements CommandExecutor {
}
player.sendMessage(LocaleLoader.getString("Commands.Party.ShareMode") + expShareInfo + separator + itemShareInfo);
if (itemSharingActive) {
player.sendMessage(LocaleLoader.getString("Commands.Party.ItemShareCategories", playerParty.getItemShareCategories()));
}
}
private void displayPartyHeader() {

View File

@@ -30,22 +30,50 @@ public class PartyItemShareCommand implements CommandExecutor {
if (args[1].equalsIgnoreCase("none") || args[1].equalsIgnoreCase("off") || args[1].equalsIgnoreCase("false")) {
handleChangingShareMode(ShareMode.NONE);
}
// else if (args[1].equalsIgnoreCase("equal") || args[1].equalsIgnoreCase("even")) {
// handleChangingShareMode(ShareMode.EQUAL);
// }
else if (args[1].equalsIgnoreCase("equal") || args[1].equalsIgnoreCase("even")) {
handleChangingShareMode(ShareMode.EQUAL);
}
else if (args[1].equalsIgnoreCase("random")) {
handleChangingShareMode(ShareMode.RANDOM);
}
else {
// sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "<NONE | EQUAL | RANDOM>"));
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "<NONE | RANDOM>"));
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "<NONE | EQUAL | RANDOM>"));
}
return true;
case 3:
playerParty = Users.getPlayer((Player) sender).getParty();
boolean toggle = false;
if (args[2].equalsIgnoreCase("true") || args[2].equalsIgnoreCase("on")|| args[2].equalsIgnoreCase("enabled")) {
toggle = true;
}
else if (args[2].equalsIgnoreCase("false") || args[2].equalsIgnoreCase("off")|| args[2].equalsIgnoreCase("disabled")) {
toggle = false;
}
if (args[1].equalsIgnoreCase("loot")) {
playerParty.setSharingLootDrops(toggle);
}
else if (args[1].equalsIgnoreCase("mining")) {
playerParty.setSharingMiningDrops(toggle);
}
else if (args[1].equalsIgnoreCase("herbalism")) {
playerParty.setSharingHerbalismDrops(toggle);
}
else if (args[1].equalsIgnoreCase("woodcutting")) {
playerParty.setSharingWoodcuttingDrops(toggle);
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "<loot | mining | herbalism | woodcutting> <true | false>"));
}
notifyToggleItemShareCategory(args, toggle);
return true;
default:
// sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "<NONE | EQUAL | RANDOM>"));
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "<NONE | RANDOM>"));
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "<NONE | EQUAL | RANDOM>"));
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "<loot | mining | herbalism | woodcutting> <true | false>"));
return true;
}
}
@@ -57,4 +85,16 @@ public class PartyItemShareCommand implements CommandExecutor {
member.sendMessage(LocaleLoader.getString("Commands.Party.SetSharing", LocaleLoader.getString("Party.ShareType.Item"), LocaleLoader.getString("Party.ShareMode." + StringUtils.getCapitalized(mode.toString()))));
}
}
private void notifyToggleItemShareCategory(String[] args, boolean toggle) {
String state = "disabled";
if (toggle) {
state = "enabled";
}
for (Player member : playerParty.getOnlineMembers()) {
member.sendMessage(LocaleLoader.getString("Commands.Party.ToggleShareCategory", StringUtils.getCapitalized(args[1]), state));
}
}
}

View File

@@ -33,6 +33,9 @@ public enum PartySubcommandType {
else if (commandName.equalsIgnoreCase("q") || commandName.equalsIgnoreCase("leave")) {
return QUIT;
}
else if (commandName.equalsIgnoreCase("leader")) {
return OWNER;
}
else if (commandName.equalsIgnoreCase("xpshare") || commandName.equalsIgnoreCase("shareexp") || commandName.equalsIgnoreCase("sharexp")) {
return EXPSHARE;
}

View File

@@ -8,6 +8,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.PerksUtils;
@@ -125,7 +126,7 @@ public abstract class SkillCommand implements CommandExecutor {
protected String[] calculateLengthDisplayValues() {
int maxLength = skill.getAbility().getMaxTicks();
int length = 2 + (int) (skillValue / SkillTools.abilityLengthIncreaseLevel);
int length = 2 + (int) (skillValue / AdvancedConfig.getInstance().getAbilityLength());
int enduranceLength = PerksUtils.handleActivationPerks(player, length, maxLength);
if (maxLength != 0) {

View File

@@ -1,18 +1,19 @@
package com.gmail.nossr50.skills;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.skills.utilities.PerksUtils;
import com.gmail.nossr50.skills.utilities.SkillType;
public abstract class SkillManager {
protected McMMOPlayer mcMMOPlayer;
protected int skillLevel;
protected int activationChance;
protected SkillType skill;
public SkillManager(McMMOPlayer mcMMOPlayer, SkillType skill) {
this.mcMMOPlayer = mcMMOPlayer;
this.skillLevel = mcMMOPlayer.getProfile().getSkillLevel(skill);
this.activationChance = PerksUtils.handleLuckyPerks(mcMMOPlayer.getPlayer(), skill);
this.skill = skill;
}
@@ -21,15 +22,23 @@ public abstract class SkillManager {
return mcMMOPlayer;
}
public Player getPlayer() {
return mcMMOPlayer.getPlayer();
}
public PlayerProfile getProfile() {
return mcMMOPlayer.getProfile();
}
public int getSkillLevel() {
return skillLevel;
return mcMMOPlayer.getProfile().getSkillLevel(skill);
}
public int getActivationChance() {
return activationChance;
}
public SkillType getSkill() {
return skill;
public void applyXpGain(int xp) {
mcMMOPlayer.beginXpGain(skill, xp);
}
}

View File

@@ -0,0 +1,128 @@
package com.gmail.nossr50.skills;
import java.util.HashMap;
import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager;
import com.gmail.nossr50.skills.archery.ArcheryManager;
import com.gmail.nossr50.skills.axes.AxeManager;
import com.gmail.nossr50.skills.excavation.ExcavationManager;
import com.gmail.nossr50.skills.fishing.FishingManager;
import com.gmail.nossr50.skills.herbalism.HerbalismManager;
import com.gmail.nossr50.skills.mining.MiningManager;
import com.gmail.nossr50.skills.smelting.SmeltingManager;
import com.gmail.nossr50.skills.swords.SwordsManager;
import com.gmail.nossr50.skills.taming.TamingManager;
import com.gmail.nossr50.skills.unarmed.UnarmedManager;
import com.gmail.nossr50.util.Users;
public class SkillManagerStore {
private static SkillManagerStore instance;
private HashMap<String, AcrobaticsManager> acrobaticsManagers = new HashMap<String, AcrobaticsManager>();
private HashMap<String, ArcheryManager> archeryManagers = new HashMap<String, ArcheryManager>();
private HashMap<String, AxeManager> axeManagers = new HashMap<String, AxeManager>();
private HashMap<String, ExcavationManager> excavationManagers = new HashMap<String, ExcavationManager>();
private HashMap<String, FishingManager> fishingManagers = new HashMap<String, FishingManager>();
private HashMap<String, HerbalismManager> herbalismManagers = new HashMap<String, HerbalismManager>();
private HashMap<String, MiningManager> miningManagers = new HashMap<String, MiningManager>();
private HashMap<String, SmeltingManager> smeltingManagers = new HashMap<String, SmeltingManager>();
private HashMap<String, SwordsManager> swordsManagers = new HashMap<String, SwordsManager>();
private HashMap<String, TamingManager> tamingManagers = new HashMap<String, TamingManager>();
private HashMap<String, UnarmedManager> unarmedManagers = new HashMap<String, UnarmedManager>();
public static SkillManagerStore getInstance() {
if (instance == null) {
instance = new SkillManagerStore();
}
return instance;
}
public AcrobaticsManager getAcrobaticsManager(String playerName) {
if (!acrobaticsManagers.containsKey(playerName)) {
acrobaticsManagers.put(playerName, new AcrobaticsManager(Users.getPlayer(playerName)));
}
return acrobaticsManagers.get(playerName);
}
public ArcheryManager getArcheryManager(String playerName) {
if (!archeryManagers.containsKey(playerName)) {
archeryManagers.put(playerName, new ArcheryManager(Users.getPlayer(playerName)));
}
return archeryManagers.get(playerName);
}
public AxeManager getAxeManager(String playerName) {
if (!axeManagers.containsKey(playerName)) {
axeManagers.put(playerName, new AxeManager(Users.getPlayer(playerName)));
}
return axeManagers.get(playerName);
}
public ExcavationManager getExcavationManager(String playerName) {
if (!excavationManagers.containsKey(playerName)) {
excavationManagers.put(playerName, new ExcavationManager(Users.getPlayer(playerName)));
}
return excavationManagers.get(playerName);
}
public FishingManager getFishingManager(String playerName) {
if (!fishingManagers.containsKey(playerName)) {
fishingManagers.put(playerName, new FishingManager(Users.getPlayer(playerName)));
}
return fishingManagers.get(playerName);
}
public HerbalismManager getHerbalismManager(String playerName) {
if (!herbalismManagers.containsKey(playerName)) {
herbalismManagers.put(playerName, new HerbalismManager(Users.getPlayer(playerName)));
}
return herbalismManagers.get(playerName);
}
public MiningManager getMiningManager(String playerName) {
if (!miningManagers.containsKey(playerName)) {
miningManagers.put(playerName, new MiningManager(Users.getPlayer(playerName)));
}
return miningManagers.get(playerName);
}
public SmeltingManager getSmeltingManager(String playerName) {
if (!smeltingManagers.containsKey(playerName)) {
smeltingManagers.put(playerName, new SmeltingManager(Users.getPlayer(playerName)));
}
return smeltingManagers.get(playerName);
}
public SwordsManager getSwordsManager(String playerName) {
if (!swordsManagers.containsKey(playerName)) {
swordsManagers.put(playerName, new SwordsManager(Users.getPlayer(playerName)));
}
return swordsManagers.get(playerName);
}
public TamingManager getTamingManager(String playerName) {
if (!tamingManagers.containsKey(playerName)) {
tamingManagers.put(playerName, new TamingManager(Users.getPlayer(playerName)));
}
return tamingManagers.get(playerName);
}
public UnarmedManager getUnarmedManager(String playerName) {
if (!unarmedManagers.containsKey(playerName)) {
unarmedManagers.put(playerName, new UnarmedManager(Users.getPlayer(playerName)));
}
return unarmedManagers.get(playerName);
}
}

View File

@@ -3,20 +3,34 @@ package com.gmail.nossr50.skills.acrobatics;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config;
public class Acrobatics {
public final class Acrobatics {
public static double dodgeMaxChance = AdvancedConfig.getInstance().getDodgeChanceMax();
public static int dodgeMaxBonusLevel = AdvancedConfig.getInstance().getDodgeMaxBonusLevel();
public static int dodgeXpModifier = AdvancedConfig.getInstance().getDodgeXPModifier();
public static int dodgeDamageModifier = AdvancedConfig.getInstance().getDodgeDamageModifier();
public static double rollMaxChance = AdvancedConfig.getInstance().getRollChanceMax();
public static int rollMaxBonusLevel = AdvancedConfig.getInstance().getRollMaxBonusLevel();
public static int rollThreshold = AdvancedConfig.getInstance().getRollDamageThreshold();
public static double gracefulRollMaxChance = AdvancedConfig.getInstance().getGracefulRollChanceMax();
public static int gracefulRollMaxBonusLevel = AdvancedConfig.getInstance().getGracefulRollMaxBonusLevel();
public static int gracefulRollThreshold = AdvancedConfig.getInstance().getGracefulRollDamageThreshold();
public static int gracefulRollSuccessModifier = AdvancedConfig.getInstance().getGracefulRollSuccessModifer();
public static int rollXpModifier = AdvancedConfig.getInstance().getRollXPModifier();
public static int fallXpModifier = AdvancedConfig.getInstance().getFallXPModifier();
public static boolean afkLevelingDisabled = Config.getInstance().getAcrobaticsAFKDisabled();
public static boolean dodgeLightningDisabled = Config.getInstance().getDodgeLightningDisabled();
private Acrobatics() {};
protected static int calculateModifiedDodgeDamage(int damage, int damageModifier) {
return Math.max(damage / damageModifier, 1);
}
protected static int calculateModifiedRollDamage(int damage, int damageThreshold) {
return Math.max(damage - damageThreshold, 0);
}
}

View File

@@ -1,62 +0,0 @@
package com.gmail.nossr50.skills.acrobatics;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent;
import com.gmail.nossr50.util.Misc;
public abstract class AcrobaticsEventHandler {
protected AcrobaticsManager manager;
protected EntityDamageEvent event;
protected int damage;
protected int skillModifier;
protected int modifiedDamage;
protected AcrobaticsEventHandler(AcrobaticsManager manager, EntityDamageEvent event) {
this.manager = manager;
this.event = event;
this.damage = event.getDamage();
}
/**
* Calculate the skill modifier applied for this event.
*/
protected abstract void calculateSkillModifier();
/**
* Calculate the modified damage for this event.
*/
protected abstract void calculateModifiedDamage();
/**
* Modify the damage dealt by this event.
*/
protected abstract void modifyEventDamage();
/**
* Send the ability message for this event.
*/
protected abstract void sendAbilityMessage();
/**
* Process Xp gain from this event.
*/
protected abstract void processXpGain(int xp);
/**
* Check to ensure you're not gaining XP after you die.
*
* @param damage The damage to be dealt
* @return true if the damage is fatal, false otherwise
*/
protected boolean isFatal(int damage) {
Player player = manager.getMcMMOPlayer().getPlayer();
if (Misc.isNPCEntity(player) || player.getHealth() - damage < 1) {
return true;
}
return false;
}
}

View File

@@ -1,58 +1,129 @@
package com.gmail.nossr50.skills.acrobatics;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LightningStrike;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.ParticleEffectUtils;
import com.gmail.nossr50.util.Permissions;
public class AcrobaticsManager extends SkillManager {
public AcrobaticsManager (McMMOPlayer mcMMOPlayer) {
super(mcMMOPlayer, SkillType.ACROBATICS);
}
/**
* Check for fall damage reduction.
*
* @param event The event to check
*/
public void rollCheck(EntityDamageEvent event) {
RollEventHandler eventHandler = new RollEventHandler(this, event);
public boolean canRoll() {
Player player = getPlayer();
double chance;
return (player.getItemInHand().getType() != Material.ENDER_PEARL) && !(Acrobatics.afkLevelingDisabled && player.isInsideVehicle()) && Permissions.roll(player);
}
if (eventHandler.isGraceful) {
chance = (Acrobatics.gracefulRollMaxChance / Acrobatics.gracefulRollMaxBonusLevel) * eventHandler.skillModifier;
}
else {
chance = (Acrobatics.rollMaxChance / Acrobatics.rollMaxBonusLevel) * eventHandler.skillModifier;
public boolean canDodge(Entity damager) {
if (Permissions.dodge(getPlayer())) {
if (damager instanceof Player && SkillType.ACROBATICS.getPVPEnabled()) {
return true;
}
else if (!(damager instanceof Player) && SkillType.ACROBATICS.getPVEEnabled() && !(damager instanceof LightningStrike && Acrobatics.dodgeLightningDisabled)) {
return true;
}
}
if (chance > Misc.getRandom().nextInt(activationChance) && !eventHandler.isFatal(eventHandler.modifiedDamage)) {
eventHandler.modifyEventDamage();
eventHandler.sendAbilityMessage();
eventHandler.processXpGain(eventHandler.damage * Acrobatics.rollXpModifier);
}
else if (!eventHandler.isFatal(event.getDamage())) {
eventHandler.processXpGain(eventHandler.damage * Acrobatics.fallXpModifier);
}
return false;
}
/**
* Check for dodge damage reduction.
* Handle the damage reduction and XP gain from the Dodge ability
*
* @param event The event to check
* @param damage The amount of damage initially dealt by the event
* @return the modified event damage if the ability was successful, the original event damage otherwise
*/
public void dodgeCheck(EntityDamageEvent event) {
DodgeEventHandler eventHandler = new DodgeEventHandler(this, event);
public int dodgeCheck(int damage) {
int modifiedDamage = Acrobatics.calculateModifiedDodgeDamage(damage, Acrobatics.dodgeDamageModifier);
Player player = getPlayer();
double chance = (Acrobatics.dodgeMaxChance / Acrobatics.dodgeMaxBonusLevel) * eventHandler.skillModifier;
if (!isFatal(modifiedDamage) && SkillTools.activationSuccessful(player, skill, Acrobatics.dodgeMaxChance, Acrobatics.dodgeMaxBonusLevel)) {
ParticleEffectUtils.playDodgeEffect(player);
if (chance > Misc.getRandom().nextInt(activationChance) && !eventHandler.isFatal(eventHandler.modifiedDamage)) {
eventHandler.modifyEventDamage();
eventHandler.sendAbilityMessage();
eventHandler.processXpGain(eventHandler.damage * Acrobatics.dodgeXpModifier);
PlayerProfile playerProfile = getProfile();
if (playerProfile.useChatNotifications()) {
player.sendMessage(LocaleLoader.getString("Acrobatics.Combat.Proc"));
}
// Why do we check respawn cooldown here?
if (System.currentTimeMillis() >= playerProfile.getRespawnATS() + Misc.PLAYER_RESPAWN_COOLDOWN_SECONDS) {
applyXpGain(damage * Acrobatics.dodgeXpModifier);
}
return modifiedDamage;
}
return damage;
}
/**
* Handle the damage reduction and XP gain from the Roll ability
*
* @param damage The amount of damage initially dealt by the event
* @return the modified event damage if the ability was successful, the original event damage otherwise
*/
public int rollCheck(int damage) {
Player player = getPlayer();
if (player.isSneaking() && Permissions.gracefulRoll(player)) {
return gracefulRollCheck(damage);
}
int modifiedDamage = Acrobatics.calculateModifiedRollDamage(damage, Acrobatics.rollThreshold);
if (!isFatal(modifiedDamage) && isSuccessfulRoll(Acrobatics.rollMaxChance, Acrobatics.rollMaxBonusLevel, 1)) {
player.sendMessage(LocaleLoader.getString("Acrobatics.Roll.Text"));
applyXpGain(damage * Acrobatics.rollXpModifier);
return modifiedDamage;
}
else if (!isFatal(damage)) {
applyXpGain(damage * Acrobatics.fallXpModifier);
}
return damage;
}
/**
* Handle the damage reduction and XP gain from the Graceful Roll ability
*
* @param damage The amount of damage initially dealt by the event
* @return the modified event damage if the ability was successful, the original event damage otherwise
*/
private int gracefulRollCheck(int damage) {
int modifiedDamage = Acrobatics.calculateModifiedRollDamage(damage, Acrobatics.gracefulRollThreshold);
if (!isFatal(modifiedDamage) && isSuccessfulRoll(Acrobatics.gracefulRollMaxChance, Acrobatics.gracefulRollMaxBonusLevel, Acrobatics.gracefulRollSuccessModifier)) {
getPlayer().sendMessage(LocaleLoader.getString("Acrobatics.Ability.Proc"));
applyXpGain(damage * Acrobatics.rollXpModifier);
return modifiedDamage;
}
else if (!isFatal(damage)) {
applyXpGain(damage * Acrobatics.fallXpModifier);
}
return damage;
}
private boolean isSuccessfulRoll(double maxChance, int maxLevel, int successModifier) {
return ((maxChance / maxLevel) * Math.min(getSkillLevel(), maxLevel) * successModifier) > Misc.getRandom().nextInt(activationChance);
}
private boolean isFatal(int damage) {
return getPlayer().getHealth() - damage < 1;
}
}

View File

@@ -1,62 +0,0 @@
package com.gmail.nossr50.skills.acrobatics;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.ParticleEffectUtils;
public class DodgeEventHandler extends AcrobaticsEventHandler {
protected DodgeEventHandler(AcrobaticsManager manager, EntityDamageEvent event) {
super(manager, event);
calculateSkillModifier();
calculateModifiedDamage();
}
@Override
protected void calculateSkillModifier() {
this.skillModifier = SkillTools.skillCheck(manager.getSkillLevel(), Acrobatics.dodgeMaxBonusLevel);
}
@Override
protected void calculateModifiedDamage() {
int modifiedDamage = damage / 2;
if (modifiedDamage <= 0) {
modifiedDamage = 1;
}
this.modifiedDamage = modifiedDamage;
}
@Override
protected void modifyEventDamage() {
event.setDamage(modifiedDamage);
}
@Override
protected void sendAbilityMessage() {
McMMOPlayer mcMMOPlayer = manager.getMcMMOPlayer();
Player dodgingPlayer = mcMMOPlayer.getPlayer();
ParticleEffectUtils.playDodgeEffect(dodgingPlayer);
if (mcMMOPlayer.getProfile().useChatNotifications()) {
dodgingPlayer.sendMessage(LocaleLoader.getString("Acrobatics.Combat.Proc"));
}
}
@Override
protected void processXpGain(int xp) {
McMMOPlayer mcMMOPlayer = manager.getMcMMOPlayer();
if (System.currentTimeMillis() >= mcMMOPlayer.getProfile().getRespawnATS() + Misc.PLAYER_RESPAWN_COOLDOWN_SECONDS) {
manager.getMcMMOPlayer().beginXpGain(SkillType.ACROBATICS, xp);
}
}
}

View File

@@ -1,101 +0,0 @@
package com.gmail.nossr50.skills.acrobatics;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Permissions;
public class RollEventHandler extends AcrobaticsEventHandler {
protected boolean isGraceful;
private int damageThreshold;
protected RollEventHandler(AcrobaticsManager manager, EntityDamageEvent event) {
super(manager, event);
isGracefulRoll();
calculateSkillModifier();
calculateDamageThreshold();
calculateModifiedDamage();
}
@Override
protected void calculateSkillModifier() {
int skillModifer = manager.getSkillLevel();
if (isGraceful) {
skillModifer = skillModifer * 2;
}
skillModifer = SkillTools.skillCheck(skillModifer, Acrobatics.rollMaxBonusLevel);
this.skillModifier = skillModifer;
}
@Override
protected void calculateModifiedDamage() {
int modifiedDamage = damage - damageThreshold;
if (modifiedDamage < 0) {
modifiedDamage = 0;
}
this.modifiedDamage = modifiedDamage;
}
@Override
protected void modifyEventDamage() {
event.setDamage(modifiedDamage);
if (event.getDamage() == 0) {
event.setCancelled(true);
}
}
@Override
protected void sendAbilityMessage() {
Player player = manager.getMcMMOPlayer().getPlayer();
if (isGraceful) {
player.sendMessage(LocaleLoader.getString("Acrobatics.Ability.Proc"));
}
else {
player.sendMessage(LocaleLoader.getString("Acrobatics.Roll.Text"));
}
}
@Override
protected void processXpGain(int xp) {
manager.getMcMMOPlayer().beginXpGain(SkillType.ACROBATICS, xp);
}
/**
* Check if this is a graceful roll.
*/
private void isGracefulRoll() {
Player player = manager.getMcMMOPlayer().getPlayer();
if (Permissions.gracefulRoll(player)) {
this.isGraceful = player.isSneaking();
}
else {
this.isGraceful = false;
}
}
/**
* Calculate the damage threshold for this event.
*/
private void calculateDamageThreshold() {
int damageThreshold = 7;
if (isGraceful) {
damageThreshold = damageThreshold * 2;
}
this.damageThreshold = damageThreshold;
}
}

View File

@@ -58,7 +58,7 @@ public class Archery {
for (Iterator<TrackedEntity> entityIterator = trackedEntities.iterator(); entityIterator.hasNext(); ) {
TrackedEntity trackedEntity = entityIterator.next();
if (trackedEntity.getLivingEntity().getEntityId() == livingEntity.getEntityId()) {
if (trackedEntity.getID() == livingEntity.getUniqueId()) {
Misc.dropItems(livingEntity.getLocation(), new ItemStack(Material.ARROW), trackedEntity.getArrowCount());
entityIterator.remove();
return;

View File

@@ -1,23 +1,49 @@
package com.gmail.nossr50.skills.archery;
import org.bukkit.Location;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users;
public class ArcheryManager extends SkillManager {
public ArcheryManager (McMMOPlayer mcMMOPlayer) {
super(mcMMOPlayer, SkillType.ARCHERY);
}
public boolean canDaze(LivingEntity target) {
return target instanceof Player && Permissions.daze(getPlayer());
}
public boolean canSkillShot() {
Player player = getPlayer();
return SkillTools.unlockLevelReached(player, skill, Archery.skillShotIncreaseLevel) && Permissions.bonusDamage(player, skill);
}
public boolean canTrackArrows() {
Player player = getPlayer();
return !(player.getItemInHand().containsEnchantment(Enchantment.ARROW_INFINITE)) && Permissions.arrowRetrieval(player);
}
/**
* Calculate bonus XP awarded for Archery when hitting a far-away target.
*
* @param target The {@link LivingEntity} damaged by the arrow
*/
public void distanceXpBonus(LivingEntity target) {
Player player = mcMMOPlayer.getPlayer();
Player player = getPlayer();
Location shooterLocation = player.getLocation();
Location targetLocation = target.getLocation();
@@ -25,61 +51,65 @@ public class ArcheryManager extends SkillManager {
return;
}
double squaredDistance = shooterLocation.distanceSquared(targetLocation);
// Cap distance at 100^2 to prevent teleport exploit.
// TODO: Better way to handle this would be great...
if (squaredDistance > 10000) {
squaredDistance = 10000;
}
double squaredDistance = Math.min(shooterLocation.distanceSquared(targetLocation), 10000);
int bonusXp = (int) (squaredDistance * Archery.distanceXpModifer);
mcMMOPlayer.beginXpGain(SkillType.ARCHERY, bonusXp);
applyXpGain((int) (squaredDistance * Archery.distanceXpModifer));
}
/**
* Track arrows fired for later retrieval.
*
* @param livingEntity Entity damaged by the arrow
* @param target The {@link LivingEntity} damaged by the arrow
*/
public void trackArrows(LivingEntity livingEntity) {
ArrowTrackingEventHandler eventHandler = new ArrowTrackingEventHandler(this, livingEntity);
double chance = (Archery.retrieveMaxChance / Archery.retrieveMaxBonusLevel) * eventHandler.skillModifier;
if (chance > Misc.getRandom().nextInt(activationChance)) {
eventHandler.addToTracker();
public void trackArrows(LivingEntity target) {
if (SkillTools.activationSuccessful(getPlayer(), skill, Archery.retrieveMaxChance, Archery.retrieveMaxBonusLevel)) {
Archery.incrementTrackerValue(target);
}
}
/**
* Check for Daze.
* Handle the effects of the Daze ability
*
* @param defender Defending player
* @param event The event to modify
* @param defender The player being affected by the ability
* @param damage The amount of damage initially dealt by the event
* @return the modified event damage if the ability was successful, the original event damage otherwise
*/
public void dazeCheck(Player defender, EntityDamageEvent event) {
DazeEventHandler eventHandler = new DazeEventHandler(this, event, defender);
public int dazeCheck(Player defender, int damage) {
Player attacker = getPlayer();
double chance = (Archery.dazeMaxBonus / Archery.dazeMaxBonusLevel) * eventHandler.skillModifier;
if (SkillTools.activationSuccessful(attacker, skill, Archery.dazeMaxBonus, Archery.dazeMaxBonusLevel)) {
Location dazedLocation = defender.getLocation();
dazedLocation.setPitch(90 - Misc.getRandom().nextInt(181));
if (chance > Misc.getRandom().nextInt(activationChance)) {
eventHandler.handleDazeEffect();
eventHandler.sendAbilityMessages();
defender.teleport(dazedLocation);
defender.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 20 * 10, 10));
if (Users.getPlayer(defender).getProfile().useChatNotifications()) {
defender.sendMessage(LocaleLoader.getString("Combat.TouchedFuzzy"));
}
if (getProfile().useChatNotifications()) {
attacker.sendMessage(LocaleLoader.getString("Combat.TargetDazed"));
}
return damage + Archery.dazeModifier;
}
return damage;
}
/**
* Handle archery bonus damage.
* Handle the effects of the Skill Shot ability
*
* @param event The event to modify.
* @param damage The amount of damage initially dealt by the event
* @return the modified event damage
*/
public void skillShot(EntityDamageEvent event) {
if (skillLevel >= Archery.skillShotIncreaseLevel && Permissions.bonusDamage(mcMMOPlayer.getPlayer(), skill)) {
SkillShotEventHandler eventHandler = new SkillShotEventHandler(this, event);
public int skillShotCheck(int damage) {
double damageBonusPercent = Math.min(((getSkillLevel() / Archery.skillShotIncreaseLevel) * Archery.skillShotIncreasePercentage), Archery.skillShotMaxBonusPercentage);
int archeryBonus = (int) (damage * damageBonusPercent);
eventHandler.calculateDamageBonus();
eventHandler.modifyEventDamage();
}
return damage + archeryBonus;
}
}

View File

@@ -1,27 +0,0 @@
package com.gmail.nossr50.skills.archery;
import org.bukkit.entity.LivingEntity;
import com.gmail.nossr50.skills.utilities.SkillTools;
public class ArrowTrackingEventHandler {
private ArcheryManager manager;
private LivingEntity entity;
protected int skillModifier;
protected ArrowTrackingEventHandler (ArcheryManager manager, LivingEntity entity) {
this.manager = manager;
this.entity = entity;
calculateSkillModifier();
}
protected void calculateSkillModifier() {
this.skillModifier = SkillTools.skillCheck(manager.getSkillLevel(), Archery.retrieveMaxBonusLevel);
}
protected void addToTracker() {
Archery.incrementTrackerValue(entity);
}
}

View File

@@ -1,55 +0,0 @@
package com.gmail.nossr50.skills.archery;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Users;
public class DazeEventHandler {
private ArcheryManager manager;
private McMMOPlayer mcMMOPlayer;
private EntityDamageEvent event;
private Player defender;
protected int skillModifier;
protected DazeEventHandler (ArcheryManager manager, EntityDamageEvent event, Player defender) {
this.manager = manager;
this.mcMMOPlayer = manager.getMcMMOPlayer();
this.event = event;
this.defender = defender;
calculateSkillModifier();
}
protected void calculateSkillModifier() {
this.skillModifier = SkillTools.skillCheck(manager.getSkillLevel(), Archery.dazeMaxBonusLevel);
}
protected void handleDazeEffect() {
Location location = defender.getLocation();
location.setPitch(90 - Misc.getRandom().nextInt(181));
defender.teleport(location);
defender.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 20 * 10, 10));
event.setDamage(event.getDamage() + Archery.dazeModifier);
}
protected void sendAbilityMessages() {
if (Users.getPlayer(defender).getProfile().useChatNotifications()) {
defender.sendMessage(LocaleLoader.getString("Combat.TouchedFuzzy"));
}
if (mcMMOPlayer.getProfile().useChatNotifications()) {
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Combat.TargetDazed"));
}
}
}

View File

@@ -1,30 +0,0 @@
package com.gmail.nossr50.skills.archery;
import org.bukkit.event.entity.EntityDamageEvent;
public class SkillShotEventHandler {
private ArcheryManager manager;
private EntityDamageEvent event;
protected double damageBonusPercent;
protected SkillShotEventHandler(ArcheryManager manager, EntityDamageEvent event) {
this.manager = manager;
this.event = event;
}
protected void calculateDamageBonus() {
this.damageBonusPercent = ((manager.getSkillLevel() / Archery.skillShotIncreaseLevel) * Archery.skillShotIncreasePercentage);
if (damageBonusPercent > Archery.skillShotMaxBonusPercentage) {
damageBonusPercent = Archery.skillShotMaxBonusPercentage;
}
}
protected void modifyEventDamage() {
int damage = event.getDamage();
int archeryBonus = (int) (damage * damageBonusPercent);
event.setDamage(damage + archeryBonus);
}
}

View File

@@ -1,6 +1,7 @@
package com.gmail.nossr50.skills.archery;
import org.bukkit.Bukkit;
import java.util.UUID;
import org.bukkit.entity.LivingEntity;
import org.bukkit.scheduler.BukkitScheduler;
@@ -8,34 +9,26 @@ import com.gmail.nossr50.mcMMO;
public class TrackedEntity implements Runnable {
private LivingEntity livingEntity;
private UUID id;
private int arrowCount;
private int previousTicksLived;
private int taskId;
private BukkitScheduler scheduler;
protected TrackedEntity(LivingEntity livingEntity) {
this.livingEntity = livingEntity;
this.scheduler = Bukkit.getScheduler();
this.id = livingEntity.getUniqueId();
this.scheduler = mcMMO.p.getServer().getScheduler();
this.taskId = scheduler.scheduleSyncRepeatingTask(mcMMO.p, this, 12000, 12000);
}
//LivingEntity.isDead() isn't a reliable way to know if an entity is still active
//This method must not be called more than once per server tick
private boolean isActive() {
int currentTicksLived = livingEntity.getTicksLived();
if (currentTicksLived == previousTicksLived) {
return false;
}
previousTicksLived = currentTicksLived;
return true;
}
protected LivingEntity getLivingEntity() {
return livingEntity;
}
protected UUID getID() {
return id;
}
protected int getArrowCount() {
return arrowCount;
}
@@ -46,7 +39,7 @@ public class TrackedEntity implements Runnable {
@Override
public void run() {
if (!isActive()) {
if (!livingEntity.isValid()) {
Archery.removeFromTracker(this);
scheduler.cancelTask(taskId);
}

View File

@@ -1,31 +0,0 @@
package com.gmail.nossr50.skills.axes;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
public class AxeBonusDamageEventHandler {
private int skillLevel;
private EntityDamageByEntityEvent event;
private int damageBonus;
public AxeBonusDamageEventHandler(AxeManager manager, EntityDamageByEntityEvent event) {
this.skillLevel = manager.getSkillLevel();
this.event = event;
}
protected void calculateDamageBonus() {
int increaseLevel = Axes.bonusDamageMaxBonusLevel / Axes.bonusDamageMaxBonus;
/* Add 1 DMG for every 50 skill levels (default value) */
damageBonus = skillLevel / increaseLevel;
if (damageBonus > Axes.bonusDamageMaxBonus) {
damageBonus = Axes.bonusDamageMaxBonus;
}
}
protected void modifyEventDamage() {
int damage = event.getDamage();
event.setDamage(damage + damageBonus);
}
}

View File

@@ -1,67 +1,148 @@
package com.gmail.nossr50.skills.axes;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mods.ModChecks;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.utilities.AbilityType;
import com.gmail.nossr50.skills.utilities.CombatTools;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.skills.utilities.ToolType;
import com.gmail.nossr50.util.ItemChecks;
import com.gmail.nossr50.util.ParticleEffectUtils;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users;
public class AxeManager extends SkillManager {
public AxeManager(McMMOPlayer mcMMOPlayer) {
super(mcMMOPlayer, SkillType.AXES);
}
/**
* Apply bonus to damage done by axes.
*
* @param event The event to modify
*/
public void bonusDamage(EntityDamageByEntityEvent event) {
AxeBonusDamageEventHandler eventHandler = new AxeBonusDamageEventHandler(this, event);
public boolean canUseAxeMastery() {
return Permissions.bonusDamage(getPlayer(), skill);
}
eventHandler.calculateDamageBonus();
eventHandler.modifyEventDamage();
public boolean canCriticalHit(LivingEntity target) {
return target.isValid() && Permissions.criticalStrikes(getPlayer());
}
public boolean canImpact(LivingEntity target) {
return target.isValid() && Permissions.armorImpact(getPlayer()) && Axes.hasArmor(target);
}
public boolean canGreaterImpact(LivingEntity target) {
return target.isValid() && Permissions.greaterImpact(getPlayer()) && !Axes.hasArmor(target);
}
public boolean canUseSkullSplitter(LivingEntity target) {
return target.isValid() && getProfile().getAbilityMode(AbilityType.SKULL_SPLITTER) && Permissions.skullSplitter(getPlayer());
}
public boolean canActivateAbility() {
return getProfile().getToolPreparationMode(ToolType.AXE) && Permissions.skullSplitter(getPlayer());
}
/**
* Check for critical chances on axe damage.
* Handle the effects of the Axe Mastery ability
*
* @param event The event to modify
* @param damage The amount of damage initially dealt by the event
* @return the modified event damage
*/
public void criticalHitCheck(EntityDamageByEntityEvent event, LivingEntity target) {
CriticalHitEventHandler eventHandler = new CriticalHitEventHandler(this, event, target);
public int axeMasteryCheck(int damage) {
int axeBonus = Math.min(getSkillLevel() / (Axes.bonusDamageMaxBonusLevel / Axes.bonusDamageMaxBonus), Axes.bonusDamageMaxBonus);
double chance = (Axes.criticalHitMaxChance / Axes.criticalHitMaxBonusLevel) * eventHandler.skillModifier;
return damage + axeBonus;
}
if (chance > Misc.getRandom().nextInt(activationChance)) {
eventHandler.modifyEventDamage();
eventHandler.sendAbilityMessages();
/**
* Handle the effects of the Critical Hit ability
*
* @param target The {@link LivingEntity} being affected by the ability
* @param damage The amount of damage initially dealt by the event
* @return the modified event damage if the ability was successful, the original event damage otherwise
*/
public int criticalHitCheck(LivingEntity target, int damage) {
Player player = getPlayer();
if (SkillTools.activationSuccessful(player, skill, Axes.criticalHitMaxChance, Axes.criticalHitMaxBonusLevel)) {
player.sendMessage(LocaleLoader.getString("Axes.Combat.CriticalHit"));
if (target instanceof Player) {
((Player) target).sendMessage(LocaleLoader.getString("Axes.Combat.CritStruck"));
return (int) (damage * Axes.criticalHitPVPModifier);
}
return (int) (damage * Axes.criticalHitPVEModifier);
}
return damage;
}
/**
* Handle the effects of the Impact ability
*
* @param target The {@link LivingEntity} being affected by Impact
*/
public void impactCheck(LivingEntity target) {
int durabilityDamage = 1 + (getSkillLevel() / Axes.impactIncreaseLevel);
for (ItemStack armor : target.getEquipment().getArmorContents()) {
if (ItemChecks.isArmor(armor) && SkillTools.activationSuccessful(getPlayer(), skill, Axes.impactChance)) {
double durabilityModifier = 1 / (armor.getEnchantmentLevel(Enchantment.DURABILITY) + 1); // Modifier to simulate the durability enchantment behavior
double modifiedDurabilityDamage = durabilityDamage * durabilityModifier;
double maxDurabilityDamage = (ModChecks.isCustomArmor(armor) ? ModChecks.getArmorFromItemStack(armor).getDurability() : armor.getType().getMaxDurability()) * Axes.impactMaxDurabilityDamageModifier;
armor.setDurability((short) (Math.min(modifiedDurabilityDamage, maxDurabilityDamage) + armor.getDurability()));
}
}
}
/**
* Check for Impact ability.
* Handle the effects of the Greater Impact ability
*
* @param event The event to modify
* @param target The {@link LivingEntity} being affected by the ability
* @param damage The amount of damage initially dealt by the event
* @return the modified event damage if the ability was successful, the original event damage otherwise
*/
public void impact(EntityDamageByEntityEvent event, LivingEntity target) {
ImpactEventHandler eventHandler = new ImpactEventHandler(this, event, target);
public int greaterImpactCheck(LivingEntity target, int damage) {
Player player = getPlayer();
if (!eventHandler.applyImpact()) {
eventHandler.applyGreaterImpact();
if (SkillTools.activationSuccessful(player, skill, Axes.greaterImpactChance)) {
ParticleEffectUtils.playGreaterImpactEffect(target);
target.setVelocity(player.getLocation().getDirection().normalize().multiply(Axes.greaterImpactKnockbackMultiplier));
if (getProfile().useChatNotifications()) {
player.sendMessage(LocaleLoader.getString("Axes.Combat.GI.Proc"));
}
if (target instanceof Player) {
Player defender = (Player) target;
if (Users.getPlayer(defender).getProfile().useChatNotifications()) {
defender.sendMessage(LocaleLoader.getString("Axes.Combat.GI.Struck"));
}
}
return damage + Axes.greaterImpactBonusDamage;
}
return damage;
}
/**
* Check for Skull Splitter ability.
* Handle the effects of the Skull Splitter ability
*
* @param target The entity hit by Skull Splitter
* @param damage The base damage to deal
* @param target The {@link LivingEntity} being affected by the ability
* @param damage The amount of damage initially dealt by the event
*/
public void skullSplitter(LivingEntity target, int damage) {
SkullSplitterEventHandler eventHandler = new SkullSplitterEventHandler(mcMMOPlayer.getPlayer(), damage, target);
eventHandler.applyAbilityEffects();
public void skullSplitterCheck(LivingEntity target, int damage) {
CombatTools.applyAbilityAoE(getPlayer(), target, damage / Axes.skullSplitterModifier, skill);
}
}

View File

@@ -1,6 +1,10 @@
package com.gmail.nossr50.skills.axes;
import org.bukkit.entity.LivingEntity;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.util.ItemChecks;
public class Axes {
public static int bonusDamageMaxBonus = AdvancedConfig.getInstance().getBonusDamageAxesBonusMax();
@@ -12,6 +16,7 @@ public class Axes {
public static double criticalHitPVEModifier = AdvancedConfig.getInstance().getAxesCriticalPVEModifier();
public static int impactIncreaseLevel = AdvancedConfig.getInstance().getArmorImpactIncreaseLevel();
public static double impactChance = AdvancedConfig.getInstance().getImpactChance();
public static double impactMaxDurabilityDamageModifier = AdvancedConfig.getInstance().getArmorImpactMaxDurabilityDamage() / 100D;
public static double greaterImpactChance = AdvancedConfig.getInstance().getGreaterImpactChance();
@@ -19,4 +24,14 @@ public class Axes {
public static int greaterImpactBonusDamage = AdvancedConfig.getInstance().getGreaterImpactBonusDamage();
public static int skullSplitterModifier = AdvancedConfig.getInstance().getSkullSplitterModifier();
protected static boolean hasArmor(LivingEntity target) {
for (ItemStack itemStack : target.getEquipment().getArmorContents()) {
if (ItemChecks.isArmor(itemStack)) {
return true;
}
}
return false;
}
}

View File

@@ -1,61 +0,0 @@
package com.gmail.nossr50.skills.axes;
import org.bukkit.Effect;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.util.Users;
public class CriticalHitEventHandler {
private AxeManager manager;
private EntityDamageByEntityEvent event;
private int damage;
protected LivingEntity defender;
protected int skillModifier;
public CriticalHitEventHandler(AxeManager manager, EntityDamageByEntityEvent event, LivingEntity defender) {
this.manager = manager;
this.event = event;
this.defender = defender;
this.damage = event.getDamage();
calculateSkillModifier();
}
protected void modifyEventDamage() {
if (defender instanceof Player) {
event.setDamage((int) (damage * Axes.criticalHitPVPModifier));
}
else {
event.setDamage((int) (damage * Axes.criticalHitPVEModifier));
}
}
protected void sendAbilityMessages() {
McMMOPlayer mcMMOPlayer = manager.getMcMMOPlayer();
Player attacker = mcMMOPlayer.getPlayer();
attacker.playEffect(defender.getEyeLocation(), Effect.MOBSPAWNER_FLAMES, 0);
if (mcMMOPlayer.getProfile().useChatNotifications()) {
attacker.sendMessage(LocaleLoader.getString("Axes.Combat.CriticalHit"));
}
if (defender instanceof Player) {
Player defendingPlayer = (Player) defender;
if (Users.getPlayer(defendingPlayer).getProfile().useChatNotifications()) {
defendingPlayer.sendMessage(LocaleLoader.getString("Axes.Combat.CritStruck"));
}
}
}
private void calculateSkillModifier() {
this.skillModifier = SkillTools.skillCheck(manager.getSkillLevel(), Axes.criticalHitMaxBonusLevel);
}
}

View File

@@ -1,104 +0,0 @@
package com.gmail.nossr50.skills.axes;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mods.ModChecks;
import com.gmail.nossr50.util.ItemChecks;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.ParticleEffectUtils;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users;
public class ImpactEventHandler {
private AxeManager manager;
private Player player;
private EntityDamageByEntityEvent event;
private short durabilityDamage = 1;
private EntityEquipment entityEquipment;
protected LivingEntity defender;
boolean impactApplied;
public ImpactEventHandler(AxeManager manager, EntityDamageByEntityEvent event, LivingEntity defender) {
this.manager = manager;
this.player = manager.getMcMMOPlayer().getPlayer();
this.event = event;
this.defender = defender;
this.entityEquipment = defender.getEquipment();
}
protected boolean applyImpact() {
// Every 50 Skill Levels you gain 1 durability damage (default values)
durabilityDamage += (short) (manager.getSkillLevel() / Axes.impactIncreaseLevel);
// getArmorContents.length can't be used because it's always equal to 4 (no armor = air block)
boolean hasArmor = false;
for (ItemStack itemStack : entityEquipment.getArmorContents()) {
if (ItemChecks.isArmor(itemStack)) {
hasArmor = true;
if (Misc.getRandom().nextInt(100) < 25) {
damageArmor(itemStack);
}
}
}
return hasArmor;
}
private void damageArmor(ItemStack armor) {
// Modifier simulate the durability enchantment behavior
float modifier = 1;
if (armor.containsEnchantment(Enchantment.DURABILITY)) {
modifier /= armor.getEnchantmentLevel(Enchantment.DURABILITY) + 1;
}
float modifiedDurabilityDamage = durabilityDamage * modifier;
short maxDurabilityDamage = ModChecks.isCustomArmor(armor) ? ModChecks.getArmorFromItemStack(armor).getDurability() : armor.getType().getMaxDurability();
maxDurabilityDamage *= Axes.impactMaxDurabilityDamageModifier;
if (modifiedDurabilityDamage > maxDurabilityDamage) {
modifiedDurabilityDamage = maxDurabilityDamage;
}
armor.setDurability((short) (modifiedDurabilityDamage + armor.getDurability()));
}
protected void applyGreaterImpact() {
if (!Permissions.greaterImpact(player)) {
return;
}
if (Misc.getRandom().nextInt(manager.getActivationChance()) <= Axes.greaterImpactChance) {
handleGreaterImpactEffect();
sendAbilityMessge();
}
}
private void handleGreaterImpactEffect() {
event.setDamage(event.getDamage() + Axes.greaterImpactBonusDamage);
ParticleEffectUtils.playGreaterImpactEffect(defender);
defender.setVelocity(player.getLocation().getDirection().normalize().multiply(Axes.greaterImpactKnockbackMultiplier));
}
private void sendAbilityMessge() {
if (manager.getMcMMOPlayer().getProfile().useChatNotifications()) {
player.sendMessage(LocaleLoader.getString("Axes.Combat.GI.Proc"));
}
if (defender instanceof Player) {
Player defendingPlayer = (Player) defender;
if (Users.getPlayer(defendingPlayer).getProfile().useChatNotifications()) {
defendingPlayer.sendMessage(LocaleLoader.getString("Axes.Combat.GI.Struck"));
}
}
}
}

View File

@@ -1,23 +0,0 @@
package com.gmail.nossr50.skills.axes;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import com.gmail.nossr50.skills.utilities.CombatTools;
import com.gmail.nossr50.skills.utilities.SkillType;
public class SkullSplitterEventHandler {
private Player player;
private LivingEntity target;
private int damage;
protected SkullSplitterEventHandler(Player player, int damage, LivingEntity target) {
this.player = player;
this.target = target;
this.damage = damage;
}
protected void applyAbilityEffects() {
CombatTools.applyAbilityAoE(player, target, damage / Axes.skullSplitterModifier, SkillType.AXES);
}
}

View File

@@ -0,0 +1,60 @@
package com.gmail.nossr50.skills.child;
import java.util.EnumSet;
import java.util.List;
import org.bukkit.configuration.file.YamlConfiguration;
import com.gmail.nossr50.config.AutoUpdateConfigLoader;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.StringUtils;
public class ChildConfig extends AutoUpdateConfigLoader {
public ChildConfig() {
super("child.yml");
loadKeys();
}
@Override
protected void loadKeys() {
config.setDefaults(YamlConfiguration.loadConfiguration(plugin.getResource("child.yml")));
for (SkillType skill : SkillType.values()) {
if (skill.isChildSkill()) {
plugin.debug("Finding parents of " + skill.name());
List<String> parentNames = config.getStringList(StringUtils.getCapitalized(skill.name()));
EnumSet<SkillType> parentSkills = EnumSet.noneOf(SkillType.class);
boolean useDefaults = false; // If we had an error we back out and use defaults
for (String name : parentNames) {
try {
SkillType parentSkill = Enum.valueOf(SkillType.class, name.toUpperCase());
FamilyTree.enforceNotChildSkill(parentSkill);
parentSkills.add(parentSkill);
} catch (IllegalArgumentException ex) {
plugin.getLogger().warning(name + " is not a valid skill type, or is a child skill!");
useDefaults = true;
break;
}
}
if (useDefaults) {
parentSkills.clear();
for (String name : config.getDefaults().getStringList(StringUtils.getCapitalized(skill.name()))) {
/* We do less checks in here because it's from inside our jar.
* If they're dedicated enough to have modified it, they can have the errors it may produce.
* Alternatively, this can be used to allow child skills to be parent skills, provided there are no circular dependencies this is an advanced sort of configuration.
*/
parentSkills.add(SkillType.valueOf(name.toUpperCase()));
}
}
// Register them
for (SkillType parentSkill : parentSkills) {
plugin.debug("Registering " + parentSkill.name() + " as parent of " + skill.name());
FamilyTree.registerParent(skill, parentSkill);
}
}
}
FamilyTree.closeRegistration();
}
}

View File

@@ -0,0 +1,49 @@
package com.gmail.nossr50.skills.child;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Set;
import com.gmail.nossr50.skills.utilities.SkillType;
public class FamilyTree {
private static HashMap<SkillType, Set<SkillType>> tree = new HashMap<SkillType, Set<SkillType>>();
public static Set<SkillType> getParents(SkillType childSkill) {
enforceChildSkill(childSkill);
// We do not check if we have the child skill in question, as not having it would mean we did something wrong, and an NPE is desired.
return tree.get(childSkill);
}
protected static void registerParent(SkillType childSkill, SkillType parentSkill) {
enforceChildSkill(childSkill);
enforceNotChildSkill(parentSkill);
if (!tree.containsKey(childSkill)) {
tree.put(childSkill, EnumSet.noneOf(SkillType.class));
}
tree.get(childSkill).add(parentSkill);
}
protected static void closeRegistration() {
for (SkillType childSkill : tree.keySet()) {
Set<SkillType> immutableSet = Collections.unmodifiableSet(tree.get(childSkill));
tree.put(childSkill, immutableSet);
}
}
protected static void enforceChildSkill(SkillType skill) {
if (!skill.isChildSkill()) {
throw new IllegalArgumentException(skill.name() + " is not a child skill!");
}
}
protected static void enforceNotChildSkill(SkillType skill) {
if (skill.isChildSkill()) {
throw new IllegalArgumentException(skill.name() + " is a child skill!");
}
}
}

View File

@@ -3,99 +3,57 @@ package com.gmail.nossr50.skills.excavation;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.block.BlockState;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.TreasuresConfig;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure;
import com.gmail.nossr50.mods.ModChecks;
import com.gmail.nossr50.skills.utilities.PerksUtils;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
public class Excavation {
/**
* Check to see if treasures were found.
* Get the list of possible {@link ExcavationTreasure|ExcavationTreasures} obtained from a given block.
*
* @param block The block to check
* @param mcMMOPlayer The player who broke the block
* @param blockState The {@link BlockState} of the block to check.
* @return the list of treasures that could be found
*/
public static void excavationProcCheck(Block block, McMMOPlayer mcMMOPlayer) {
Material material = block.getType();
int xp = Config.getInstance().getXp(SkillType.EXCAVATION, material);
protected static List<ExcavationTreasure> getTreasures(BlockState blockState) {
switch (blockState.getType()) {
case DIRT:
return TreasuresConfig.getInstance().excavationFromDirt;
if (xp == 0 && ModChecks.isCustomExcavationBlock(block)) {
xp = ModChecks.getCustomBlock(block).getXpGain();
case GRASS:
return TreasuresConfig.getInstance().excavationFromGrass;
case SAND:
return TreasuresConfig.getInstance().excavationFromSand;
case GRAVEL:
return TreasuresConfig.getInstance().excavationFromGravel;
case CLAY:
return TreasuresConfig.getInstance().excavationFromClay;
case MYCEL:
return TreasuresConfig.getInstance().excavationFromMycel;
case SOUL_SAND:
return TreasuresConfig.getInstance().excavationFromSoulSand;
default:
return new ArrayList<ExcavationTreasure>();
}
Player player = mcMMOPlayer.getPlayer();
List<ExcavationTreasure> treasures = new ArrayList<ExcavationTreasure>();
if (Permissions.excavationTreasureHunter(player)) {
switch (material) {
case DIRT:
treasures = TreasuresConfig.getInstance().excavationFromDirt;
break;
case GRASS:
treasures = TreasuresConfig.getInstance().excavationFromGrass;
break;
case SAND:
treasures = TreasuresConfig.getInstance().excavationFromSand;
break;
case GRAVEL:
treasures = TreasuresConfig.getInstance().excavationFromGravel;
break;
case CLAY:
treasures = TreasuresConfig.getInstance().excavationFromClay;
break;
case MYCEL:
treasures = TreasuresConfig.getInstance().excavationFromMycel;
break;
case SOUL_SAND:
treasures = TreasuresConfig.getInstance().excavationFromSoulSand;
break;
default:
break;
}
Location location = block.getLocation();
for (ExcavationTreasure treasure : treasures) {
if (mcMMOPlayer.getProfile().getSkillLevel(SkillType.EXCAVATION) >= treasure.getDropLevel()) {
int activationChance = PerksUtils.handleLuckyPerks(player, SkillType.EXCAVATION);
if (Misc.getRandom().nextDouble() * activationChance <= treasure.getDropChance()) {
xp += treasure.getXp();
Misc.dropItem(location, treasure.getDrop());
}
}
}
}
mcMMOPlayer.beginXpGain(SkillType.EXCAVATION, xp);
}
/**
* Handle triple drops from Giga Drill Breaker.
*
* @param mcMMOPlayer The player using the ability
* @param block The block to check
*/
public static void gigaDrillBreaker(McMMOPlayer mcMMOPlayer, Block block) {
Excavation.excavationProcCheck(block, mcMMOPlayer);
Excavation.excavationProcCheck(block, mcMMOPlayer);
}
}
protected static int getBlockXP(BlockState blockState) {
int xp = Config.getInstance().getXp(SkillType.EXCAVATION, blockState.getType());
if (xp == 0 && ModChecks.isCustomExcavationBlock(blockState)) {
xp = ModChecks.getCustomBlock(blockState).getXpGain();
}
return xp;
}
}

View File

@@ -0,0 +1,57 @@
package com.gmail.nossr50.skills.excavation;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.block.BlockState;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
public class ExcavationManager extends SkillManager {
public ExcavationManager(McMMOPlayer mcMMOPlayer) {
super(mcMMOPlayer, SkillType.EXCAVATION);
}
/**
* Process treasure drops & XP gain for Excavation.
*
* @param blockState The {@link BlockState} to check ability activation for
*/
public void excavationBlockCheck(BlockState blockState) {
int xp = Excavation.getBlockXP(blockState);
if (Permissions.excavationTreasureHunter(getPlayer())) {
List<ExcavationTreasure> treasures = Excavation.getTreasures(blockState);
if (!treasures.isEmpty()) {
int skillLevel = getSkillLevel();
Location location = blockState.getLocation();
for (ExcavationTreasure treasure : treasures) {
if (skillLevel >= treasure.getDropLevel() && SkillTools.treasureDropSuccessful(treasure.getDropChance(), activationChance)) {
xp += treasure.getXp();
Misc.dropItem(location, treasure.getDrop());
}
}
}
}
applyXpGain(xp);
}
/**
* Process the Giga Drill Breaker ability.
*
* @param blockState The {@link BlockState} to check ability activation for
*/
public void gigaDrillBreaker(BlockState blockState) {
excavationBlockCheck(blockState);
excavationBlockCheck(blockState);
}
}

View File

@@ -1,55 +1,41 @@
package com.gmail.nossr50.skills.fishing;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Item;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.Potion;
import org.bukkit.potion.PotionType;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.TreasuresConfig;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.treasure.FishingTreasure;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.PerksUtils;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.ItemChecks;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
public final class Fishing {
static final AdvancedConfig ADVANCED_CONFIG = AdvancedConfig.getInstance();
// The order of the values is extremely important, a few methods depend on it to work properly
protected enum Tier {
FIVE(5) {
@Override public int getLevel() {return ADVANCED_CONFIG.getFishingTierLevelsTier5();}
@Override public int getShakeChance() {return ADVANCED_CONFIG.getShakeChanceRank5();}
@Override public int getVanillaXPBoostModifier() {return ADVANCED_CONFIG.getFishingVanillaXPModifierRank5();}},
@Override public int getLevel() {return AdvancedConfig.getInstance().getFishingTierLevelsTier5();}
@Override public int getShakeChance() {return AdvancedConfig.getInstance().getShakeChanceRank5();}
@Override public int getVanillaXPBoostModifier() {return AdvancedConfig.getInstance().getFishingVanillaXPModifierRank5();}},
FOUR(4) {
@Override public int getLevel() {return ADVANCED_CONFIG.getFishingTierLevelsTier4();}
@Override public int getShakeChance() {return ADVANCED_CONFIG.getShakeChanceRank4();}
@Override public int getVanillaXPBoostModifier() {return ADVANCED_CONFIG.getFishingVanillaXPModifierRank4();}},
@Override public int getLevel() {return AdvancedConfig.getInstance().getFishingTierLevelsTier4();}
@Override public int getShakeChance() {return AdvancedConfig.getInstance().getShakeChanceRank4();}
@Override public int getVanillaXPBoostModifier() {return AdvancedConfig.getInstance().getFishingVanillaXPModifierRank4();}},
THREE(3) {
@Override public int getLevel() {return ADVANCED_CONFIG.getFishingTierLevelsTier3();}
@Override public int getShakeChance() {return ADVANCED_CONFIG.getShakeChanceRank3();}
@Override public int getVanillaXPBoostModifier() {return ADVANCED_CONFIG.getFishingVanillaXPModifierRank3();}},
@Override public int getLevel() {return AdvancedConfig.getInstance().getFishingTierLevelsTier3();}
@Override public int getShakeChance() {return AdvancedConfig.getInstance().getShakeChanceRank3();}
@Override public int getVanillaXPBoostModifier() {return AdvancedConfig.getInstance().getFishingVanillaXPModifierRank3();}},
TWO(2) {
@Override public int getLevel() {return ADVANCED_CONFIG.getFishingTierLevelsTier2();}
@Override public int getShakeChance() {return ADVANCED_CONFIG.getShakeChanceRank2();}
@Override public int getVanillaXPBoostModifier() {return ADVANCED_CONFIG.getFishingVanillaXPModifierRank2();}},
@Override public int getLevel() {return AdvancedConfig.getInstance().getFishingTierLevelsTier2();}
@Override public int getShakeChance() {return AdvancedConfig.getInstance().getShakeChanceRank2();}
@Override public int getVanillaXPBoostModifier() {return AdvancedConfig.getInstance().getFishingVanillaXPModifierRank2();}},
ONE(1) {
@Override public int getLevel() {return ADVANCED_CONFIG.getFishingTierLevelsTier1();}
@Override public int getShakeChance() {return ADVANCED_CONFIG.getShakeChanceRank1();}
@Override public int getVanillaXPBoostModifier() {return ADVANCED_CONFIG.getFishingVanillaXPModifierRank1();}};
@Override public int getLevel() {return AdvancedConfig.getInstance().getFishingTierLevelsTier1();}
@Override public int getShakeChance() {return AdvancedConfig.getInstance().getShakeChanceRank1();}
@Override public int getVanillaXPBoostModifier() {return AdvancedConfig.getInstance().getFishingVanillaXPModifierRank1();}};
int numerical;
@@ -67,206 +53,149 @@ public final class Fishing {
}
// TODO: Get rid of that
public static int fishermansDietRankLevel1 = ADVANCED_CONFIG.getFishermanDietRankChange();
public static int fishermansDietRankLevel1 = AdvancedConfig.getInstance().getFishermanDietRankChange();
public static int fishermansDietRankLevel2 = fishermansDietRankLevel1 * 2;
public static int fishermansDietMaxLevel = fishermansDietRankLevel1 * 5;
public static final double STORM_MODIFIER = 0.909;
private Fishing() {}
/**
* Begins Fisherman's Diet ability
* Finds the possible drops of an entity
*
* @param player Player using the ability
* @param rankChange ???
* @param event Event to process
* @param target Targeted entity
* @param possibleDrops List of ItemStack that can be dropped
*/
public static void beginFishermansDiet(Player player, int rankChange, FoodLevelChangeEvent event) {
// TODO: The permission should probably not be checked here
// TODO: Also I don't like the idea of moving event around
if (!Permissions.fishermansDiet(player)) {
protected static void findPossibleDrops(LivingEntity target, Map<ItemStack, Integer> possibleDrops) {
switch (target.getType()) {
case BLAZE:
possibleDrops.put(new ItemStack(Material.BLAZE_ROD), 100);
break;
case CAVE_SPIDER:
case SPIDER:
possibleDrops.put(new ItemStack(Material.SPIDER_EYE), 50);
possibleDrops.put(new ItemStack(Material.STRING), 50);
break;
case CHICKEN:
possibleDrops.put(new ItemStack(Material.FEATHER), 34);
possibleDrops.put(new ItemStack(Material.RAW_CHICKEN), 33);
possibleDrops.put(new ItemStack(Material.EGG), 33);
break;
case COW:
possibleDrops.put(new ItemStack(Material.MILK_BUCKET), 2);
possibleDrops.put(new ItemStack(Material.LEATHER), 49);
possibleDrops.put(new ItemStack(Material.RAW_BEEF), 49);
break;
case CREEPER:
possibleDrops.put(new ItemStack(Material.SKULL_ITEM, 1, (short) 4), 1);
possibleDrops.put(new ItemStack(Material.SULPHUR), 99);
break;
case ENDERMAN:
possibleDrops.put(new ItemStack(Material.ENDER_PEARL), 100);
break;
case GHAST:
possibleDrops.put(new ItemStack(Material.SULPHUR), 50);
possibleDrops.put(new ItemStack(Material.GHAST_TEAR), 50);
break;
case IRON_GOLEM:
possibleDrops.put(new ItemStack(Material.PUMPKIN), 3);
possibleDrops.put(new ItemStack(Material.IRON_INGOT), 12);
possibleDrops.put(new ItemStack(Material.RED_ROSE), 85);
break;
case MAGMA_CUBE:
possibleDrops.put(new ItemStack(Material.MAGMA_CREAM), 100);
break;
case MUSHROOM_COW:
possibleDrops.put(new ItemStack(Material.MILK_BUCKET), 5);
possibleDrops.put(new ItemStack(Material.MUSHROOM_SOUP), 5);
possibleDrops.put(new ItemStack(Material.LEATHER), 30);
possibleDrops.put(new ItemStack(Material.RAW_BEEF), 30);
possibleDrops.put(new ItemStack(Material.RED_MUSHROOM, Misc.getRandom().nextInt(3) + 1), 30);
break;
case PIG:
possibleDrops.put(new ItemStack(Material.PORK), 100);
break;
case PIG_ZOMBIE:
possibleDrops.put(new ItemStack(Material.ROTTEN_FLESH), 50);
possibleDrops.put(new ItemStack(Material.GOLD_NUGGET), 50);
break;
case SHEEP:
possibleDrops.put(new ItemStack(Material.WOOL, Misc.getRandom().nextInt(6) + 1), 100);
break;
case SKELETON:
possibleDrops.put(new ItemStack(Material.SKULL_ITEM, 1, (short) 0), 2);
possibleDrops.put(new ItemStack(Material.BONE), 49);
possibleDrops.put(new ItemStack(Material.ARROW, Misc.getRandom().nextInt(3) + 1), 49);
break;
case SLIME:
possibleDrops.put(new ItemStack(Material.SLIME_BALL), 100);
break;
case SNOWMAN:
possibleDrops.put(new ItemStack(Material.PUMPKIN), 3);
possibleDrops.put(new ItemStack(Material.SNOW_BALL, Misc.getRandom().nextInt(4) + 1), 97);
break;
case SQUID:
possibleDrops.put(new ItemStack(Material.INK_SACK, 1, DyeColor.BLACK.getDyeData()), 100);
break;
case WITCH:
possibleDrops.put(new Potion(PotionType.INSTANT_HEAL).toItemStack(1), 1);
possibleDrops.put(new Potion(PotionType.FIRE_RESISTANCE).toItemStack(1), 1);
possibleDrops.put(new Potion(PotionType.SPEED).toItemStack(1), 1);
possibleDrops.put(new ItemStack(Material.GLASS_BOTTLE), 9);
possibleDrops.put(new ItemStack(Material.GLOWSTONE_DUST), 13);
possibleDrops.put(new ItemStack(Material.SULPHUR), 12);
possibleDrops.put(new ItemStack(Material.REDSTONE), 13);
possibleDrops.put(new ItemStack(Material.SPIDER_EYE), 12);
possibleDrops.put(new ItemStack(Material.STICK), 13);
possibleDrops.put(new ItemStack(Material.SUGAR), 12);
possibleDrops.put(new ItemStack(Material.POTION), 13);
break;
case ZOMBIE:
possibleDrops.put(new ItemStack(Material.SKULL_ITEM, 1, (short) 2), 2);
possibleDrops.put(new ItemStack(Material.ROTTEN_FLESH), 98);
break;
default:
return;
}
SkillTools.handleFoodSkills(player, SkillType.FISHING, event, fishermansDietRankLevel1, fishermansDietMaxLevel, rankChange);
}
/**
* Begins Shake Mob ability
* Randomly chooses a drop among the list
*
* @param player Player using the ability
* @param mob Targeted mob
* @param skillLevel Fishing level of the player
* @param possibleDrops List of ItemStack that can be dropped
* @return Chosen ItemStack
*/
public static void beginShakeMob(Player player, LivingEntity mob, int skillLevel) {
ShakeMob.process(player, mob, skillLevel);
protected static ItemStack chooseDrop(Map<ItemStack, Integer> possibleDrops) {
int dropProbability = Misc.getRandom().nextInt(100);
int cumulatedProbability = 0;
for (Entry<ItemStack, Integer> entry : possibleDrops.entrySet()) {
cumulatedProbability += entry.getValue();
if (dropProbability < cumulatedProbability) {
return entry.getKey();
}
}
return null;
}
/**
* Begins Fishing
*
* @param mcMMOPlayer Player fishing
* @param skillLevel Fishing level of the player
* @param event Event to process
*/
public static void beginFishing(McMMOPlayer mcMMOPlayer, int skillLevel, PlayerFishEvent event) {
int treasureXp = 0;
Player player = mcMMOPlayer.getPlayer();
FishingTreasure treasure = checkForTreasure(player, skillLevel);
if (treasure != null) {
player.sendMessage(LocaleLoader.getString("Fishing.ItemFound"));
treasureXp = treasure.getXp();
ItemStack treasureDrop = treasure.getDrop();
if (Permissions.magicHunter(player) && beginMagicHunter(player, skillLevel, treasureDrop, player.getWorld().hasStorm())) {
player.sendMessage(LocaleLoader.getString("Fishing.MagicFound"));
}
// Drop the original catch at the feet of the player and set the treasure as the real catch
Item caught = (Item) event.getCaught();
Misc.dropItem(player.getEyeLocation(), caught.getItemStack());
caught.setItemStack(treasureDrop);
}
mcMMOPlayer.beginXpGain(SkillType.FISHING, Config.getInstance().getFishingBaseXP() + treasureXp);
if (Permissions.vanillaXpBoost(player, SkillType.FISHING)) {
event.setExpToDrop(event.getExpToDrop() * getVanillaXpMultiplier(skillLevel));
}
}
/**
* Checks for treasure
*
* @param player Player fishing
* @param skillLevel Fishing level of the player
* @return Chosen treasure
*/
private static FishingTreasure checkForTreasure(Player player, int skillLevel) {
if (!Config.getInstance().getFishingDropsEnabled() || !Permissions.fishingTreasureHunter(player)) {
return null;
}
List<FishingTreasure> rewards = new ArrayList<FishingTreasure>();
for (FishingTreasure treasure : TreasuresConfig.getInstance().fishingRewards) {
int maxLevel = treasure.getMaxLevel();
if (treasure.getDropLevel() <= skillLevel && (maxLevel >= skillLevel || maxLevel <= 0)) {
rewards.add(treasure);
}
}
if (rewards.isEmpty()) {
return null;
}
FishingTreasure treasure = rewards.get(Misc.getRandom().nextInt(rewards.size()));
ItemStack treasureDrop = treasure.getDrop();
int activationChance = PerksUtils.handleLuckyPerks(player, SkillType.FISHING);
if (Misc.getRandom().nextDouble() * activationChance > treasure.getDropChance()) {
return null;
}
short maxDurability = treasureDrop.getType().getMaxDurability();
if (maxDurability > 0) {
treasureDrop.setDurability((short) (Misc.getRandom().nextInt(maxDurability)));
}
return treasure;
}
/**
* Processes for treasure
*
* @param player Player fishing
* @param skillLevel Fishing level of the player
* @param itemStack ItemStack to enchant
* @param storm World's weather
* @return True if the ItemStack has been enchanted
*/
private static boolean beginMagicHunter(Player player, int skillLevel, ItemStack itemStack, boolean storm) {
if (!ItemChecks.isEnchantable(itemStack)) {
return false;
}
int activationChance = PerksUtils.handleLuckyPerks(player, SkillType.FISHING);
if (storm) {
activationChance = (int) (activationChance * 0.909);
}
if (Misc.getRandom().nextInt(activationChance) > getLootTier(skillLevel) * ADVANCED_CONFIG.getFishingMagicMultiplier()) {
return false;
}
List<Enchantment> possibleEnchantments = new ArrayList<Enchantment>();
for (Enchantment enchantment : Enchantment.values()) {
if (enchantment.canEnchantItem(itemStack)) {
possibleEnchantments.add(enchantment);
}
}
// This make sure that the order isn't always the same, for example previously Unbreaking had a lot more chance to be used than any other enchant
Collections.shuffle(possibleEnchantments, Misc.getRandom());
boolean enchanted = false;
int specificChance = 1;
for (Enchantment possibleEnchantment : possibleEnchantments) {
boolean conflicts = false;
for (Enchantment currentEnchantment : itemStack.getEnchantments().keySet()) {
conflicts = currentEnchantment.conflictsWith(possibleEnchantment);
if (conflicts) {
break;
}
}
if (!conflicts && Misc.getRandom().nextInt(specificChance) == 0) {
itemStack.addEnchantment(possibleEnchantment, Misc.getRandom().nextInt(possibleEnchantment.getMaxLevel()) + 1);
specificChance++;
enchanted = true;
}
}
return enchanted;
}
/**
* Gets the loot tier for a given skill level
*
* @param skillLevel Fishing skill level
* @return Loot tier
*/
public static int getLootTier(int skillLevel) {
for (Tier tier : Tier.values()) {
if (skillLevel >= tier.getLevel()) {
return tier.toNumerical();
}
}
return 0;
}
/**
* Gets the vanilla xp multiplier for a given skill level
*
* @param skillLevel Fishing skill level
* @return Shake Mob probability
*/
public static int getVanillaXpMultiplier(int skillLevel) {
for (Tier tier : Tier.values()) {
if (skillLevel >= tier.getLevel()) {
return tier.getVanillaXPBoostModifier();
}
}
return 0;
}
}

View File

@@ -3,6 +3,7 @@ package com.gmail.nossr50.skills.fishing;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.SkillCommand;
import com.gmail.nossr50.skills.SkillManagerStore;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Permissions;
@@ -26,7 +27,7 @@ public class FishingCommand extends SkillCommand {
@Override
protected void dataCalculations() {
lootTier = Fishing.getLootTier((int) skillValue);
lootTier = SkillManagerStore.getInstance().getFishingManager(player.getName()).getLootTier();
//TREASURE HUNTER
double enchantChance = lootTier * AdvancedConfig.getInstance().getFishingMagicMultiplier();
@@ -41,7 +42,7 @@ public class FishingCommand extends SkillCommand {
magicChanceLucky = treasureHunterStrings[1];
//SHAKE
String[] shakeStrings = calculateAbilityDisplayValues(ShakeMob.getShakeProbability((int) skillValue));
String[] shakeStrings = calculateAbilityDisplayValues(SkillManagerStore.getInstance().getFishingManager(player.getName()).getShakeProbability());
shakeChance = shakeStrings[0];
shakeChanceLucky = shakeStrings[1];

View File

@@ -0,0 +1,305 @@
package com.gmail.nossr50.skills.fishing;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Sheep;
import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Skeleton.SkeletonType;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.TreasuresConfig;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.treasure.FishingTreasure;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.fishing.Fishing.Tier;
import com.gmail.nossr50.skills.utilities.CombatTools;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.ItemChecks;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
public class FishingManager extends SkillManager {
public FishingManager(McMMOPlayer mcMMOPlayer) {
super(mcMMOPlayer, SkillType.FISHING);
}
public boolean canShake(Entity target) {
Player player = getPlayer();
return target instanceof LivingEntity && SkillTools.unlockLevelReached(player, skill, AdvancedConfig.getInstance().getShakeUnlockLevel()) && Permissions.shake(player);
}
/**
* Handle the Fisherman's Diet ability
*
* @param rankChange The # of levels to change rank for the food
* @param eventFoodLevel The initial change in hunger from the event
* @return the modified change in hunger for the event
*/
public int handleFishermanDiet(int rankChange, int eventFoodLevel) {
return SkillTools.handleFoodSkills(getPlayer(), skill, eventFoodLevel, Fishing.fishermansDietRankLevel1, Fishing.fishermansDietMaxLevel, rankChange);
}
/**
* Process the results from a successful fishing trip
*
* @param fishingCatch The {@link Item} initially caught
*/
public void handleFishing(Item fishingCatch) {
int treasureXp = 0;
Player player = getPlayer();
FishingTreasure treasure = null;
if (Config.getInstance().getFishingDropsEnabled() && Permissions.fishingTreasureHunter(player)) {
treasure = getFishingTreasure();
}
if (treasure != null) {
player.sendMessage(LocaleLoader.getString("Fishing.ItemFound"));
treasureXp = treasure.getXp();
ItemStack treasureDrop = treasure.getDrop();
if (Permissions.magicHunter(player) && ItemChecks.isEnchantable(treasureDrop) && handleMagicHunter(treasureDrop)) {
player.sendMessage(LocaleLoader.getString("Fishing.MagicFound"));
}
// Drop the original catch at the feet of the player and set the treasure as the real catch
Misc.dropItem(player.getEyeLocation(), fishingCatch.getItemStack());
fishingCatch.setItemStack(treasureDrop);
}
applyXpGain(Config.getInstance().getFishingBaseXP() + treasureXp);
}
/**
* Handle the vanilla XP boost for Fishing
*
* @param experience The amount of experience initially awarded by the event
* @return the modified event damage
*/
public int handleVanillaXpBoost(int experience) {
return experience * getVanillaXpMultiplier();
}
/**
* Handle the Shake ability
*
* @param mob The {@link LivingEntity} affected by the ability
*/
public void shakeCheck(LivingEntity target) {
if (SkillTools.activationSuccessful(getPlayer(), skill, getShakeProbability())) {
Map<ItemStack, Integer> possibleDrops = new HashMap<ItemStack, Integer>();
Fishing.findPossibleDrops(target, possibleDrops);
if (possibleDrops.isEmpty()) {
return;
}
ItemStack drop = Fishing.chooseDrop(possibleDrops);
// It's possible that chooseDrop returns null if the sum of probability in possibleDrops is inferior than 100
if (drop == null) {
return;
}
// Extra processing depending on the mob and drop type
switch (target.getType()) {
case SHEEP:
Sheep sheep = (Sheep) target;
if (drop.getType() == Material.WOOL) {
if (sheep.isSheared()) {
return;
}
drop.setDurability(sheep.getColor().getWoolData());
sheep.setSheared(true);
}
break;
case SKELETON:
Skeleton skeleton = (Skeleton) target;
if (skeleton.getSkeletonType() == SkeletonType.WITHER) {
switch (drop.getType()) {
case SKULL_ITEM:
drop.setDurability((short) 1);
break;
case ARROW:
drop.setType(Material.COAL);
break;
default:
break;
}
}
break;
default:
break;
}
Misc.dropItem(target.getLocation(), drop);
CombatTools.dealDamage(target, target.getMaxHealth() / 4); // Make it so you can shake a mob no more than 4 times.
}
}
/**
* Process the Treasure Hunter ability for Fishing
*
* @return The {@link FishingTreasure} found, or null if no treasure was found.
*/
private FishingTreasure getFishingTreasure() {
List<FishingTreasure> rewards = new ArrayList<FishingTreasure>();
int skillLevel = getSkillLevel();
for (FishingTreasure treasure : TreasuresConfig.getInstance().fishingRewards) {
int maxLevel = treasure.getMaxLevel();
if (treasure.getDropLevel() <= skillLevel && (maxLevel >= skillLevel || maxLevel <= 0)) {
rewards.add(treasure);
}
}
if (rewards.isEmpty()) {
return null;
}
FishingTreasure treasure = rewards.get(Misc.getRandom().nextInt(rewards.size()));
ItemStack treasureDrop = treasure.getDrop();
if (!SkillTools.treasureDropSuccessful(treasure.getDropChance(), skillLevel)) {
return null;
}
short maxDurability = treasureDrop.getType().getMaxDurability();
if (maxDurability > 0) {
treasureDrop.setDurability((short) (Misc.getRandom().nextInt(maxDurability)));
}
return treasure;
}
/**
* Process the Magic Hunter ability
*
* @param treasureDrop The {@link ItemStack} to enchant
* @return true if the item has been enchanted
*/
private boolean handleMagicHunter(ItemStack treasureDrop) {
Player player = getPlayer();
int activationChance = this.activationChance;
if (player.getWorld().hasStorm()) {
activationChance *= Fishing.STORM_MODIFIER;
}
if (Misc.getRandom().nextInt(activationChance) > getLootTier() * AdvancedConfig.getInstance().getFishingMagicMultiplier()) {
return false;
}
List<Enchantment> possibleEnchantments = new ArrayList<Enchantment>();
for (Enchantment enchantment : Enchantment.values()) {
if (enchantment.canEnchantItem(treasureDrop)) {
possibleEnchantments.add(enchantment);
}
}
// This make sure that the order isn't always the same, for example previously Unbreaking had a lot more chance to be used than any other enchant
Collections.shuffle(possibleEnchantments, Misc.getRandom());
boolean enchanted = false;
int specificChance = 1;
for (Enchantment possibleEnchantment : possibleEnchantments) {
boolean conflicts = false;
for (Enchantment currentEnchantment : treasureDrop.getEnchantments().keySet()) {
conflicts = currentEnchantment.conflictsWith(possibleEnchantment);
if (conflicts) {
break;
}
}
if (!conflicts && Misc.getRandom().nextInt(specificChance) == 0) {
treasureDrop.addEnchantment(possibleEnchantment, Misc.getRandom().nextInt(possibleEnchantment.getMaxLevel()) + 1);
specificChance++;
enchanted = true;
}
}
return enchanted;
}
/**
* Gets the loot tier
*
* @return the loot tier
*/
public int getLootTier() {
int skillLevel = getSkillLevel();
for (Tier tier : Tier.values()) {
if (skillLevel >= tier.getLevel()) {
return tier.toNumerical();
}
}
return 0;
}
/**
* Gets the Shake Mob probability
*
* @return Shake Mob probability
*/
public int getShakeProbability() {
int skillLevel = getSkillLevel();
for (Tier tier : Tier.values()) {
if (skillLevel >= tier.getLevel()) {
return tier.getShakeChance();
}
}
return 0;
}
/**
* Gets the vanilla XP multiplier
*
* @return the vanilla XP multiplier
*/
private int getVanillaXpMultiplier() {
int skillLevel = getSkillLevel();
for (Tier tier : Tier.values()) {
if (skillLevel >= tier.getLevel()) {
return tier.getVanillaXPBoostModifier();
}
}
return 0;
}
}

View File

@@ -1,236 +0,0 @@
package com.gmail.nossr50.skills.fishing;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Sheep;
import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Skeleton.SkeletonType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Wool;
import org.bukkit.potion.Potion;
import org.bukkit.potion.PotionType;
import com.gmail.nossr50.skills.fishing.Fishing.Tier;
import com.gmail.nossr50.skills.utilities.CombatTools;
import com.gmail.nossr50.skills.utilities.PerksUtils;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Misc;
public final class ShakeMob {
private ShakeMob() {}
/**
* Begins Tree Feller
*
* @param player Player using Shake Mob
* @param mob Targeted entity
* @param skillLevel Fishing level of the player
*/
public static void process(Player player, LivingEntity mob, int skillLevel) {
int activationChance = PerksUtils.handleLuckyPerks(player, SkillType.FISHING);
if (getShakeProbability(skillLevel) <= Misc.getRandom().nextInt(activationChance)) {
return;
}
Map<ItemStack, Integer> possibleDrops = new HashMap<ItemStack, Integer>();
findPossibleDrops(mob, possibleDrops);
if (possibleDrops.isEmpty()) {
return;
}
ItemStack drop = chooseDrop(possibleDrops);
// It's possible that chooseDrop returns null if the sum of probability in possibleDrops is inferior than 100
if (drop == null) {
return;
}
// Extra processing depending on the mob and drop type
switch (mob.getType()) {
case SHEEP:
Sheep sheep = (Sheep) mob;
if (drop.getType() == Material.WOOL) {
if (sheep.isSheared()) {
return;
}
// TODO: Find a cleaner way to do this, maybe by using Sheep.getColor().getWoolData() (available since 1.4.7-R0.1)
Wool wool = (Wool) drop.getData();
wool.setColor(sheep.getColor());
drop.setDurability(wool.getData());
sheep.setSheared(true);
}
break;
case SKELETON:
Skeleton skeleton = (Skeleton) mob;
if (skeleton.getSkeletonType() == SkeletonType.WITHER) {
switch (drop.getType()) {
case SKULL_ITEM:
drop.setDurability((short) 1);
break;
case ARROW:
drop.setType(Material.COAL);
break;
default:
break;
}
}
break;
default:
break;
}
Misc.dropItem(mob.getLocation(), drop);
CombatTools.dealDamage(mob, 1); // We may want to base the damage on the entity max health
}
/**
* Finds the possible drops of an entity
*
* @param mob Targeted entity
* @param possibleDrops List of ItemStack that can be dropped
*/
private static void findPossibleDrops(LivingEntity mob, Map<ItemStack, Integer> possibleDrops) {
switch (mob.getType()) {
case BLAZE:
possibleDrops.put(new ItemStack(Material.BLAZE_ROD), 100);
break;
case CAVE_SPIDER:
case SPIDER:
possibleDrops.put(new ItemStack(Material.SPIDER_EYE), 50);
possibleDrops.put(new ItemStack(Material.STRING), 50);
break;
case CHICKEN:
possibleDrops.put(new ItemStack(Material.FEATHER), 34);
possibleDrops.put(new ItemStack(Material.RAW_CHICKEN), 33);
possibleDrops.put(new ItemStack(Material.EGG), 33);
break;
case COW:
possibleDrops.put(new ItemStack(Material.MILK_BUCKET), 2);
possibleDrops.put(new ItemStack(Material.LEATHER), 49);
possibleDrops.put(new ItemStack(Material.RAW_BEEF), 49);
break;
case CREEPER:
possibleDrops.put(new ItemStack(Material.SKULL_ITEM, 1, (short) 4), 1);
possibleDrops.put(new ItemStack(Material.SULPHUR), 99);
break;
case ENDERMAN:
possibleDrops.put(new ItemStack(Material.ENDER_PEARL), 100);
break;
case GHAST:
possibleDrops.put(new ItemStack(Material.SULPHUR), 50);
possibleDrops.put(new ItemStack(Material.GHAST_TEAR), 50);
break;
case IRON_GOLEM:
possibleDrops.put(new ItemStack(Material.PUMPKIN), 3);
possibleDrops.put(new ItemStack(Material.IRON_INGOT), 12);
possibleDrops.put(new ItemStack(Material.RED_ROSE), 85);
break;
case MAGMA_CUBE:
possibleDrops.put(new ItemStack(Material.MAGMA_CREAM), 100);
break;
case MUSHROOM_COW:
possibleDrops.put(new ItemStack(Material.MILK_BUCKET), 5);
possibleDrops.put(new ItemStack(Material.MUSHROOM_SOUP), 5);
possibleDrops.put(new ItemStack(Material.LEATHER), 30);
possibleDrops.put(new ItemStack(Material.RAW_BEEF), 30);
possibleDrops.put(new ItemStack(Material.RED_MUSHROOM, Misc.getRandom().nextInt(3) + 1), 30);
break;
case PIG:
possibleDrops.put(new ItemStack(Material.PORK), 100);
break;
case PIG_ZOMBIE:
possibleDrops.put(new ItemStack(Material.ROTTEN_FLESH), 50);
possibleDrops.put(new ItemStack(Material.GOLD_NUGGET), 50);
break;
case SHEEP:
possibleDrops.put(new ItemStack(Material.WOOL, Misc.getRandom().nextInt(6) + 1), 100);
break;
case SKELETON:
possibleDrops.put(new ItemStack(Material.SKULL_ITEM, 1, (short) 0), 2);
possibleDrops.put(new ItemStack(Material.BONE), 49);
possibleDrops.put(new ItemStack(Material.ARROW, Misc.getRandom().nextInt(3) + 1), 49);
break;
case SLIME:
possibleDrops.put(new ItemStack(Material.SLIME_BALL), 100);
break;
case SNOWMAN:
possibleDrops.put(new ItemStack(Material.PUMPKIN), 3);
possibleDrops.put(new ItemStack(Material.SNOW_BALL, Misc.getRandom().nextInt(4) + 1), 97);
break;
case SQUID:
possibleDrops.put(new ItemStack(Material.INK_SACK, 1, DyeColor.BLACK.getDyeData()), 100);
break;
case WITCH:
possibleDrops.put(new Potion(PotionType.INSTANT_HEAL).toItemStack(1), 1);
possibleDrops.put(new Potion(PotionType.FIRE_RESISTANCE).toItemStack(1), 1);
possibleDrops.put(new Potion(PotionType.SPEED).toItemStack(1), 1);
possibleDrops.put(new ItemStack(Material.GLASS_BOTTLE), 9);
possibleDrops.put(new ItemStack(Material.GLOWSTONE_DUST), 13);
possibleDrops.put(new ItemStack(Material.SULPHUR), 12);
possibleDrops.put(new ItemStack(Material.REDSTONE), 13);
possibleDrops.put(new ItemStack(Material.SPIDER_EYE), 12);
possibleDrops.put(new ItemStack(Material.STICK), 13);
possibleDrops.put(new ItemStack(Material.SUGAR), 12);
possibleDrops.put(new ItemStack(Material.POTION), 13);
break;
case ZOMBIE:
possibleDrops.put(new ItemStack(Material.SKULL_ITEM, 1, (short) 2), 2);
possibleDrops.put(new ItemStack(Material.ROTTEN_FLESH), 98);
break;
default:
return;
}
}
/**
* Randomly chooses a drop among the list
*
* @param possibleDrops List of ItemStack that can be dropped
* @return Chosen ItemStack
*/
private static ItemStack chooseDrop(Map<ItemStack, Integer> possibleDrops) {
int dropProbability = Misc.getRandom().nextInt(100);
int cumulatedProbability = 0;
for (Entry<ItemStack, Integer> entry : possibleDrops.entrySet()) {
cumulatedProbability += entry.getValue();
if (dropProbability < cumulatedProbability) {
return entry.getKey();
}
}
return null;
}
/**
* Gets the Shake Mob probability for a given skill level
*
* @param skillLevel Fishing skill level
* @return Shake Mob probability
*/
public static int getShakeProbability(int skillLevel) {
for (Tier tier : Tier.values()) {
if (skillLevel >= tier.getLevel()) {
return tier.getShakeChance();
}
}
return 0;
}
}

View File

@@ -0,0 +1,46 @@
package com.gmail.nossr50.skills.herbalism;
import org.bukkit.CropState;
import org.bukkit.block.BlockState;
import org.bukkit.material.CocoaPlant;
import org.bukkit.material.CocoaPlant.CocoaPlantSize;
/**
* Convert plants affected by the Green Terra ability.
*
* @param blockState The {@link BlockState} to check ability activation for
*/
public class GreenTerraTimer implements Runnable {
private BlockState blockState;
public GreenTerraTimer(BlockState blockState) {
this.blockState = blockState;
}
@Override
public void run() {
switch (blockState.getType()) {
case CROPS:
case CARROT:
case POTATO:
blockState.setRawData(CropState.MEDIUM.getData());
blockState.update(true);
return;
case NETHER_WARTS:
blockState.setRawData((byte) 0x2);
blockState.update(true);
return;
case COCOA:
CocoaPlant plant = (CocoaPlant) blockState.getData();
plant.setSize(CocoaPlantSize.MEDIUM);
blockState.setData(plant);
blockState.update(true);
return;
default:
return;
}
}
}

View File

@@ -1,86 +1,64 @@
package com.gmail.nossr50.skills.herbalism;
import org.bukkit.CropState;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.material.CocoaPlant;
import org.bukkit.material.CocoaPlant.CocoaPlantSize;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.skills.utilities.AbilityType;
import com.gmail.nossr50.skills.utilities.SkillType;
/**
* Convert plants affected by the Green Thumb ability.
*
* @param blockState The {@link BlockState} to check ability activation for
* @param skillLevel The player's Herbalism skill level
*/
public class GreenThumbTimer implements Runnable {
private Block block;
private PlayerProfile profile;
private Material type;
private BlockState blockState;
private int skillLevel;
public GreenThumbTimer(Block block, PlayerProfile profile, Material material) {
this.block = block;
this.profile = profile;
this.type = material;
public GreenThumbTimer(BlockState blockState, int skillLevel) {
this.blockState = blockState;
this.skillLevel = skillLevel;
}
@Override
public void run() {
this.block.setType(this.type);
int greenThumbStage = Math.min(Math.min(skillLevel, Herbalism.greenThumbStageMaxLevel) / Herbalism.greenThumbStageChangeLevel, 4);
int skillLevel = this.profile.getSkillLevel(SkillType.HERBALISM);
int greenThumbStage = skillLevel / Herbalism.greenThumbStageChangeLevel;
if (greenThumbStage > 4) {
greenThumbStage = 4;
}
switch(this.type) {
switch(blockState.getType()) {
case CROPS:
case CARROT:
case POTATO:
//This replants the wheat at a certain stage in development based on Herbalism Skill
if (!this.profile.getAbilityMode(AbilityType.GREEN_TERRA)) {
this.block.setData((byte) greenThumbStage);
}
else {
this.block.setData(CropState.MEDIUM.getData());
}
break;
case NETHER_WARTS:
if (!this.profile.getAbilityMode(AbilityType.GREEN_TERRA)) {
if (greenThumbStage == 3) {
this.block.setData((byte) 0x2);
}
else if (greenThumbStage == 2) {
this.block.setData((byte) 0x1);
}
else {
this.block.setData((byte) 0x0);
}
}
else {
this.block.setData((byte) 0x2);
}
break;
case COCOA:
CocoaPlant plant = (CocoaPlant) block.getState().getData();
blockState.setRawData((byte) greenThumbStage);
blockState.update(true);
return;
if (!this.profile.getAbilityMode(AbilityType.GREEN_TERRA)) {
if (greenThumbStage == 3) {
plant.setSize(CocoaPlantSize.MEDIUM);
}
else if (greenThumbStage == 2) {
plant.setSize(CocoaPlantSize.MEDIUM);
}
else {
plant.setSize(CocoaPlantSize.SMALL);
}
case NETHER_WARTS:
if (greenThumbStage > 2) {
blockState.setRawData((byte) 0x2);
}
else if (greenThumbStage == 2) {
blockState.setRawData((byte) 0x1);
}
else {
blockState.setRawData((byte) 0x0);
}
blockState.update(true);
return;
case COCOA:
CocoaPlant plant = (CocoaPlant) blockState.getData();
if (greenThumbStage > 1) {
plant.setSize(CocoaPlantSize.MEDIUM);
}
block.setData(plant.getData());
break;
else {
plant.setSize(CocoaPlantSize.SMALL);
}
blockState.setData(plant);
blockState.update(true);
return;
default:
break;
return;
}
}
}

View File

@@ -1,36 +1,12 @@
package com.gmail.nossr50.skills.herbalism;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.block.BlockState;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.TreasuresConfig;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.treasure.HylianTreasure;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mods.ModChecks;
import com.gmail.nossr50.mods.datatypes.CustomBlock;
import com.gmail.nossr50.skills.utilities.AbilityType;
import com.gmail.nossr50.skills.utilities.PerksUtils;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users;
public class Herbalism {
public static int farmersDietRankLevel1 = AdvancedConfig.getInstance().getFarmerDietRankChange();
@@ -49,79 +25,62 @@ public class Herbalism {
public static double hylianLuckMaxChance = AdvancedConfig.getInstance().getHylianLuckChanceMax();
public static int hylianLuckMaxLevel = AdvancedConfig.getInstance().getHylianLuckMaxLevel();
/**
* Handle the farmers diet skill.
*
* @param player The player to activate the skill for
* @param rankChange The # of levels to change rank for the food
* @param event The actual FoodLevelChange event
*/
public static void farmersDiet(Player player, int rankChange, FoodLevelChangeEvent event) {
if (!Permissions.farmersDiet(player)) {
return;
}
public static double shroomThumbMaxChance = AdvancedConfig.getInstance().getShroomThumbChanceMax();
public static int shroomThumbMaxLevel = AdvancedConfig.getInstance().getShroomThumbMaxLevel();
SkillTools.handleFoodSkills(player, SkillType.HERBALISM, event, farmersDietRankLevel1, farmersDietMaxLevel, rankChange);
/**
* Convert blocks affected by the Green Thumb & Green Terra abilities.
*
* @param blockState The {@link BlockState} to check ability activation for
* @return true if the ability was successful, false otherwise
*/
protected static boolean convertGreenTerraBlocks(BlockState blockState) {
switch (blockState.getType()) {
case COBBLE_WALL:
case SMOOTH_BRICK:
blockState.setRawData((byte) 0x1);
return true;
case DIRT:
blockState.setType(Material.GRASS);
return true;
case COBBLESTONE:
blockState.setType(Material.MOSSY_COBBLESTONE);
return true;
default:
return false;
}
}
/**
* Activate the Green Terra ability.
* Calculate the drop amounts for cacti & sugar cane based on the blocks above them.
*
* @param player The player activating the ability
* @param block The block to be changed by Green Terra
* @param blockState The {@link BlockState} of the bottom block of the plant
* @return the number of bonus drops to award from the blocks in this plant
*/
public static void greenTerra(Player player, Block block) {
PlayerInventory inventory = player.getInventory();
boolean hasSeeds = inventory.contains(Material.SEEDS);
if (!hasSeeds) {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTe.NeedMore"));
return;
}
inventory.removeItem(new ItemStack(Material.SEEDS));
player.updateInventory(); // Needed until replacement available
greenTerraConvert(player, block);
}
public static void greenTerraConvert(Player player, Block block) {
if (SkillTools.blockBreakSimulate(block, player, false)) {
Material type = block.getType();
if (!Permissions.greenThumbBlock(player, type)) {
return;
}
switch (type) {
case SMOOTH_BRICK:
block.setData((byte) 0x1);
return;
case DIRT:
block.setType(Material.GRASS);
return;
case COBBLESTONE:
block.setType(Material.MOSSY_COBBLESTONE);
return;
case COBBLE_WALL:
block.setData((byte) 0x1);
return;
default:
return;
}
}
}
private static int calculateCatciAndSugarDrops(Block block) {
Material blockType = block.getType();
protected static int calculateCatciAndSugarDrops(BlockState blockState) {
Block block = blockState.getBlock();
Material blockType = blockState.getType();
int dropAmount = 0;
for (int y = 0; y <= 2; y++) {
// Handle the original block
if (!mcMMO.placeStore.isTrue(blockState)) {
dropAmount++;
}
// Handle the two blocks above it - cacti & sugar cane can only grow 3 high naturally
for (int y = 1; y < 3; y++) {
Block relativeBlock = block.getRelative(BlockFace.UP, y);
if (relativeBlock.getType() == blockType && !mcMMO.placeStore.isTrue(relativeBlock)) {
Material relativeBlockType = relativeBlock.getType();
// If the first one is air, so is the next one
if (relativeBlockType == Material.AIR) {
break;
}
if (relativeBlockType == blockType && !mcMMO.placeStore.isTrue(relativeBlock)) {
dropAmount++;
}
}
@@ -130,223 +89,20 @@ public class Herbalism {
}
/**
* Check for extra Herbalism drops.
* Convert blocks affected by the Green Thumb & Green Terra abilities.
*
* @param block The block to check for extra drops
* @param mcMMOPlayer The player getting extra drops
* @param event The event to use for Green Thumb
* @param plugin mcMMO plugin instance
* @param blockState The {@link BlockState} to check ability activation for
* @return true if the ability was successful, false otherwise
*/
public static void herbalismProcCheck(final Block block, McMMOPlayer mcMMOPlayer, mcMMO plugin) {
Player player = mcMMOPlayer.getPlayer();
protected static boolean convertShroomThumb(BlockState blockState) {
switch (blockState.getType()){
case DIRT:
case GRASS:
blockState.setType(Material.MYCEL);
return true;
if (Config.getInstance().getHerbalismAFKDisabled() && player.isInsideVehicle()) {
return;
}
PlayerProfile profile = mcMMOPlayer.getProfile();
int herbLevel = profile.getSkillLevel(SkillType.HERBALISM);
Material blockType = block.getType();
HerbalismBlock herbalismBlock = HerbalismBlock.getHerbalismBlock(blockType);
CustomBlock customBlock = null;
int xp = 0;
int dropAmount = 1;
ItemStack dropItem = null;
if (herbalismBlock != null) {
if (blockType == Material.CACTUS || blockType == Material.SUGAR_CANE_BLOCK) {
dropItem = herbalismBlock.getDropItem();
dropAmount = calculateCatciAndSugarDrops(block);
xp = herbalismBlock.getXpGain() * dropAmount;
}
else if (herbalismBlock.hasGreenThumbPermission(player)){
dropItem = herbalismBlock.getDropItem();
xp = herbalismBlock.getXpGain();
greenThumbWheat(block, player, plugin);
}
else {
if (!mcMMO.placeStore.isTrue(block)) {
dropItem = herbalismBlock.getDropItem();
xp = herbalismBlock.getXpGain();
}
}
}
else {
customBlock = ModChecks.getCustomBlock(block);
dropItem = customBlock.getItemDrop();
xp = customBlock.getXpGain();
}
if (Permissions.doubleDrops(player, SkillType.HERBALISM)) {
int activationChance = PerksUtils.handleLuckyPerks(player, SkillType.HERBALISM);
double chance = (doubleDropsMaxChance / doubleDropsMaxLevel) * SkillTools.skillCheck(herbLevel, doubleDropsMaxLevel);
if (chance > Misc.getRandom().nextInt(activationChance)) {
Location location = block.getLocation();
if (dropItem != null && herbalismBlock != null && herbalismBlock.canDoubleDrop()) {
Misc.dropItems(location, dropItem, dropAmount);
}
else if (customBlock != null){
int minimumDropAmount = customBlock.getMinimumDropAmount();
int maximumDropAmount = customBlock.getMaximumDropAmount();
if (minimumDropAmount != maximumDropAmount) {
Misc.randomDropItems(location, dropItem, maximumDropAmount - minimumDropAmount);
}
Misc.dropItems(location, dropItem, minimumDropAmount);
}
}
}
mcMMOPlayer.beginXpGain(SkillType.HERBALISM, xp);
}
/**
* Apply the Green Thumb ability to crops.
*
* @param block The block to apply the ability to
* @param player The player using the ability
* @param event The event triggering the ability
* @param plugin mcMMO plugin instance
*/
private static void greenThumbWheat(Block block, Player player, mcMMO plugin) {
PlayerProfile profile = Users.getPlayer(player).getProfile();
int herbLevel = profile.getSkillLevel(SkillType.HERBALISM);
PlayerInventory inventory = player.getInventory();
boolean hasSeeds = false;
Material type = block.getType();
switch(type) {
case CROPS:
hasSeeds = inventory.contains(Material.SEEDS);
break;
case COCOA:
hasSeeds = inventory.containsAtLeast(new ItemStack(Material.INK_SACK, 1, DyeColor.BROWN.getDyeData()), 1);
break;
case CARROT:
hasSeeds = inventory.contains(Material.CARROT_ITEM);
break;
case POTATO:
hasSeeds = inventory.contains(Material.POTATO_ITEM);
break;
case NETHER_WARTS:
hasSeeds = inventory.contains(Material.NETHER_STALK);
break;
default:
break;
}
if (!hasSeeds) {
return;
}
int activationChance = PerksUtils.handleLuckyPerks(player, SkillType.HERBALISM);
float chance = (float) (greenThumbMaxChance / greenThumbMaxLevel * herbLevel);
if (chance > greenThumbMaxChance) {
chance = (float) greenThumbMaxChance;
}
if (profile.getAbilityMode(AbilityType.GREEN_TERRA) || chance > Misc.getRandom().nextInt(activationChance)) {
switch(type) {
case CROPS:
inventory.removeItem(new ItemStack(Material.SEEDS));
break;
case COCOA:
inventory.removeItem(new ItemStack(Material.INK_SACK, 1, DyeColor.BROWN.getDyeData()));
break;
case CARROT:
inventory.removeItem(new ItemStack(Material.CARROT_ITEM));
break;
case POTATO:
inventory.removeItem(new ItemStack(Material.POTATO_ITEM));
break;
case NETHER_WARTS:
inventory.removeItem(new ItemStack(Material.NETHER_STALK));
break;
default:
break;
}
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new GreenThumbTimer(block, profile, type), 0);
player.updateInventory(); // Needed until replacement available
}
}
/**
* Apply the Green Thumb ability to blocks.
*
* @param is The item in the player's hand
* @param player The player activating the ability
* @param block The block being used in the ability
*/
public static void greenThumbBlocks(ItemStack is, Player player, Block block) {
PlayerProfile profile = Users.getPlayer(player).getProfile();
int skillLevel = profile.getSkillLevel(SkillType.HERBALISM);
int seeds = is.getAmount();
player.setItemInHand(new ItemStack(Material.SEEDS, seeds - 1));
int activationChance = PerksUtils.handleLuckyPerks(player, SkillType.HERBALISM);
float chance = (float) ((greenThumbMaxChance / greenThumbMaxLevel) * skillLevel);
if (chance > greenThumbMaxChance) chance = (float) greenThumbMaxChance;
if (chance > Misc.getRandom().nextInt(activationChance)) {
greenTerraConvert(player, block);
}
else {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTh.Fail"));
}
}
public static void hylianLuck(Block block, Player player, BlockBreakEvent event) {
int skillLevel = Users.getPlayer(player).getProfile().getSkillLevel(SkillType.HERBALISM);
double chance = (hylianLuckMaxChance / hylianLuckMaxLevel) * SkillTools.skillCheck(skillLevel, hylianLuckMaxLevel);
int activationChance = PerksUtils.handleLuckyPerks(player, SkillType.HERBALISM);
if (chance > Misc.getRandom().nextInt(activationChance)) {
List<HylianTreasure> treasures = new ArrayList<HylianTreasure>();
switch (block.getType()) {
case DEAD_BUSH:
case LONG_GRASS:
case SAPLING:
treasures = TreasuresConfig.getInstance().hylianFromBushes;
break;
case RED_ROSE:
case YELLOW_FLOWER:
if (mcMMO.placeStore.isTrue(block)) {
mcMMO.placeStore.setFalse(block);
return;
}
treasures = TreasuresConfig.getInstance().hylianFromFlowers;
break;
case FLOWER_POT:
treasures = TreasuresConfig.getInstance().hylianFromPots;
break;
default:
return;
}
if (treasures.isEmpty()) {
return;
}
event.setCancelled(true);
event.getBlock().setType(Material.AIR);
Misc.dropItem(block.getLocation(), treasures.get(Misc.getRandom().nextInt(treasures.size())).getDrop());
player.sendMessage(LocaleLoader.getString("Herbalism.HylianLuck"));
return false;
}
}
}

View File

@@ -18,6 +18,8 @@ public class HerbalismCommand extends SkillCommand {
private String doubleDropChanceLucky;
private String hylianLuckChance;
private String hylianLuckChanceLucky;
private String shroomThumbChance;
private String shroomThumbChanceLucky;
private boolean hasHylianLuck;
private boolean canGreenTerra;
@@ -25,6 +27,7 @@ public class HerbalismCommand extends SkillCommand {
private boolean canGreenThumbBlocks;
private boolean canFarmersDiet;
private boolean canDoubleDrop;
private boolean canShroomThumb;
private boolean doubleDropsDisabled;
public HerbalismCommand() {
@@ -57,6 +60,11 @@ public class HerbalismCommand extends SkillCommand {
String[] hylianLuckStrings = calculateAbilityDisplayValues(Herbalism.hylianLuckMaxLevel, Herbalism.hylianLuckMaxChance);
hylianLuckChance = hylianLuckStrings[0];
hylianLuckChanceLucky = hylianLuckStrings[1];
//SHROOM THUMB
String[] shroomThumbStrings = calculateAbilityDisplayValues(Herbalism.shroomThumbMaxLevel, Herbalism.shroomThumbMaxChance);
shroomThumbChance = shroomThumbStrings[0];
shroomThumbChanceLucky = shroomThumbStrings[1];
}
@Override
@@ -68,11 +76,12 @@ public class HerbalismCommand extends SkillCommand {
canFarmersDiet = Permissions.farmersDiet(player);
canDoubleDrop = Permissions.doubleDrops(player, skill);
doubleDropsDisabled = skill.getDoubleDropsDisabled();
canShroomThumb = Permissions.shroomThumb(player);
}
@Override
protected boolean effectsHeaderPermissions() {
return canGreenTerra || (canDoubleDrop && !doubleDropsDisabled) || canFarmersDiet || canGreenThumbBlocks || canGreenThumbWheat;
return canGreenTerra || (canDoubleDrop && !doubleDropsDisabled) || canFarmersDiet || canGreenThumbBlocks || canGreenThumbWheat || canShroomThumb;
}
@Override
@@ -99,6 +108,10 @@ public class HerbalismCommand extends SkillCommand {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.10"), LocaleLoader.getString("Herbalism.Effect.11")));
}
if (canShroomThumb) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.12"), LocaleLoader.getString("Herbalism.Effect.13")));
}
if (canDoubleDrop && !doubleDropsDisabled) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.8"), LocaleLoader.getString("Herbalism.Effect.9")));
}
@@ -106,7 +119,7 @@ public class HerbalismCommand extends SkillCommand {
@Override
protected boolean statsHeaderPermissions() {
return canGreenTerra || (canDoubleDrop && !doubleDropsDisabled) || canFarmersDiet || canGreenThumbBlocks || canGreenThumbWheat;
return canGreenTerra || (canDoubleDrop && !doubleDropsDisabled) || canFarmersDiet || canGreenThumbBlocks || canGreenThumbWheat || canShroomThumb;
}
@Override
@@ -145,6 +158,16 @@ public class HerbalismCommand extends SkillCommand {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.HylianLuck", hylianLuckChance));
}
}
if (canShroomThumb) {
if (isLucky) {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.ShroomThumb.Chance", shroomThumbChance) + LocaleLoader.getString("Perks.lucky.bonus", shroomThumbChanceLucky));
}
else {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.ShroomThumb.Chance", shroomThumbChance));
}
}
if (canDoubleDrop && !doubleDropsDisabled) {
if (isLucky) {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.DoubleDropChance", doubleDropChance) + LocaleLoader.getString("Perks.lucky.bonus", doubleDropChanceLucky));

View File

@@ -0,0 +1,306 @@
package com.gmail.nossr50.skills.herbalism;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.TreasuresConfig;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.treasure.HylianTreasure;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mods.ModChecks;
import com.gmail.nossr50.mods.datatypes.CustomBlock;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.utilities.AbilityType;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.skills.utilities.ToolType;
import com.gmail.nossr50.util.BlockChecks;
import com.gmail.nossr50.util.ItemChecks;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.Users;
public class HerbalismManager extends SkillManager {
public HerbalismManager(McMMOPlayer mcMMOPlayer) {
super(mcMMOPlayer, SkillType.HERBALISM);
}
public boolean canBlockCheck() {
return !(Config.getInstance().getHerbalismAFKDisabled() && getPlayer().isInsideVehicle());
}
public boolean canGreenThumbBlock(BlockState blockState) {
Player player = getPlayer();
return player.getItemInHand().getType() == Material.SEEDS && BlockChecks.canMakeMossy(blockState) && Permissions.greenThumbBlock(player, blockState.getType());
}
public boolean canUseShroomThumb(BlockState blockState) {
Player player = getPlayer();
Material itemType = player.getItemInHand().getType();
return (itemType == Material.RED_MUSHROOM || itemType == Material.BROWN_MUSHROOM) && BlockChecks.canMakeShroomy(blockState) && Permissions.shroomThumb(player);
}
public boolean canUseHylianLuck() {
Player player = getPlayer();
return ItemChecks.isSword(player.getItemInHand()) && Permissions.hylianLuck(player);
}
public boolean canGreenTerraBlock(BlockState blockState) {
return getProfile().getAbilityMode(AbilityType.GREEN_TERRA) && BlockChecks.canMakeMossy(blockState);
}
public boolean canActivateAbility() {
return getProfile().getToolPreparationMode(ToolType.HOE) && Permissions.greenTerra(getPlayer());
}
public boolean canGreenTerraPlant() {
return getProfile().getAbilityMode(AbilityType.GREEN_TERRA);
}
/**
* Handle the Farmer's Diet ability
*
* @param rankChange The # of levels to change rank for the food
* @param eventFoodLevel The initial change in hunger from the event
* @return the modified change in hunger for the event
*/
public int farmersDiet(int rankChange, int eventFoodLevel) {
return SkillTools.handleFoodSkills(getPlayer(), SkillType.HERBALISM, eventFoodLevel, Herbalism.farmersDietRankLevel1, Herbalism.farmersDietMaxLevel, rankChange);
}
/**
* Process the Green Terra ability.
*
* @param blockState The {@link BlockState} to check ability activation for
* @return true if the ability was successful, false otherwise
*/
public boolean processGreenTerra(BlockState blockState) {
Player player = getPlayer();
if (!Permissions.greenThumbBlock(player, blockState.getType())) {
return false;
}
PlayerInventory playerInventory = player.getInventory();
ItemStack seed = new ItemStack(Material.SEEDS);
if (!playerInventory.containsAtLeast(seed, 1)) {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTe.NeedMore"));
return false;
}
playerInventory.removeItem(seed);
player.updateInventory(); // Needed until replacement available
return Herbalism.convertGreenTerraBlocks(blockState);
}
/**
* Process double drops & XP gain for Herbalism.
*
* @param blockState The {@link BlockState} to check ability activation for
* @return true if the ability was successful, false otherwise
*/
public void herbalismBlockCheck(BlockState blockState) {
Player player = getPlayer();
Material blockType = blockState.getType();
HerbalismBlock herbalismBlock = HerbalismBlock.getHerbalismBlock(blockType);
CustomBlock customBlock = null;
int xp = 0;
int dropAmount = 1;
ItemStack dropItem = null;
if (herbalismBlock != null) {
if (blockType == Material.CACTUS || blockType == Material.SUGAR_CANE_BLOCK) {
dropItem = herbalismBlock.getDropItem();
dropAmount = Herbalism.calculateCatciAndSugarDrops(blockState);
xp = herbalismBlock.getXpGain() * dropAmount;
}
else if (herbalismBlock.hasGreenThumbPermission(player)){
dropItem = herbalismBlock.getDropItem();
xp = herbalismBlock.getXpGain();
processGreenThumbPlants(blockState);
}
else {
if (!mcMMO.placeStore.isTrue(blockState)) {
dropItem = herbalismBlock.getDropItem();
xp = herbalismBlock.getXpGain();
}
}
}
else {
customBlock = ModChecks.getCustomBlock(blockState);
dropItem = customBlock.getItemDrop();
xp = customBlock.getXpGain();
}
if (Permissions.doubleDrops(player, skill) && SkillTools.activationSuccessful(player, skill, Herbalism.doubleDropsMaxChance, Herbalism.doubleDropsMaxLevel)) {
Location location = blockState.getLocation();
if (dropItem != null && herbalismBlock != null && herbalismBlock.canDoubleDrop()) {
Misc.dropItems(location, dropItem, dropAmount);
}
else if (customBlock != null){
int minimumDropAmount = customBlock.getMinimumDropAmount();
int maximumDropAmount = customBlock.getMaximumDropAmount();
if (minimumDropAmount != maximumDropAmount) {
Misc.randomDropItems(location, dropItem, maximumDropAmount - minimumDropAmount);
}
Misc.dropItems(location, dropItem, minimumDropAmount);
}
}
applyXpGain(xp);
}
/**
* Process the Green Thumb ability for blocks.
*
* @param blockState The {@link BlockState} to check ability activation for
* @return true if the ability was successful, false otherwise
*/
public boolean processGreenThumbBlocks(BlockState blockState) {
Player player = getPlayer();
if (!SkillTools.activationSuccessful(player, skill, Herbalism.greenThumbMaxChance, Herbalism.greenThumbMaxLevel)) {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTh.Fail"));
return false;
}
return Herbalism.convertGreenTerraBlocks(blockState);
}
/**
* Process the Hylian Luck ability.
*
* @param blockState The {@link BlockState} to check ability activation for
* @return true if the ability was successful, false otherwise
*/
public boolean processHylianLuck(BlockState blockState) {
Player player = getPlayer();
if (!SkillTools.activationSuccessful(player, skill, Herbalism.hylianLuckMaxChance, Herbalism.hylianLuckMaxLevel)) {
return false;
}
List<HylianTreasure> treasures = new ArrayList<HylianTreasure>();
switch (blockState.getType()) {
case DEAD_BUSH:
case LONG_GRASS:
case SAPLING:
treasures = TreasuresConfig.getInstance().hylianFromBushes;
break;
case RED_ROSE:
case YELLOW_FLOWER:
if (mcMMO.placeStore.isTrue(blockState)) {
mcMMO.placeStore.setFalse(blockState);
return false;
}
treasures = TreasuresConfig.getInstance().hylianFromFlowers;
break;
case FLOWER_POT:
treasures = TreasuresConfig.getInstance().hylianFromPots;
break;
default:
return false;
}
if (treasures.isEmpty()) {
return false;
}
blockState.setRawData((byte) 0x0);
blockState.setType(Material.AIR);
Misc.dropItem(blockState.getLocation(), treasures.get(Misc.getRandom().nextInt(treasures.size())).getDrop());
player.sendMessage(LocaleLoader.getString("Herbalism.HylianLuck"));
return true;
}
/**
* Process the Shroom Thumb ability.
*
* @param blockState The {@link BlockState} to check ability activation for
* @return true if the ability was successful, false otherwise
*/
public boolean processShroomThumb(BlockState blockState) {
Player player = getPlayer();
PlayerInventory playerInventory = player.getInventory();
if (!playerInventory.contains(Material.BROWN_MUSHROOM)) {
player.sendMessage(LocaleLoader.getString("Skills.NeedMore", StringUtils.getPrettyItemString(Material.BROWN_MUSHROOM)));
return false;
}
if (!playerInventory.contains(Material.RED_MUSHROOM)) {
player.sendMessage(LocaleLoader.getString("Skills.NeedMore", StringUtils.getPrettyItemString(Material.RED_MUSHROOM)));
return false;
}
playerInventory.removeItem(new ItemStack(Material.BROWN_MUSHROOM));
playerInventory.removeItem(new ItemStack(Material.RED_MUSHROOM));
player.updateInventory();
if (!SkillTools.activationSuccessful(player, skill, Herbalism.shroomThumbMaxChance, Herbalism.shroomThumbMaxLevel)) {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.ShroomThumb.Fail"));
return false;
}
return Herbalism.convertShroomThumb(blockState);
}
/**
* Process the Green Thumb ability for plants.
*
* @param blockState The {@link BlockState} to check ability activation for
*/
private void processGreenThumbPlants(BlockState blockState) {
Player player = getPlayer();
PlayerInventory playerInventory = player.getInventory();
ItemStack seed = HerbalismBlock.getHerbalismBlock(blockState.getType()).getDropItem();
if (!playerInventory.containsAtLeast(seed, 1)) {
return;
}
PlayerProfile playerProfile = Users.getPlayer(player).getProfile();
if (playerProfile.getAbilityMode(AbilityType.GREEN_TERRA)) {
playerInventory.removeItem(seed);
player.updateInventory(); // Needed until replacement available
mcMMO.p.getServer().getScheduler().scheduleSyncDelayedTask(mcMMO.p, new GreenTerraTimer(blockState), 0);
return;
}
else if (SkillTools.activationSuccessful(player, skill, Herbalism.greenThumbMaxChance, Herbalism.greenThumbMaxLevel)) {
playerInventory.removeItem(seed);
player.updateInventory(); // Needed until replacement available
mcMMO.p.getServer().getScheduler().scheduleSyncDelayedTask(mcMMO.p, new GreenThumbTimer(blockState, getSkillLevel()), 0);
return;
}
}
}

View File

@@ -1,42 +0,0 @@
package com.gmail.nossr50.skills.mining;
import org.bukkit.event.entity.ExplosionPrimeEvent;
public class BiggerBombsEventHandler {
private int skillLevel;
private ExplosionPrimeEvent event;
private float radius;
private float radiusModifier;
protected BiggerBombsEventHandler(MiningManager manager, ExplosionPrimeEvent event) {
this.skillLevel = manager.getSkillLevel();
this.event = event;
this.radius = event.getRadius();
}
protected void calculateRadiusIncrease() {
if (skillLevel < BlastMining.rank2) {
return;
}
if (skillLevel >= BlastMining.rank8) {
radiusModifier = 4.0f;
}
else if (skillLevel >= BlastMining.rank6) {
radiusModifier = 3.0f;
}
else if (skillLevel >= BlastMining.rank4) {
radiusModifier = 2.0f;
}
else if (skillLevel >= BlastMining.rank2) {
radiusModifier = 1.0f;
}
}
protected void modifyBlastRadius() {
radius = radius + radiusModifier;
event.setRadius(radius);
}
}

View File

@@ -1,19 +1,103 @@
package com.gmail.nossr50.skills.mining;
import java.util.HashSet;
import org.bukkit.Material;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config;
public class BlastMining {
public static int rank1 = AdvancedConfig.getInstance().getBlastMiningRank1();
public static int rank2 = AdvancedConfig.getInstance().getBlastMiningRank2();
public static int rank3 = AdvancedConfig.getInstance().getBlastMiningRank3();
public static int rank4 = AdvancedConfig.getInstance().getBlastMiningRank4();
public static int rank5 = AdvancedConfig.getInstance().getBlastMiningRank5();
public static int rank6 = AdvancedConfig.getInstance().getBlastMiningRank6();
public static int rank7 = AdvancedConfig.getInstance().getBlastMiningRank7();
public static int rank8 = AdvancedConfig.getInstance().getBlastMiningRank8();
// The order of the values is extremely important, a few methods depend on it to work properly
protected enum Tier {
EIGHT(8) {
@Override public int getLevel() {return AdvancedConfig.getInstance().getBlastMiningRank8();}
@Override public double getBlastRadiusModifier() {return AdvancedConfig.getInstance().getBlastRadiusModifierRank8();}
@Override public double getOreBonus() {return AdvancedConfig.getInstance().getOreBonusRank8();}
@Override public double getDebrisReduction() {return AdvancedConfig.getInstance().getDebrisReductionRank8();}
@Override public double getBlastDamageDecrease() {return AdvancedConfig.getInstance().getBlastDamageDecreaseRank8();}
@Override public int getDropMultiplier() {return AdvancedConfig.getInstance().getDropMultiplierRank8();}},
SEVEN(7) {
@Override public int getLevel() {return AdvancedConfig.getInstance().getBlastMiningRank7();}
@Override public double getBlastRadiusModifier() {return AdvancedConfig.getInstance().getBlastRadiusModifierRank7();}
@Override public double getOreBonus() {return AdvancedConfig.getInstance().getOreBonusRank7();}
@Override public double getDebrisReduction() {return AdvancedConfig.getInstance().getDebrisReductionRank7();}
@Override public double getBlastDamageDecrease() {return AdvancedConfig.getInstance().getBlastDamageDecreaseRank7();}
@Override public int getDropMultiplier() {return AdvancedConfig.getInstance().getDropMultiplierRank7();}},
SIX(6) {
@Override public int getLevel() {return AdvancedConfig.getInstance().getBlastMiningRank6();}
@Override public double getBlastRadiusModifier() {return AdvancedConfig.getInstance().getBlastRadiusModifierRank6();}
@Override public double getOreBonus() {return AdvancedConfig.getInstance().getOreBonusRank6();}
@Override public double getDebrisReduction() {return AdvancedConfig.getInstance().getDebrisReductionRank6();}
@Override public double getBlastDamageDecrease() {return AdvancedConfig.getInstance().getBlastDamageDecreaseRank6();}
@Override public int getDropMultiplier() {return AdvancedConfig.getInstance().getDropMultiplierRank6();}},
FIVE(5) {
@Override public int getLevel() {return AdvancedConfig.getInstance().getBlastMiningRank5();}
@Override public double getBlastRadiusModifier() {return AdvancedConfig.getInstance().getBlastRadiusModifierRank5();}
@Override public double getOreBonus() {return AdvancedConfig.getInstance().getOreBonusRank5();}
@Override public double getDebrisReduction() {return AdvancedConfig.getInstance().getDebrisReductionRank5();}
@Override public double getBlastDamageDecrease() {return AdvancedConfig.getInstance().getBlastDamageDecreaseRank5();}
@Override public int getDropMultiplier() {return AdvancedConfig.getInstance().getDropMultiplierRank5();}},
FOUR(4) {
@Override public int getLevel() {return AdvancedConfig.getInstance().getBlastMiningRank4();}
@Override public double getBlastRadiusModifier() {return AdvancedConfig.getInstance().getBlastRadiusModifierRank4();}
@Override public double getOreBonus() {return AdvancedConfig.getInstance().getOreBonusRank4();}
@Override public double getDebrisReduction() {return AdvancedConfig.getInstance().getDebrisReductionRank4();}
@Override public double getBlastDamageDecrease() {return AdvancedConfig.getInstance().getBlastDamageDecreaseRank4();}
@Override public int getDropMultiplier() {return AdvancedConfig.getInstance().getDropMultiplierRank4();}},
THREE(3) {
@Override public int getLevel() {return AdvancedConfig.getInstance().getBlastMiningRank3();}
@Override public double getBlastRadiusModifier() {return AdvancedConfig.getInstance().getBlastRadiusModifierRank3();}
@Override public double getOreBonus() {return AdvancedConfig.getInstance().getOreBonusRank3();}
@Override public double getDebrisReduction() {return AdvancedConfig.getInstance().getDebrisReductionRank3();}
@Override public double getBlastDamageDecrease() {return AdvancedConfig.getInstance().getBlastDamageDecreaseRank3();}
@Override public int getDropMultiplier() {return AdvancedConfig.getInstance().getDropMultiplierRank3();}},
TWO(2) {
@Override public int getLevel() {return AdvancedConfig.getInstance().getBlastMiningRank2();}
@Override public double getBlastRadiusModifier() {return AdvancedConfig.getInstance().getBlastRadiusModifierRank2();}
@Override public double getOreBonus() {return AdvancedConfig.getInstance().getOreBonusRank2();}
@Override public double getDebrisReduction() {return AdvancedConfig.getInstance().getDebrisReductionRank2();}
@Override public double getBlastDamageDecrease() {return AdvancedConfig.getInstance().getBlastDamageDecreaseRank2();}
@Override public int getDropMultiplier() {return AdvancedConfig.getInstance().getDropMultiplierRank2();}},
ONE(1) {
@Override public int getLevel() {return AdvancedConfig.getInstance().getBlastMiningRank1();}
@Override public double getBlastRadiusModifier() {return AdvancedConfig.getInstance().getBlastRadiusModifierRank1();}
@Override public double getOreBonus() {return AdvancedConfig.getInstance().getOreBonusRank1();}
@Override public double getDebrisReduction() {return AdvancedConfig.getInstance().getDebrisReductionRank1();}
@Override public double getBlastDamageDecrease() {return AdvancedConfig.getInstance().getBlastDamageDecreaseRank1();}
@Override public int getDropMultiplier() {return AdvancedConfig.getInstance().getDropMultiplierRank1();}};
int numerical;
private Tier(int numerical) {
this.numerical = numerical;
}
public int toNumerical() {
return numerical;
}
abstract protected int getLevel();
abstract protected double getBlastRadiusModifier();
abstract protected double getOreBonus();
abstract protected double getDebrisReduction();
abstract protected double getBlastDamageDecrease();
abstract protected int getDropMultiplier();
}
public static int detonatorID = Config.getInstance().getDetonatorItemID();
public final static int MAXIMUM_REMOTE_DETONATION_DISTANCE = 100;
protected static HashSet<Byte> generateTransparentBlockList() {
HashSet<Byte> transparentBlocks = new HashSet<Byte>();
for (Material material : Material.values()) {
if (material.isTransparent()) {
transparentBlocks.add((byte) material.getId());
}
}
return transparentBlocks;
}
}

View File

@@ -1,152 +0,0 @@
package com.gmail.nossr50.skills.mining;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.util.BlockChecks;
import com.gmail.nossr50.util.Misc;
public class BlastMiningDropEventHandler {
private MiningManager manager;
private int skillLevel;
private EntityExplodeEvent event;
private float yield;
private List<Block> blocks;
private List<Block> ores = new ArrayList<Block>();
private List<Block> debris = new ArrayList<Block>();
private List<Block> droppedOres = new ArrayList<Block>();
private float oreBonus;
private float debrisReduction;
private int dropMultiplier;
public BlastMiningDropEventHandler(MiningManager manager, EntityExplodeEvent event) {
this.manager = manager;
this.skillLevel = manager.getSkillLevel();
this.event = event;
this.yield = event.getYield();
this.blocks = event.blockList();
}
protected void sortExplosionBlocks() {
for (Block block : blocks) {
if (BlockChecks.isOre(block)) {
ores.add(block);
}
else {
debris.add(block);
}
}
}
protected void processXPGain() {
McMMOPlayer mcMMOPlayer = manager.getMcMMOPlayer();
for (Block block : droppedOres) {
if (!mcMMO.placeStore.isTrue(block)) {
Mining.miningXP(mcMMOPlayer, block, block.getType());
}
}
}
protected void processDroppedBlocks() {
for (Block block : ores) {
Location location = block.getLocation();
Material type = block.getType();
if (Misc.getRandom().nextFloat() < (yield + oreBonus)) {
droppedOres.add(block);
Mining.miningDrops(block, location, type);
if (!mcMMO.placeStore.isTrue(block)) {
for (int i = 1 ; i < dropMultiplier ; i++) {
droppedOres.add(block);
Mining.miningDrops(block, location, type);
}
}
}
}
float debrisYield = yield - debrisReduction;
if (debrisYield > 0) {
for (Block block : debris) {
Location location = block.getLocation();
Material type = block.getType();
if (Misc.getRandom().nextFloat() < debrisYield) {
Misc.dropItem(location, new ItemStack(type));
}
}
}
}
protected void modifyEventYield() {
event.setYield(0);
}
protected void calcuateDropModifiers() {
calculateOreBonus();
calculateDebrisReduction();
calculateDropMultiplier();
}
private void calculateOreBonus() {
if (skillLevel >= BlastMining.rank8) {
oreBonus = .70f;
}
else if (skillLevel >= BlastMining.rank7) {
oreBonus = .65f;
}
else if (skillLevel >= BlastMining.rank6) {
oreBonus = .60f;
}
else if (skillLevel >= BlastMining.rank5) {
oreBonus = .55f;
}
else if (skillLevel >= BlastMining.rank4) {
oreBonus = .50f;
}
else if (skillLevel >= BlastMining.rank3) {
oreBonus = .45f;
}
else if (skillLevel >= BlastMining.rank2) {
oreBonus = .40f;
}
else {
debrisReduction = .35f;
}
}
private void calculateDebrisReduction() {
if (skillLevel >= BlastMining.rank3) {
debrisReduction = .30f;
}
else if (skillLevel >= BlastMining.rank2) {
debrisReduction = .20f;
}
else {
debrisReduction = .10f;
}
}
private void calculateDropMultiplier() {
if (skillLevel >= BlastMining.rank7) {
dropMultiplier = 3;
}
else if (skillLevel >= BlastMining.rank5) {
dropMultiplier = 2;
}
else {
dropMultiplier = 1;
}
}
}

View File

@@ -1,37 +0,0 @@
package com.gmail.nossr50.skills.mining;
import org.bukkit.event.entity.EntityDamageEvent;
public class DemoltionsExpertiseEventHandler {
private int skillLevel;
private EntityDamageEvent event;
private int damage;
private double damageModifier;
public DemoltionsExpertiseEventHandler(MiningManager manager, EntityDamageEvent event) {
this.skillLevel = manager.getSkillLevel();
this.event = event;
this.damage = event.getDamage();
}
protected void calculateDamageModifier() {
if (skillLevel >= BlastMining.rank8) {
damageModifier = 0.0;
}
else if (skillLevel >= BlastMining.rank6) {
damageModifier = 0.25;
}
else if (skillLevel >= BlastMining.rank4) {
damageModifier = 0.5;
}
else {
damageModifier = 1.0;
}
}
protected void modifyEventDamage() {
damage = (int) (damage * damageModifier);
event.setDamage(damage);
}
}

View File

@@ -1,15 +1,12 @@
package com.gmail.nossr50.skills.mining;
import org.bukkit.CoalType;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.mods.ModChecks;
import com.gmail.nossr50.mods.datatypes.CustomBlock;
import com.gmail.nossr50.skills.utilities.SkillType;
@@ -21,44 +18,38 @@ public class Mining {
public static int doubleDropsMaxLevel = advancedConfig.getMiningDoubleDropMaxLevel();
public static double doubleDropsMaxChance = advancedConfig.getMiningDoubleDropChance();
public static final int DIAMOND_TOOL_TIER = 4;
public static final int IRON_TOOL_TIER = 3;
public static final int STONE_TOOL_TIER = 2;
/**
* Award XP for Mining blocks.
* Calculate XP gain for Mining.
*
* @param mcMMOPlayer The player to award XP to
* @param block The block to award XP for
* @param blockState The {@link BlockState} to check ability activation for
*/
protected static void miningXP(McMMOPlayer mcMMOPlayer, Block block, Material type) {
int xp = Config.getInstance().getXp(SkillType.MINING, type);
protected static int getBlockXp(BlockState blockState) {
Material blockType = blockState.getType();
int xp = Config.getInstance().getXp(SkillType.MINING, blockType);
if (type == Material.GLOWING_REDSTONE_ORE) {
if (blockType == Material.GLOWING_REDSTONE_ORE) {
xp = Config.getInstance().getXp(SkillType.MINING, Material.REDSTONE_ORE);
}
else if (xp == 0 && ModChecks.isCustomMiningBlock(block)) {
xp = ModChecks.getCustomBlock(block).getXpGain();
else if (xp == 0 && ModChecks.isCustomMiningBlock(blockState)) {
xp = ModChecks.getCustomBlock(blockState).getXpGain();
}
mcMMOPlayer.beginXpGain(SkillType.MINING, xp);
return xp;
}
/**
* Handle double drops when using Silk Touch.
*
* @param block The block to process drops for
* @param location The location of the block
* @param type The material type of the block
* @param blockState The {@link BlockState} to check ability activation for
*/
protected static void silkTouchDrops(Block block, Location location, Material type) {
ItemStack item = new ItemStack(type);
protected static void handleSilkTouchDrops(BlockState blockState) {
Material blockType = blockState.getType();
if (type != Material.GLOWING_REDSTONE_ORE && !Config.getInstance().getDoubleDropsEnabled(SkillType.MINING, type)) {
if (blockType != Material.GLOWING_REDSTONE_ORE && !Config.getInstance().getDoubleDropsEnabled(SkillType.MINING, blockType)) {
return;
}
switch (type) {
switch (blockType) {
case ENDER_STONE:
case GOLD_ORE:
case IRON_ORE:
@@ -66,14 +57,14 @@ public class Mining {
case NETHERRACK:
case OBSIDIAN:
case SANDSTONE:
miningDrops(block, location, type);
break;
handleMiningDrops(blockState);
return;
case GLOWING_REDSTONE_ORE:
if (Config.getInstance().getDoubleDropsEnabled(SkillType.MINING, Material.REDSTONE_ORE)) {
Misc.dropItem(location, item);
Misc.dropItem(blockState.getLocation(), new ItemStack(Material.REDSTONE_ORE));
}
break;
return;
case COAL_ORE:
case DIAMOND_ORE:
@@ -82,75 +73,39 @@ public class Mining {
case LAPIS_ORE:
case STONE:
case EMERALD_ORE:
Misc.dropItem(location, item);
break;
Misc.dropItem(blockState.getLocation(), new ItemStack(blockType));
return;
default:
if (ModChecks.isCustomMiningBlock(block)) {
ItemStack dropItem = new ItemStack(block.getTypeId(), 1, block.getData());
Misc.dropItem(location, dropItem);
if (ModChecks.isCustomMiningBlock(blockState)) {
Misc.dropItem(blockState.getLocation(), blockState.getData().toItemStack());
}
break;
return;
}
}
/**
* Drop items from Mining & Blast Mining skills.
* Handle double drops from Mining & Blast Mining.
*
* @param block The block to process drops for
* @param location The location of the block
* @param type The material type of the block
* @param blockState The {@link BlockState} to check ability activation for
*/
protected static void miningDrops(Block block, Location location, Material type) {
if (type != Material.GLOWING_REDSTONE_ORE && !Config.getInstance().getDoubleDropsEnabled(SkillType.MINING, type)) {
protected static void handleMiningDrops(BlockState blockState) {
Material blockType = blockState.getType();
if (blockType != Material.GLOWING_REDSTONE_ORE && !Config.getInstance().getDoubleDropsEnabled(SkillType.MINING, blockType)) {
return;
}
ItemStack item = new ItemStack(type);
Location location = blockState.getLocation();
ItemStack dropItem;
switch (type) {
switch (blockType) {
case COAL_ORE:
item = new ItemStack(Material.COAL, 1, CoalType.COAL.getData());
Misc.dropItem(location, item);
break;
case DIAMOND_ORE:
item = new ItemStack(Material.DIAMOND);
Misc.dropItem(location, item);
break;
case EMERALD_ORE:
item = new ItemStack(Material.EMERALD);
Misc.dropItem(location, item);
break;
case GLOWING_REDSTONE_ORE:
case REDSTONE_ORE:
if (Config.getInstance().getDoubleDropsEnabled(SkillType.MINING, Material.REDSTONE_ORE)) {
item = new ItemStack(Material.REDSTONE);
Misc.dropItems(location, item, 4);
Misc.randomDropItem(location, item, 50);
}
break;
case GLOWSTONE:
item = new ItemStack(Material.GLOWSTONE_DUST);
Misc.dropItems(location, item, 2);
Misc.randomDropItems(location, item, 2);
break;
case LAPIS_ORE:
item = new ItemStack(Material.INK_SACK, 1, DyeColor.BLUE.getDyeData());
Misc.dropItems(location, item, 4);
Misc.randomDropItems(location, item, 4);
break;
case STONE:
item = new ItemStack(Material.COBBLESTONE);
Misc.dropItem(location, item);
break;
case ENDER_STONE:
case GOLD_ORE:
case IRON_ORE:
@@ -158,26 +113,36 @@ public class Mining {
case NETHERRACK:
case OBSIDIAN:
case SANDSTONE:
Misc.dropItem(location, item);
break;
for (ItemStack drop : blockState.getBlock().getDrops()) {
Misc.dropItem(location, drop);
}
return;
case GLOWING_REDSTONE_ORE:
case REDSTONE_ORE:
if (Config.getInstance().getDoubleDropsEnabled(SkillType.MINING, Material.REDSTONE_ORE)) {
for (ItemStack drop : blockState.getBlock().getDrops()) {
Misc.dropItem(location, drop);
}
}
return;
default:
if (ModChecks.isCustomMiningBlock(block)) {
CustomBlock customBlock = ModChecks.getCustomBlock(block);
if (ModChecks.isCustomMiningBlock(blockState)) {
CustomBlock customBlock = ModChecks.getCustomBlock(blockState);
int minimumDropAmount = customBlock.getMinimumDropAmount();
int maximumDropAmount = customBlock.getMaximumDropAmount();
item = ModChecks.getCustomBlock(block).getItemDrop();
dropItem = customBlock.getItemDrop();
if (minimumDropAmount != maximumDropAmount) {
Misc.dropItems(location, item, minimumDropAmount);
Misc.randomDropItems(location, item, maximumDropAmount - minimumDropAmount);
Misc.dropItems(location, dropItem, minimumDropAmount);
Misc.randomDropItems(location, dropItem, maximumDropAmount - minimumDropAmount);
}
else {
Misc.dropItems(location, item, minimumDropAmount);
Misc.dropItems(location, dropItem, minimumDropAmount);
}
}
break;
return;
}
}
}

View File

@@ -1,45 +0,0 @@
package com.gmail.nossr50.skills.mining;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment;
import com.gmail.nossr50.skills.utilities.SkillTools;
public class MiningBlockEventHandler {
private MiningManager manager;
private Block block;
private Location blockLocation;
private Material blockType;
protected int skillModifier;
protected MiningBlockEventHandler(MiningManager manager, Block block) {
this.manager = manager;
this.block = block;
this.blockLocation = block.getLocation();
this.blockType = block.getType();
calculateSkillModifier();
}
private void calculateSkillModifier() {
this.skillModifier = SkillTools.skillCheck(manager.getSkillLevel(), Mining.doubleDropsMaxLevel);
}
/**
* Process Mining block drops.
*/
protected void processDrops() {
if (manager.getMcMMOPlayer().getPlayer().getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
Mining.silkTouchDrops(block, blockLocation, blockType);
}
else {
Mining.miningDrops(block, blockLocation, blockType);
}
}
protected void processXPGain() {
Mining.miningXP(manager.getMcMMOPlayer(), block, blockType);
}
}

View File

@@ -1,7 +1,9 @@
package com.gmail.nossr50.skills.mining;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.SkillCommand;
import com.gmail.nossr50.skills.SkillManagerStore;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Permissions;
@@ -10,8 +12,12 @@ public class MiningCommand extends SkillCommand {
private String doubleDropChanceLucky;
private String superBreakerLength;
private String superBreakerLengthEndurance;
private String blastMiningRank;
private String blastRadiusIncrease;
private int blastMiningRank;
private int bonusTNTDrops;
private double blastRadiusIncrease;
private String oreBonus;
private String debrisReduction;
private String blastDamageDecrease;
private boolean canSuperBreaker;
@@ -38,51 +44,13 @@ public class MiningCommand extends SkillCommand {
doubleDropChanceLucky = doubleDropStrings[1];
//BLAST MINING
if (skillValue >= BlastMining.rank8) {
blastMiningRank = "8";
blastDamageDecrease = "100.00%";
blastRadiusIncrease = "4";
}
else if (skillValue >= BlastMining.rank7) {
blastMiningRank = "7";
blastDamageDecrease = "50.00%";
blastRadiusIncrease = "3";
}
else if (skillValue >= BlastMining.rank6) {
blastMiningRank = "6";
blastDamageDecrease = "50.00%";
blastRadiusIncrease = "3";
}
else if (skillValue >= BlastMining.rank5) {
blastMiningRank = "5";
blastDamageDecrease = "25.00%";
blastRadiusIncrease = "2";
}
else if (skillValue >= BlastMining.rank4) {
blastMiningRank = "4";
blastDamageDecrease = "25.00%";
blastRadiusIncrease = "2";
}
else if (skillValue >= BlastMining.rank3) {
blastMiningRank = "3";
blastDamageDecrease = "0.00%";
blastRadiusIncrease = "1";
}
else if (skillValue >= BlastMining.rank2) {
blastMiningRank = "2";
blastDamageDecrease = "0.00%";
blastRadiusIncrease = "1";
}
else if (skillValue >= BlastMining.rank1) {
blastMiningRank = "1";
blastDamageDecrease = "0.00%";
blastRadiusIncrease = "0";
}
else {
blastMiningRank = "0";
blastDamageDecrease = "0.00%";
blastRadiusIncrease = "0";
}
MiningManager miningManager = SkillManagerStore.getInstance().getMiningManager(player.getName());
blastMiningRank = miningManager.getBlastMiningTier();
bonusTNTDrops = miningManager.getDropMultiplier();
oreBonus = percent.format(miningManager.getOreBonus() / 30.0D); // Base received in TNT is 30%
debrisReduction = percent.format(miningManager.getDebrisReduction() / 30.0D); // Base received in TNT is 30%
blastDamageDecrease = percent.format(miningManager.getBlastDamageModifier() / 100.0D);
blastRadiusIncrease = miningManager.getBlastRadiusModifier();
}
@Override
@@ -151,17 +119,17 @@ public class MiningCommand extends SkillCommand {
}
if (canBlast) {
if (skillValue < BlastMining.rank1) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Mining.Ability.Locked.0", BlastMining.rank1)));
if (skillValue < AdvancedConfig.getInstance().getBlastMiningRank1()) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Mining.Ability.Locked.0", AdvancedConfig.getInstance().getBlastMiningRank1())));
}
else {
player.sendMessage(LocaleLoader.getString("Mining.Blast.Rank", blastMiningRank, LocaleLoader.getString("Mining.Blast.Effect." + (Integer.parseInt(blastMiningRank) - 1))));
player.sendMessage(LocaleLoader.getString("Mining.Blast.Rank", blastMiningRank, LocaleLoader.getString("Mining.Blast.Effect", oreBonus, debrisReduction, bonusTNTDrops)));
}
}
if (canBiggerBombs) {
if (skillValue < BlastMining.rank2) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Mining.Ability.Locked.1", BlastMining.rank2)));
if (skillValue < AdvancedConfig.getInstance().getBlastMiningRank2()) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Mining.Ability.Locked.1", AdvancedConfig.getInstance().getBlastMiningRank2())));
}
else {
player.sendMessage(LocaleLoader.getString("Mining.Blast.Radius.Increase", blastRadiusIncrease));
@@ -169,8 +137,8 @@ public class MiningCommand extends SkillCommand {
}
if (canDemoExpert) {
if (skillValue < BlastMining.rank4) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Mining.Ability.Locked.2", BlastMining.rank4)));
if (skillValue < AdvancedConfig.getInstance().getBlastMiningRank4()) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Mining.Ability.Locked.2", AdvancedConfig.getInstance().getBlastMiningRank4())));
}
else {
player.sendMessage(LocaleLoader.getString("Mining.Effect.Decrease", blastDamageDecrease));

View File

@@ -1,16 +1,26 @@
package com.gmail.nossr50.skills.mining;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.ExplosionPrimeEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.block.BlockState;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.mining.BlastMining.Tier;
import com.gmail.nossr50.skills.utilities.AbilityType;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.BlockChecks;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
@@ -19,35 +29,76 @@ public class MiningManager extends SkillManager{
super(mcMMOPlayer, SkillType.MINING);
}
public boolean canUseDemolitionsExpertise() {
Player player = getPlayer();
return SkillTools.unlockLevelReached(player, skill, BlastMining.Tier.FOUR.getLevel()) && Permissions.demolitionsExpertise(player);
}
public boolean canDetonate() {
Player player = getPlayer();
return player.isSneaking() && player.getItemInHand().getTypeId() == BlastMining.detonatorID && Permissions.remoteDetonation(player) && SkillTools.unlockLevelReached(player, skill, BlastMining.Tier.ONE.getLevel());
}
public boolean canUseBlastMining() {
return SkillTools.unlockLevelReached(getPlayer(), skill, BlastMining.Tier.ONE.getLevel());
}
public boolean canUseBiggerBombs() {
Player player = getPlayer();
return Permissions.biggerBombs(player) && SkillTools.unlockLevelReached(getPlayer(), skill, BlastMining.Tier.TWO.getLevel());
}
/**
* Process double drops & XP gain for Mining.
*
* @param blockState The {@link BlockState} to check ability activation for
* @param player The {@link Player} using this ability
*/
public void miningBlockCheck(BlockState blockState) {
Player player = getPlayer();
int xp = Mining.getBlockXp(blockState);
if (Permissions.doubleDrops(player, skill) && SkillTools.activationSuccessful(player, skill, Mining.doubleDropsMaxChance, Mining.doubleDropsMaxLevel)) {
if (player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
Mining.handleSilkTouchDrops(blockState);
}
else {
Mining.handleMiningDrops(blockState);
}
}
applyXpGain(xp);
}
/**
* Detonate TNT for Blast Mining
*
* @param event The PlayerInteractEvent
*/
public void detonate(PlayerInteractEvent event) {
if (skillLevel < BlastMining.rank1) {
public void remoteDetonation() {
Player player = getPlayer();
HashSet<Byte> transparentBlocks = BlastMining.generateTransparentBlockList();
Block targetBlock = player.getTargetBlock(transparentBlocks, BlastMining.MAXIMUM_REMOTE_DETONATION_DISTANCE);
if (targetBlock.getType() != Material.TNT || !SkillTools.blockBreakSimulate(targetBlock, player, true) || !blastMiningCooldownOver()) {
return;
}
RemoteDetonationEventHandler eventHandler = new RemoteDetonationEventHandler(this, event);
PlayerProfile profile = getProfile();
TNTPrimed tnt = player.getWorld().spawn(targetBlock.getLocation(), TNTPrimed.class);
eventHandler.targetTNT();
SkillTools.sendSkillMessage(player, AbilityType.BLAST_MINING.getAbilityPlayer(player));
player.sendMessage(LocaleLoader.getString("Mining.Blast.Boom"));
if (eventHandler.getBlock().getType() != Material.TNT) {
return;
}
mcMMO.p.addToTNTTracker(tnt.getEntityId(), player.getName());
tnt.setFuseTicks(0);
targetBlock.setData((byte) 0x0);
targetBlock.setType(Material.AIR);
if (!SkillTools.blockBreakSimulate(eventHandler.getBlock(), mcMMOPlayer.getPlayer(), true)) {
return;
}
if (!eventHandler.cooldownOver()) {
return;
}
eventHandler.sendMessages();
eventHandler.handleDetonation();
eventHandler.setProfileData();
profile.setSkillDATS(AbilityType.BLAST_MINING, System.currentTimeMillis());
profile.setAbilityInformed(AbilityType.BLAST_MINING, false);
}
/**
@@ -55,36 +106,54 @@ public class MiningManager extends SkillManager{
*
* @param event Event whose explosion is being processed
*/
public void blastMiningDropProcessing(EntityExplodeEvent event) {
if (Misc.isNPCEntity(mcMMOPlayer.getPlayer())) {
return;
public void blastMiningDropProcessing(float yield, List<Block> blockList) {
List<BlockState> ores = new ArrayList<BlockState>();
List<BlockState> debris = new ArrayList<BlockState>();
int xp = 0;
float oreBonus = (float) (getOreBonus() / 100);
float debrisReduction = (float) (getDebrisReduction() / 100);
int dropMultiplier = getDropMultiplier();
float debrisYield = yield - debrisReduction;
for (Block block : blockList) {
BlockState blockState = block.getState();
if (BlockChecks.isOre(blockState)) {
ores.add(blockState);
}
else {
debris.add(blockState);
}
}
if (skillLevel < BlastMining.rank1) {
return;
for (BlockState blockState : ores) {
if (Misc.getRandom().nextFloat() < (yield + oreBonus)) {
if (!mcMMO.placeStore.isTrue(blockState)) {
xp += Mining.getBlockXp(blockState);
}
Misc.dropItem(blockState.getLocation(), blockState.getData().toItemStack()); // Initial block that would have been dropped
if (!mcMMO.placeStore.isTrue(blockState)) {
for (int i = 1 ; i < dropMultiplier ; i++) {
xp += Mining.getBlockXp(blockState);
Mining.handleSilkTouchDrops(blockState); // Bonus drops - should drop the block & not the items
}
}
}
}
BlastMiningDropEventHandler eventHandler = new BlastMiningDropEventHandler(this, event);
if (debrisYield > 0) {
for (BlockState blockState : debris) {
if (Misc.getRandom().nextFloat() < debrisYield) {
Misc.dropItem(blockState.getLocation(), blockState.getData().toItemStack());
}
}
}
eventHandler.sortExplosionBlocks();
eventHandler.modifyEventYield();
eventHandler.calcuateDropModifiers();
eventHandler.processDroppedBlocks();
eventHandler.processXPGain();
}
/**
* Decreases damage dealt by the explosion from TNT activated by Blast Mining.
*
* @param event Event whose explosion damage is being reduced
*/
public void demolitionsExpertise(EntityDamageEvent event) {
DemoltionsExpertiseEventHandler eventHandler = new DemoltionsExpertiseEventHandler(this, event);
eventHandler.calculateDamageModifier();
eventHandler.modifyEventDamage();
applyXpGain(xp);
}
/**
@@ -92,34 +161,128 @@ public class MiningManager extends SkillManager{
*
* @param event Event whose explosion radius is being changed
*/
public void biggerBombs(ExplosionPrimeEvent event) {
if (Misc.isNPCEntity(mcMMOPlayer.getPlayer())) {
return;
public float biggerBombs(float radius) {
return (float) (radius + getBlastRadiusModifier());
}
public int processDemolitionsExpertise(int damage) {
return (int) (damage * (100.0 - getBlastDamageModifier()));
}
private boolean blastMiningCooldownOver() {
Player player = getPlayer();
PlayerProfile profile = getProfile();
long oldTime = profile.getSkillDATS(AbilityType.BLAST_MINING) * Misc.TIME_CONVERSION_FACTOR;
int cooldown = AbilityType.BLAST_MINING.getCooldown();
if (!SkillTools.cooldownOver(oldTime, cooldown, player)) {
player.sendMessage(LocaleLoader.getString("Skills.TooTired", SkillTools.calculateTimeLeft(oldTime, cooldown, player)));
return false;
}
BiggerBombsEventHandler eventHandler = new BiggerBombsEventHandler(this, event);
eventHandler.calculateRadiusIncrease();
eventHandler.modifyBlastRadius();
return true;
}
/**
* Process Mining block drops.
* Gets the Blast Mining tier
*
* @param block The block being broken
* @return the Blast Mining tier
*/
public void miningBlockCheck(Block block) {
MiningBlockEventHandler eventHandler = new MiningBlockEventHandler(this, block);
eventHandler.processXPGain();
public int getBlastMiningTier() {
int skillLevel = getSkillLevel();
if (!Permissions.doubleDrops(mcMMOPlayer.getPlayer(), skill)) {
return;
for (Tier tier : Tier.values()) {
if (skillLevel >= tier.getLevel()) {
return tier.toNumerical();
}
}
float chance = ((float) Mining.doubleDropsMaxChance / Mining.doubleDropsMaxLevel) * eventHandler.skillModifier;
return 0;
}
if (chance > Misc.getRandom().nextInt(activationChance)) {
eventHandler.processDrops();
/**
* Gets the Blast Mining tier
*
* @return the Blast Mining tier
*/
public double getOreBonus() {
int skillLevel = getSkillLevel();
for (Tier tier : Tier.values()) {
if (skillLevel >= tier.getLevel()) {
return tier.getOreBonus();
}
}
return 0;
}
/**
* Gets the Blast Mining tier
*
* @return the Blast Mining tier
*/
public double getDebrisReduction() {
int skillLevel = getSkillLevel();
for (Tier tier : Tier.values()) {
if (skillLevel >= tier.getLevel()) {
return tier.getDebrisReduction();
}
}
return 0;
}
/**
* Gets the Blast Mining tier
*
* @return the Blast Mining tier
*/
public int getDropMultiplier() {
int skillLevel = getSkillLevel();
for (Tier tier : Tier.values()) {
if (skillLevel >= tier.getLevel()) {
return tier.getDropMultiplier();
}
}
return 0;
}
/**
* Gets the Blast Mining tier
*
* @return the Blast Mining tier
*/
public double getBlastRadiusModifier() {
int skillLevel = getSkillLevel();
for (Tier tier : Tier.values()) {
if (skillLevel >= tier.getLevel()) {
return tier.getBlastRadiusModifier();
}
}
return 0;
}
/**
* Gets the Blast Mining tier
*
* @return the Blast Mining tier
*/
public double getBlastDamageModifier() {
int skillLevel = getSkillLevel();
for (Tier tier : Tier.values()) {
if (skillLevel >= tier.getLevel()) {
return tier.getBlastDamageDecrease();
}
}
return 0;
}
}

View File

@@ -1,89 +0,0 @@
package com.gmail.nossr50.skills.mining;
import java.util.HashSet;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.player.PlayerInteractEvent;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.AbilityType;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.util.Misc;
public class RemoteDetonationEventHandler {
private MiningManager manager;
private PlayerInteractEvent event;
private Block block;
private HashSet<Byte> transparentBlocks = new HashSet<Byte>();
public RemoteDetonationEventHandler(MiningManager manager, PlayerInteractEvent event) {
this.manager = manager;
this.event = event;
this.block = event.getClickedBlock();
}
protected void targetTNT() {
if (block == null || block.getType() != Material.TNT) {
generateTransparentBlockList();
block = manager.getMcMMOPlayer().getPlayer().getTargetBlock(transparentBlocks, BlastMining.MAXIMUM_REMOTE_DETONATION_DISTANCE);
}
else {
event.setCancelled(true); // This is the only way I know to avoid the original TNT to be triggered (in case the player is close to it)
}
}
protected boolean cooldownOver() {
McMMOPlayer mcMMOPlayer = manager.getMcMMOPlayer();
Player player = mcMMOPlayer.getPlayer();
PlayerProfile profile = mcMMOPlayer.getProfile();
if (!SkillTools.cooldownOver(profile.getSkillDATS(AbilityType.BLAST_MINING) * Misc.TIME_CONVERSION_FACTOR, AbilityType.BLAST_MINING.getCooldown(), player)) {
player.sendMessage(LocaleLoader.getString("Skills.TooTired", SkillTools.calculateTimeLeft(profile.getSkillDATS(AbilityType.BLAST_MINING) * Misc.TIME_CONVERSION_FACTOR, AbilityType.BLAST_MINING.getCooldown(), player)));
return false;
}
return true;
}
protected void sendMessages() {
Player player = manager.getMcMMOPlayer().getPlayer();
SkillTools.sendSkillMessage(player, AbilityType.BLAST_MINING.getAbilityPlayer(player));
player.sendMessage(LocaleLoader.getString("Mining.Blast.Boom"));
}
protected void handleDetonation() {
Player player = manager.getMcMMOPlayer().getPlayer();
TNTPrimed tnt = player.getWorld().spawn(block.getLocation(), TNTPrimed.class);
mcMMO.p.addToTNTTracker(tnt.getEntityId(), player.getName());
tnt.setFuseTicks(0);
block.setType(Material.AIR);
}
protected void setProfileData() {
PlayerProfile profile = manager.getMcMMOPlayer().getProfile();
profile.setSkillDATS(AbilityType.BLAST_MINING, System.currentTimeMillis());
profile.setAbilityInformed(AbilityType.BLAST_MINING, false);
}
private void generateTransparentBlockList() {
for (Material material : Material.values()) {
if (material.isTransparent()) {
transparentBlocks.add((byte) material.getId());
}
}
}
protected Block getBlock() {
return block;
}
}

View File

@@ -1,17 +1,13 @@
package com.gmail.nossr50.skills.runnables;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.Effect;
import org.bukkit.Material;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.CombatTools;
import com.gmail.nossr50.util.ParticleEffectUtils;
@@ -19,70 +15,55 @@ import com.gmail.nossr50.util.ParticleEffectUtils;
public class BleedTimer implements Runnable {
private final static int MAX_BLEED_TICKS = 10;
private static Map<LivingEntity, Integer> bleedList = new HashMap<LivingEntity, Integer>();
private static Map<LivingEntity, Integer> bleedAddList = new HashMap<LivingEntity, Integer>();
private static List<LivingEntity> bleedRemoveList = new ArrayList<LivingEntity>();
private static boolean lock = false;
@Override
public void run() {
updateBleedList();
bleedSimulate();
}
private void bleedSimulate() {
lock = true;
for (Entry<LivingEntity, Integer> entry : bleedList.entrySet()) {
for (Iterator<Entry<LivingEntity, Integer>> bleedIterator = bleedList.entrySet().iterator(); bleedIterator.hasNext();) {
Entry<LivingEntity, Integer> entry = bleedIterator.next();
LivingEntity entity = entry.getKey();
if (entry.getValue() <= 0 || entity.isDead()) {
remove(entity);
break;
if (entry.getValue() <= 0 || !entity.isValid()) {
bleedIterator.remove();
continue;
}
// Player bleed simulation
int damage = 0;
if (entity instanceof Player) {
damage = 1;
Player player = (Player) entity;
if (!player.isOnline()) {
continue;
}
//Never kill with Bleeding
if (player.getHealth() - 1 > 0) {
CombatTools.dealDamage(player, 1);
ParticleEffectUtils.playBleedEffect(player);
// Never kill with Bleeding
if (player.getHealth() - damage > 0) {
CombatTools.dealDamage(player, damage);
ParticleEffectUtils.playBleedEffect(entity);
}
entry.setValue(entry.getValue() - 1);
entry.setValue(entry.getValue() - damage);
if (entry.getValue() <= 0) {
player.sendMessage(LocaleLoader.getString("Swords.Combat.Bleeding.Stopped"));
}
}
// Bleed monsters/animals
else {
CombatTools.dealDamage(entity, 2);
entry.setValue(entry.getValue() - 1);
entity.getWorld().playEffect(entity.getEyeLocation(), Effect.STEP_SOUND, Material.REDSTONE_WIRE);
damage = 2;
// Anticipate the entity's death to prevent CME because of our EntityDeathEvent listener
if (entity.getHealth() - damage > 0) {
entry.setValue(entry.getValue() - 1);
}
else {
bleedIterator.remove();
}
CombatTools.dealDamage(entity, damage);
ParticleEffectUtils.playBleedEffect(entity);
}
}
// Unlock list now that we are done
lock = false;
}
private void updateBleedList() {
if (lock) {
mcMMO.p.getLogger().warning("mcBleedTimer attempted to update the bleedList but the list was locked!");
}
else {
bleedList.keySet().removeAll(bleedRemoveList);
bleedRemoveList.clear();
bleedList.putAll(bleedAddList);
bleedAddList.clear();
}
}
/**
@@ -103,15 +84,8 @@ public class BleedTimer implements Runnable {
* @param entity LivingEntity to remove
*/
public static void remove(LivingEntity entity) {
if (lock) {
if (!bleedRemoveList.contains(entity)) {
bleedRemoveList.add(entity);
}
}
else {
if (bleedList.containsKey(entity)) {
bleedList.remove(entity);
}
if (bleedList.containsKey(entity)) {
bleedList.remove(entity);
}
}
@@ -124,58 +98,12 @@ public class BleedTimer implements Runnable {
public static void add(LivingEntity entity, int ticks) {
int newTicks = ticks;
if (lock) {
if (bleedAddList.containsKey(entity)) {
newTicks += bleedAddList.get(entity);
if (newTicks > MAX_BLEED_TICKS) {
newTicks = MAX_BLEED_TICKS;
}
bleedAddList.put(entity, newTicks);
}
else {
if (newTicks > MAX_BLEED_TICKS) {
newTicks = MAX_BLEED_TICKS;
}
bleedAddList.put(entity, newTicks);
}
if (bleedList.containsKey(entity)) {
newTicks += bleedList.get(entity);
bleedList.put(entity, Math.min(newTicks, MAX_BLEED_TICKS));
}
else {
if (bleedList.containsKey(entity)) {
newTicks += bleedList.get(entity);
if (newTicks > MAX_BLEED_TICKS) {
newTicks = MAX_BLEED_TICKS;
}
bleedList.put(entity, newTicks);
// Need to find a better way to ensure that the entity stays in bleedList
// when some ticks are added but already marked for removal.
// Suggestion: Why not use Iterator.remove() and drop the lock boolean?
if (bleedRemoveList.contains(entity)) {
bleedRemoveList.remove(entity);
}
}
else {
if (newTicks > MAX_BLEED_TICKS) {
newTicks = MAX_BLEED_TICKS;
}
bleedList.put(entity, newTicks);
}
bleedList.put(entity, Math.min(newTicks, MAX_BLEED_TICKS));
}
}
/**
* Check to see if a LivingEntity is in the bleedList
*
* @param entity LivingEntity to check if in the bleedList
* @return true if in the list, false if not
*/
public static boolean contains(LivingEntity entity) {
return (bleedList.containsKey(entity) || bleedAddList.containsKey(entity));
}
}

View File

@@ -1,68 +0,0 @@
package com.gmail.nossr50.skills.smelting;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.mining.Mining;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
public class FluxMiningEventHandler {
private SmeltingManager manager;
private BlockBreakEvent event;
private Block block;
protected FluxMiningEventHandler(SmeltingManager manager, BlockBreakEvent event) {
this.manager = manager;
this.event = event;
this.block = event.getBlock();
}
protected void processDrops() {
ItemStack item = null;
switch (block.getType()) {
case IRON_ORE:
item = new ItemStack(Material.IRON_INGOT);
break;
case GOLD_ORE:
item = new ItemStack(Material.GOLD_INGOT);
break;
default:
break;
}
if (item == null) {
return;
}
Location location = block.getLocation();
Misc.dropItem(location, item);
McMMOPlayer mcMMOPlayer = manager.getMcMMOPlayer();
if (Permissions.doubleDrops(mcMMOPlayer.getPlayer(), manager.getSkill())) {
int chance = (int) ((Mining.doubleDropsMaxChance / Mining.doubleDropsMaxLevel) * (SkillTools.skillCheck(mcMMOPlayer.getProfile().getSkillLevel(SkillType.MINING), Mining.doubleDropsMaxLevel)));
Misc.randomDropItem(location, item, chance);
}
}
protected void eventCancellationAndProcessing() {
event.setCancelled(true);
block.setType(Material.AIR);
}
protected void sendAbilityMessage() {
manager.getMcMMOPlayer().getPlayer().sendMessage(LocaleLoader.getString("Smelting.FluxMining.Success"));
}
}

View File

@@ -1,23 +0,0 @@
package com.gmail.nossr50.skills.smelting;
import org.bukkit.event.inventory.FurnaceBurnEvent;
public class FuelEfficiencyEventHandler {
private SmeltingManager manager;
private FurnaceBurnEvent event;
private double burnModifier;
protected FuelEfficiencyEventHandler(SmeltingManager manager, FurnaceBurnEvent event) {
this.manager = manager;
this.event = event;
}
protected void calculateBurnModifier() {
this.burnModifier = 1 + (((double) manager.getSkillLevel() / Smelting.burnModifierMaxLevel) * Smelting.burnTimeMultiplier);
}
protected void modifyBurnTime() {
int burnTime = event.getBurnTime();
event.setBurnTime((int)(burnTime * burnModifier));
}
}

View File

@@ -1,55 +0,0 @@
package com.gmail.nossr50.skills.smelting;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.FurnaceSmeltEvent;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Permissions;
public class SmeltResourceEventHandler {
private SmeltingManager manager;
private FurnaceSmeltEvent event;
protected int skillModifier;
protected SmeltResourceEventHandler(SmeltingManager manager, FurnaceSmeltEvent event) {
this.manager = manager;
this.event = event;
}
protected void calculateSkillModifier() {
this.skillModifier = SkillTools.skillCheck(manager.getSkillLevel(), Smelting.secondSmeltMaxLevel);
}
protected void handleXPGain() {
Material sourceType = event.getSource().getType();
int xp = Config.getInstance().getXp(SkillType.SMELTING, sourceType);
if (sourceType == Material.GLOWING_REDSTONE_ORE) {
xp = Config.getInstance().getXp(SkillType.SMELTING, Material.REDSTONE_ORE);
}
McMMOPlayer mcMMOPlayer = manager.getMcMMOPlayer();
Player player = mcMMOPlayer.getPlayer();
if (Permissions.skillEnabled(player, SkillType.MINING)) {
mcMMOPlayer.beginXpGain(SkillType.MINING, xp / 2);
}
if (Permissions.skillEnabled(player, SkillType.REPAIR)) {
mcMMOPlayer.beginXpGain(SkillType.REPAIR, xp / 2);
}
}
protected void handleBonusSmelts() {
ItemStack result = event.getResult();
result.setAmount(result.getAmount() + 1);
event.setResult(result);
}
}

View File

@@ -1,8 +1,44 @@
package com.gmail.nossr50.skills.smelting;
import org.bukkit.Material;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.skills.utilities.SkillType;
public class Smelting {
// The order of the values is extremely important, a few methods depend on it to work properly
protected enum Tier {
FIVE(5) {
@Override public int getLevel() {return AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank5Level();}
@Override public int getVanillaXPBoostModifier() {return AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank5Multiplier();}},
FOUR(4) {
@Override public int getLevel() {return AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank4Level();}
@Override public int getVanillaXPBoostModifier() {return AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank4Multiplier();}},
THREE(3) {
@Override public int getLevel() {return AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank3Level();}
@Override public int getVanillaXPBoostModifier() {return AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank3Multiplier();}},
TWO(2) {
@Override public int getLevel() {return AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank2Level();}
@Override public int getVanillaXPBoostModifier() {return AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank2Multiplier();}},
ONE(1) {
@Override public int getLevel() {return AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank1Level();}
@Override public int getVanillaXPBoostModifier() {return AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank1Multiplier();}};
int numerical;
private Tier(int numerical) {
this.numerical = numerical;
}
public int toNumerical() {
return numerical;
}
abstract protected int getLevel();
abstract protected int getVanillaXPBoostModifier();
}
public static int burnModifierMaxLevel = AdvancedConfig.getInstance().getBurnModifierMaxLevel();
public static double burnTimeMultiplier = AdvancedConfig.getInstance().getBurnTimeMultiplier();
@@ -12,15 +48,13 @@ public class Smelting {
public static int fluxMiningUnlockLevel = AdvancedConfig.getInstance().getFluxMiningUnlockLevel();
public static double fluxMiningChance = AdvancedConfig.getInstance().getFluxMiningChance();
public static int vanillaXPBoostRank1Level = AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank1Level();
public static int vanillaXPBoostRank2Level = AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank2Level();
public static int vanillaXPBoostRank3Level = AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank3Level();
public static int vanillaXPBoostRank4Level = AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank4Level();
public static int vanillaXPBoostRank5Level = AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank5Level();
protected static int getResourceXp(Material resourceType) {
int xp = Config.getInstance().getXp(SkillType.SMELTING, resourceType);
public static int vanillaXPBoostRank1Multiplier = AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank1Multiplier();
public static int vanillaXPBoostRank2Multiplier = AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank2Multiplier();
public static int vanillaXPBoostRank3Multiplier = AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank3Multiplier();
public static int vanillaXPBoostRank4Multiplier = AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank4Multiplier();
public static int vanillaXPBoostRank5Multiplier = AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank5Multiplier();
if (resourceType == Material.GLOWING_REDSTONE_ORE) {
xp = Config.getInstance().getXp(SkillType.SMELTING, Material.REDSTONE_ORE);
}
return xp;
}
}

View File

@@ -1,7 +1,9 @@
package com.gmail.nossr50.skills.smelting;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.SkillCommand;
import com.gmail.nossr50.skills.SkillManagerStore;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Permissions;
@@ -11,7 +13,7 @@ public class SmeltingCommand extends SkillCommand {
private String secondSmeltChanceLucky;
private String fluxMiningChance;
private String fluxMiningChanceLucky;
private String vanillaXPModifier;
private int vanillaXPModifier;
private boolean canFuelEfficiency;
private boolean canSecondSmelt;
@@ -38,21 +40,7 @@ public class SmeltingCommand extends SkillCommand {
fluxMiningChanceLucky = fluxMiningStrings[1];
//VANILLA XP BOOST
if (skillValue >= Smelting.vanillaXPBoostRank5Level) {
vanillaXPModifier = String.valueOf(Smelting.vanillaXPBoostRank5Multiplier);
}
else if (skillValue >= Smelting.vanillaXPBoostRank4Level) {
vanillaXPModifier = String.valueOf(Smelting.vanillaXPBoostRank4Multiplier);
}
else if (skillValue >= Smelting.vanillaXPBoostRank3Level) {
vanillaXPModifier = String.valueOf(Smelting.vanillaXPBoostRank3Multiplier);
}
else if (skillValue >= Smelting.vanillaXPBoostRank2Level) {
vanillaXPModifier = String.valueOf(Smelting.vanillaXPBoostRank2Multiplier);
}
else {
vanillaXPModifier = String.valueOf(Smelting.vanillaXPBoostRank1Multiplier);
}
vanillaXPModifier = SkillManagerStore.getInstance().getSmeltingManager(player.getName()).getVanillaXpMultiplier();
}
@Override
@@ -110,8 +98,8 @@ public class SmeltingCommand extends SkillCommand {
}
if (canVanillaXPBoost) {
if (skillValue < Smelting.vanillaXPBoostRank1Level) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Smelting.Ability.Locked.0", Smelting.vanillaXPBoostRank1Level)));
if (skillValue < AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank1Level()) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Smelting.Ability.Locked.0", AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank1Level())));
}
else {
player.sendMessage(LocaleLoader.getString("Smelting.Ability.VanillaXPBoost", vanillaXPModifier));

View File

@@ -1,85 +1,132 @@
package com.gmail.nossr50.skills.smelting;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockState;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.inventory.FurnaceBurnEvent;
import org.bukkit.event.inventory.FurnaceExtractEvent;
import org.bukkit.event.inventory.FurnaceSmeltEvent;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.mining.Mining;
import com.gmail.nossr50.skills.smelting.Smelting.Tier;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.BlockChecks;
import com.gmail.nossr50.util.ItemChecks;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
public class SmeltingManager extends SkillManager {
public SmeltingManager(McMMOPlayer mcMMOPlayer) {
super(mcMMOPlayer, SkillType.SMELTING);
}
public boolean canUseFluxMining(BlockState blockState) {
Player player = getPlayer();
ItemStack heldItem = player.getItemInHand();
return BlockChecks.affectedByFluxMining(blockState) && ItemChecks.isPickaxe(heldItem) && !heldItem.containsEnchantment(Enchantment.SILK_TOUCH) && Permissions.fluxMining(player) && !mcMMO.placeStore.isTrue(blockState);
}
public boolean canUseVanillaXpBoost() {
Player player = getPlayer();
return SkillTools.unlockLevelReached(player, skill, Smelting.Tier.ONE.getLevel()) && Permissions.vanillaXpBoost(player, skill);
}
/**
* Process the Flux Mining ability.
*
* @param blockState The {@link BlockState} to check ability activation for
* @return true if the ability was successful, false otherwise
*/
public boolean processFluxMining(BlockState blockState) {
Player player = getPlayer();
if (SkillTools.unlockLevelReached(player, skill, Smelting.fluxMiningUnlockLevel) && SkillTools.activationSuccessful(player, skill, Smelting.fluxMiningChance)) {
ItemStack item = null;
switch (blockState.getType()) {
case IRON_ORE:
item = new ItemStack(Material.IRON_INGOT);
break;
case GOLD_ORE:
item = new ItemStack(Material.GOLD_INGOT);
break;
default:
break;
}
if (item == null) {
return false;
}
Location location = blockState.getLocation();
Misc.dropItem(location, item);
if (Permissions.doubleDrops(player, skill) && SkillTools.activationSuccessful(player, skill, Mining.doubleDropsMaxChance, Mining.doubleDropsMaxLevel)) {
Misc.dropItem(location, item);
}
blockState.setRawData((byte) 0x0);
blockState.setType(Material.AIR);
player.sendMessage(LocaleLoader.getString("Smelting.FluxMining.Success"));
return true;
}
return false;
}
/**
* Increases burn time for furnace fuel.
*
* @param event The {@link FurnaceBurnEvent} to modify.
* @param burnTime The initial burn time from the {@link FurnaceBurnEvent}
*/
public void fuelEfficiency(FurnaceBurnEvent event) {
Player player = mcMMOPlayer.getPlayer();
public int fuelEfficiency(int burnTime) {
double burnModifier = 1 + (((double) getSkillLevel() / Smelting.burnModifierMaxLevel) * Smelting.burnTimeMultiplier);
if (Misc.isNPCEntity(player) || !Permissions.fuelEfficiency(player)) {
return;
}
FuelEfficiencyEventHandler eventHandler = new FuelEfficiencyEventHandler(this, event);
eventHandler.calculateBurnModifier();
eventHandler.modifyBurnTime();
return (int) (burnTime * burnModifier);
}
public void smeltProcessing(FurnaceSmeltEvent event) {
Player player = mcMMOPlayer.getPlayer();
public ItemStack smeltProcessing(Material resourceType, ItemStack result) {
Player player = getPlayer();
if (Misc.isNPCEntity(player)) {
return;
applyXpGain(Smelting.getResourceXp(resourceType));
if (Permissions.doubleDrops(player, skill) && SkillTools.activationSuccessful(player, skill, Smelting.secondSmeltMaxChance, Smelting.secondSmeltMaxLevel)) {
ItemStack newResult = new ItemStack(result.getType(), result.getAmount() + 1);
return newResult;
}
SmeltResourceEventHandler eventHandler = new SmeltResourceEventHandler(this, event);
if (Permissions.skillEnabled(player, skill)) {
eventHandler.handleXPGain();
}
if (!Permissions.doubleDrops(player, skill)) {
return;
}
eventHandler.calculateSkillModifier();
double chance = (Smelting.secondSmeltMaxChance / Smelting.secondSmeltMaxLevel) * eventHandler.skillModifier;
if (chance > Misc.getRandom().nextInt(activationChance)) {
eventHandler.handleBonusSmelts();
}
return result;
}
public void fluxMining(BlockBreakEvent event) {
if (skillLevel < Smelting.fluxMiningUnlockLevel) {
return;
}
if (Smelting.fluxMiningChance > Misc.getRandom().nextInt(activationChance)) {
FluxMiningEventHandler eventHandler = new FluxMiningEventHandler(this, event);
eventHandler.processDrops();
eventHandler.eventCancellationAndProcessing();
eventHandler.sendAbilityMessage();
}
public int vanillaXPBoost(int experience) {
return experience * getVanillaXpMultiplier();
}
public void vanillaXPBoost(FurnaceExtractEvent event) {
if (skillLevel < Smelting.vanillaXPBoostRank1Level || !Permissions.vanillaXpBoost(mcMMOPlayer.getPlayer(), skill)) {
return;
/**
* Gets the vanilla XP multiplier
*
* @return the vanilla XP multiplier
*/
protected int getVanillaXpMultiplier() {
int skillLevel = getSkillLevel();
for (Tier tier : Tier.values()) {
if (skillLevel >= tier.getLevel()) {
return tier.getVanillaXPBoostModifier();
}
}
SmeltingVanillaXPEventHandler eventHandler = new SmeltingVanillaXPEventHandler(this, event);
eventHandler.calculateModifier();
eventHandler.modifyVanillaXP();
return 0;
}
}

View File

@@ -1,39 +0,0 @@
package com.gmail.nossr50.skills.smelting;
import org.bukkit.event.inventory.FurnaceExtractEvent;
public class SmeltingVanillaXPEventHandler {
private SmeltingManager manager;
private FurnaceExtractEvent event;
private int xpBoostModifier;
protected SmeltingVanillaXPEventHandler(SmeltingManager manager, FurnaceExtractEvent event) {
this.manager = manager;
this.event = event;
}
protected void calculateModifier() {
int skillLevel = manager.getSkillLevel();
if (skillLevel >= Smelting.vanillaXPBoostRank5Level) {
xpBoostModifier = Smelting.vanillaXPBoostRank5Multiplier;
}
else if (skillLevel >= Smelting.vanillaXPBoostRank4Level) {
xpBoostModifier = Smelting.vanillaXPBoostRank4Multiplier;
}
else if (skillLevel >= Smelting.vanillaXPBoostRank3Level) {
xpBoostModifier = Smelting.vanillaXPBoostRank3Multiplier;
}
else if (skillLevel >= Smelting.vanillaXPBoostRank2Level) {
xpBoostModifier = Smelting.vanillaXPBoostRank2Multiplier;
}
else {
xpBoostModifier = Smelting.vanillaXPBoostRank1Multiplier;
}
}
protected void modifyVanillaXP() {
int xp = event.getExpToDrop();
event.setExpToDrop(xp * xpBoostModifier);
}
}

View File

@@ -1,56 +0,0 @@
package com.gmail.nossr50.skills.swords;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.runnables.BleedTimer;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.util.Users;
public class BleedEventHandler {
private McMMOPlayer mcMMOPlayer;
private int skillLevel;
private LivingEntity defender;
protected int skillModifier;
protected BleedEventHandler(SwordsManager manager, LivingEntity defender) {
this.mcMMOPlayer = manager.getMcMMOPlayer();
this.skillLevel = manager.getSkillLevel();
this.defender = defender;
calculateSkillModifier();
}
protected void calculateSkillModifier() {
this.skillModifier = SkillTools.skillCheck(skillLevel, Swords.bleedMaxBonusLevel);
}
protected void addBleedTicks() {
int bleedTicks;
if (skillLevel >= Swords.bleedMaxBonusLevel) {
bleedTicks = Swords.bleedMaxTicks;
}
else {
bleedTicks = Swords.bleedBaseTicks;
}
BleedTimer.add(defender, bleedTicks);
}
protected void sendAbilityMessages() {
if (mcMMOPlayer.getProfile().useChatNotifications()) {
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Swords.Combat.Bleeding"));
}
if (defender instanceof Player) {
Player defendingPlayer = (Player) defender;
if (Users.getPlayer(defendingPlayer).getProfile().useChatNotifications()) {
defendingPlayer.sendMessage(LocaleLoader.getString("Swords.Combat.Bleeding.Started"));
}
}
}
}

View File

@@ -1,37 +0,0 @@
package com.gmail.nossr50.skills.swords;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.CombatTools;
import com.gmail.nossr50.skills.utilities.SkillTools;
public class CounterAttackEventHandler {
private SwordsManager manager;
private LivingEntity attacker;
private int damage;
protected int skillModifier;
protected CounterAttackEventHandler(SwordsManager manager, LivingEntity attacker, int damage) {
this.manager = manager;
this.attacker = attacker;
this.damage = damage;
}
protected void calculateSkillModifier() {
this.skillModifier = SkillTools.skillCheck(manager.getSkillLevel(), Swords.counterAttackMaxBonusLevel);
}
protected void dealDamage() {
CombatTools.dealDamage(attacker, damage / Swords.counterAttackModifier);
}
protected void sendAbilityMessages() {
manager.getMcMMOPlayer().getPlayer().sendMessage(LocaleLoader.getString("Swords.Combat.Countered"));
if (attacker instanceof Player) {
((Player) attacker).sendMessage(LocaleLoader.getString("Swords.Combat.Counter.Hit"));
}
}
}

View File

@@ -1,24 +0,0 @@
package com.gmail.nossr50.skills.swords;
import org.bukkit.entity.LivingEntity;
import com.gmail.nossr50.skills.runnables.BleedTimer;
import com.gmail.nossr50.skills.utilities.CombatTools;
import com.gmail.nossr50.skills.utilities.SkillType;
public class SerratedStrikesEventHandler {
private SwordsManager manager;
private LivingEntity target;
private int damage;
protected SerratedStrikesEventHandler(SwordsManager manager, LivingEntity target, int damage) {
this.manager = manager;
this.target = target;
this.damage = damage;
}
protected void applyAbilityEffects() {
CombatTools.applyAbilityAoE(manager.getMcMMOPlayer().getPlayer(), target, damage / Swords.serratedStrikesModifier, SkillType.SWORDS);
BleedTimer.add(target, Swords.serratedStrikesBleedTicks);
}
}

View File

@@ -1,11 +1,16 @@
package com.gmail.nossr50.skills.swords;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.runnables.BleedTimer;
import com.gmail.nossr50.skills.utilities.CombatTools;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Users;
public class SwordsManager extends SkillManager {
public SwordsManager(McMMOPlayer mcMMOPlayer) {
@@ -15,35 +20,48 @@ public class SwordsManager extends SkillManager {
/**
* Check for Bleed effect.
*
* @param defender The defending entity
* @param target The defending entity
*/
public void bleedCheck(LivingEntity defender) {
BleedEventHandler eventHandler = new BleedEventHandler(this, defender);
public void bleedCheck(LivingEntity target) {
Player player = getPlayer();
float chance = (float) ((Swords.bleedMaxChance / Swords.bleedMaxBonusLevel) * skillLevel);
if (chance > Swords.bleedMaxChance) chance = (float) Swords.bleedMaxChance;
if (SkillTools.activationSuccessful(player, skill, Swords.bleedMaxChance, Swords.bleedMaxBonusLevel)) {
if (chance > Misc.getRandom().nextInt(activationChance)) {
eventHandler.addBleedTicks();
eventHandler.sendAbilityMessages();
if (getSkillLevel() >= Swords.bleedMaxBonusLevel) {
BleedTimer.add(target, Swords.bleedMaxTicks);
}
else {
BleedTimer.add(target, Swords.bleedBaseTicks);
}
if (getProfile().useChatNotifications()) {
player.sendMessage(LocaleLoader.getString("Swords.Combat.Bleeding"));
}
if (target instanceof Player) {
Player defender = (Player) target;
if (Users.getPlayer(defender).getProfile().useChatNotifications()) {
defender.sendMessage(LocaleLoader.getString("Swords.Combat.Bleeding.Started"));
}
}
}
}
public void counterAttackChecks(LivingEntity attacker, int damage) {
CounterAttackEventHandler eventHandler = new CounterAttackEventHandler(this, attacker, damage);
eventHandler.calculateSkillModifier();
if (SkillTools.activationSuccessful(getPlayer(), skill, Swords.counterAttackMaxChance, Swords.counterAttackMaxBonusLevel)) {
CombatTools.dealDamage(attacker, damage / Swords.counterAttackModifier);
float chance = (float) ((Swords.counterAttackMaxChance / Swords.counterAttackMaxBonusLevel) * skillLevel);
if (chance > Swords.counterAttackMaxChance) chance = (float) Swords.counterAttackMaxChance;
getPlayer().sendMessage(LocaleLoader.getString("Swords.Combat.Countered"));
if (chance > Misc.getRandom().nextInt(activationChance)) {
eventHandler.dealDamage();
eventHandler.sendAbilityMessages();
if (attacker instanceof Player) {
((Player) attacker).sendMessage(LocaleLoader.getString("Swords.Combat.Counter.Hit"));
}
}
}
public void serratedStrikes(LivingEntity target, int damage) {
SerratedStrikesEventHandler eventHandler = new SerratedStrikesEventHandler(this, target, damage);
eventHandler.applyAbilityEffects();
CombatTools.applyAbilityAoE(getPlayer(), target, damage / Swords.serratedStrikesModifier, skill);
BleedTimer.add(target, Swords.serratedStrikesBleedTicks);
}
}

View File

@@ -67,7 +67,7 @@ public class CallOfTheWildEventHandler {
return;
LivingEntity entity = (LivingEntity) player.getWorld().spawnEntity(player.getLocation(), type);
entity.setMetadata(mcMMO.entityMetadataKey, mcMMO.entityMetadata);
entity.setMetadata(mcMMO.entityMetadataKey, mcMMO.metadataValue);
((Tameable) entity).setOwner(player);

View File

@@ -1,35 +0,0 @@
package com.gmail.nossr50.skills.taming;
import org.bukkit.entity.Player;
import org.bukkit.entity.Wolf;
import org.bukkit.event.entity.EntityDamageEvent;
import com.gmail.nossr50.locale.LocaleLoader;
public class EnvironmentallyAwareEventHandler {
private Player player;
private EntityDamageEvent event;
private Wolf wolf;
protected EnvironmentallyAwareEventHandler(TamingManager manager, EntityDamageEvent event) {
this.player = manager.getMcMMOPlayer().getPlayer();
this.event = event;
this.wolf = (Wolf) event.getEntity();
}
protected void teleportWolf() {
if (event.getDamage() > wolf.getHealth()) {
return;
}
wolf.teleport(player.getLocation());
}
protected void sendAbilityMessage() {
player.sendMessage(LocaleLoader.getString("Taming.Listener.Wolf"));
}
protected void cancelEvent() {
event.setCancelled(true);
}
}

View File

@@ -1,15 +0,0 @@
package com.gmail.nossr50.skills.taming;
import org.bukkit.event.entity.EntityDamageEvent;
public class ShockProofEventHandler {
private EntityDamageEvent event;
protected ShockProofEventHandler (EntityDamageEvent event) {
this.event = event;
}
protected void modifyEventDamage() {
event.setDamage(event.getDamage() / Taming.shockProofModifier);
}
}

View File

@@ -1,10 +1,21 @@
package com.gmail.nossr50.skills.taming;
import org.bukkit.EntityEffect;
import org.bukkit.entity.AnimalTamer;
import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Wolf;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Permissions;
public class Taming {
public static int environmentallyAwareUnlockLevel = AdvancedConfig.getInstance().getEnviromentallyAwareUnlock();
public static int holyHoundUnlockLevel = AdvancedConfig.getInstance().getHolyHoundUnlock();
public static double fastFoodServiceActivationChance = AdvancedConfig.getInstance().getFastFoodChance();
public static int fastFoodServiceUnlockLevel = AdvancedConfig.getInstance().getFastFoodUnlock();
@@ -25,4 +36,55 @@ public class Taming {
public static int wolfXp = Config.getInstance().getTamingXPWolf();
public static int ocelotXp = Config.getInstance().getTamingXPOcelot();
public static boolean canPreventDamage(Tameable pet, AnimalTamer owner) {
return pet.isTamed() && owner instanceof Player && pet instanceof Wolf;
}
public static boolean canUseThickFur(Player player) {
return SkillTools.unlockLevelReached(player, SkillType.TAMING, thickFurUnlockLevel) && Permissions.thickFur(player);
}
public static boolean canUseEnvironmentallyAware(Player player) {
return SkillTools.unlockLevelReached(player, SkillType.TAMING, environmentallyAwareUnlockLevel) && Permissions.environmentallyAware(player);
}
public static boolean canUseShockProof(Player player) {
return SkillTools.unlockLevelReached(player, SkillType.TAMING, shockProofUnlockLevel) && Permissions.shockProof(player);
}
public static boolean canUseHolyHound(Player player) {
return SkillTools.unlockLevelReached(player, SkillType.TAMING, holyHoundUnlockLevel) && Permissions.holyHound(player);
}
public static int processThickFur(Wolf wolf, int damage) {
wolf.playEffect(EntityEffect.WOLF_SHAKE);
return damage / thickFurModifier;
}
public static void processThickFurFire(Wolf wolf) {
wolf.playEffect(EntityEffect.WOLF_SMOKE);
wolf.setFireTicks(0);
}
public static void processEnvironmentallyAware(Player player, Wolf wolf, int damage) {
if (damage > wolf.getHealth()) {
return;
}
wolf.teleport(player);
player.sendMessage(LocaleLoader.getString("Taming.Listener.Wolf"));
}
public static int processShockProof(Wolf wolf, int damage) {
wolf.playEffect(EntityEffect.WOLF_SHAKE);
return damage / shockProofModifier;
}
public static void processHolyHound(Wolf wolf, int damage) {
int modifiedHealth = Math.min(wolf.getHealth() + damage, wolf.getMaxHealth());
wolf.setHealth(modifiedHealth);
wolf.playEffect(EntityEffect.WOLF_HEARTS);
}
}

View File

@@ -18,6 +18,7 @@ public class TamingCommand extends SkillCommand {
private boolean canShockProof;
private boolean canCallWild;
private boolean canFastFood;
private boolean canHolyHound;
public TamingCommand() {
super(SkillType.TAMING);
@@ -40,11 +41,12 @@ public class TamingCommand extends SkillCommand {
canSharpenedClaws = Permissions.sharpenedClaws(player);
canShockProof = Permissions.shockProof(player);
canThickFur = Permissions.thickFur(player);
canHolyHound = Permissions.holyHound(player);
}
@Override
protected boolean effectsHeaderPermissions() {
return canBeastLore || canCallWild || canEnvironmentallyAware || canFastFood || canGore || canSharpenedClaws || canShockProof || canThickFur;
return canBeastLore || canCallWild || canEnvironmentallyAware || canFastFood || canGore || canSharpenedClaws || canShockProof || canThickFur || canHolyHound;
}
@Override
@@ -79,6 +81,10 @@ public class TamingCommand extends SkillCommand {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Taming.Effect.16"), LocaleLoader.getString("Taming.Effect.17")));
}
if (canHolyHound) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Taming.Effect.18"), LocaleLoader.getString("Taming.Effect.19")));
}
if (canCallWild) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Taming.Effect.12"), LocaleLoader.getString("Taming.Effect.13")));
player.sendMessage(LocaleLoader.getString("Taming.Effect.14", Config.getInstance().getTamingCOTWOcelotCost()));
@@ -88,7 +94,7 @@ public class TamingCommand extends SkillCommand {
@Override
protected boolean statsHeaderPermissions() {
return canEnvironmentallyAware || canFastFood || canGore || canSharpenedClaws || canShockProof || canThickFur;
return canEnvironmentallyAware || canFastFood || canGore || canSharpenedClaws || canShockProof || canThickFur || canHolyHound;
}
@Override
@@ -120,6 +126,15 @@ public class TamingCommand extends SkillCommand {
}
}
if (canHolyHound) {
if (skillValue < Taming.holyHoundUnlockLevel) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Taming.Ability.Locked.5", Taming.holyHoundUnlockLevel)));
}
else {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Taming.Ability.Bonus.10"), LocaleLoader.getString("Taming.Ability.Bonus.11")));
}
}
if (canShockProof) {
if (skillValue < Taming.shockProofUnlockLevel) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Taming.Ability.Locked.2", Taming.shockProofUnlockLevel)));

View File

@@ -4,7 +4,6 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Wolf;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityTameEvent;
import org.bukkit.inventory.ItemStack;
@@ -12,6 +11,7 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
@@ -26,25 +26,18 @@ public class TamingManager extends SkillManager {
*
* @param event The event to award XP for
*/
public void awardTamingXP(EntityTameEvent event) {
if (event.getEntity() == null) {
return;
}
else if (event.getEntity().hasMetadata(mcMMO.entityMetadataKey)) {
return;
}
switch (event.getEntityType()) {
public void awardTamingXP(LivingEntity entity) {
switch (entity.getType()) {
case WOLF:
mcMMOPlayer.beginXpGain(SkillType.TAMING, Taming.wolfXp);
break;
applyXpGain(Taming.wolfXp);
return;
case OCELOT:
mcMMOPlayer.beginXpGain(SkillType.TAMING, Taming.ocelotXp);
break;
applyXpGain(Taming.ocelotXp);
return;
default:
break;
return;
}
}
@@ -55,10 +48,15 @@ public class TamingManager extends SkillManager {
* @param damage The damage being absorbed by the wolf
*/
public void fastFoodService(Wolf wolf, int damage) {
if (Misc.getRandom().nextInt(activationChance) < Taming.fastFoodServiceActivationChance) {
FastFoodServiceEventHandler eventHandler = new FastFoodServiceEventHandler(wolf);
if (SkillTools.activationSuccessful(getPlayer(), skill, Taming.fastFoodServiceActivationChance)) {
eventHandler.modifyHealth(damage);
int health = wolf.getHealth();
int maxHealth = wolf.getMaxHealth();
if (health < maxHealth) {
int newHealth = health + damage;
wolf.setHealth(Math.min(newHealth, maxHealth));
}
}
}
@@ -80,7 +78,7 @@ public class TamingManager extends SkillManager {
public void gore(EntityDamageEvent event) {
GoreEventHandler eventHandler = new GoreEventHandler(this, event);
float chance = (float) ((Taming.goreMaxChance / Taming.goreMaxBonusLevel) * skillLevel);
float chance = (float) ((Taming.goreMaxChance / Taming.goreMaxBonusLevel) * getSkillLevel());
if (chance > Taming.goreMaxChance) chance = (float) Taming.goreMaxChance;
if (chance > Misc.getRandom().nextInt(activationChance)) {
@@ -90,39 +88,6 @@ public class TamingManager extends SkillManager {
}
}
/**
* Prevent damage to wolves based on various skills.
*
* @param event The event to modify
*/
public void preventDamage(EntityDamageEvent event) {
DamageCause cause = event.getCause();
switch (cause) {
case CONTACT:
case LAVA:
case FIRE:
case FALL:
environmentallyAware(event, cause);
break;
case ENTITY_ATTACK:
case FIRE_TICK:
case PROJECTILE:
thickFur(event, cause);
break;
case BLOCK_EXPLOSION:
case ENTITY_EXPLOSION:
case LIGHTNING:
shockProof(event);
break;
default:
break;
}
}
/**
* Summon an ocelot to your side.
*/
@@ -177,57 +142,4 @@ public class TamingManager extends SkillManager {
eventHandler.sendSuccessMessage();
}
}
/**
* Handle the Environmentally Aware ability.
*
* @param event The event to modify
* @param cause The damage cause of the event
*/
private void environmentallyAware(EntityDamageEvent event, DamageCause cause) {
if (skillLevel >= Taming.environmentallyAwareUnlockLevel && Permissions.environmentallyAware(mcMMOPlayer.getPlayer())) {
EnvironmentallyAwareEventHandler eventHandler = new EnvironmentallyAwareEventHandler(this, event);
switch (cause) {
case CONTACT:
case FIRE:
case LAVA:
eventHandler.teleportWolf();
eventHandler.sendAbilityMessage();
break;
case FALL:
eventHandler.cancelEvent();
break;
default:
break;
}
}
}
/**
* Handle the Thick Fur ability.
*
* @param event The event to modify
* @param cause The damage cause of the event
*/
private void thickFur(EntityDamageEvent event, DamageCause cause) {
if (skillLevel >= Taming.thickFurUnlockLevel && Permissions.thickFur(mcMMOPlayer.getPlayer())) {
ThickFurEventHandler eventHandler = new ThickFurEventHandler(event, cause);
eventHandler.modifyEventDamage();
}
}
/**
* Handle the Shock Proof ability.
*
* @param event The event to modify
*/
private void shockProof(EntityDamageEvent event) {
if (skillLevel >= Taming.shockProofUnlockLevel && Permissions.shockProof(mcMMOPlayer.getPlayer())) {
ShockProofEventHandler eventHandler = new ShockProofEventHandler(event);
eventHandler.modifyEventDamage();
}
}
}

View File

@@ -1,33 +0,0 @@
package com.gmail.nossr50.skills.taming;
import org.bukkit.entity.Wolf;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
public class ThickFurEventHandler {
private DamageCause cause;
private EntityDamageEvent event;
private Wolf wolf;
protected ThickFurEventHandler (EntityDamageEvent event, DamageCause cause) {
this.cause = cause;
this.event = event;
this.wolf = (Wolf) event.getEntity();
}
protected void modifyEventDamage() {
switch (cause) {
case FIRE_TICK:
wolf.setFireTicks(0);
break;
case ENTITY_ATTACK:
case PROJECTILE:
event.setDamage(event.getDamage() / Taming.thickFurModifier);
break;
default:
break;
}
}
}

View File

@@ -1,31 +0,0 @@
package com.gmail.nossr50.skills.unarmed;
import org.bukkit.event.entity.EntityDamageEvent;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.SkillTools;
public class DeflectEventHandler {
private UnarmedManager manager;
private EntityDamageEvent event;
protected int skillModifier;
protected DeflectEventHandler(UnarmedManager manager, EntityDamageEvent event) {
this.manager = manager;
this.event = event;
calculateSkillModifier();
}
protected void calculateSkillModifier() {
this.skillModifier = SkillTools.skillCheck(manager.getSkillLevel(), Unarmed.deflectMaxBonusLevel);
}
protected void sendAbilityMessage() {
manager.getMcMMOPlayer().getPlayer().sendMessage(LocaleLoader.getString("Combat.ArrowDeflect"));
}
protected void cancelEvent() {
event.setCancelled(true);
}
}

View File

@@ -1,48 +0,0 @@
package com.gmail.nossr50.skills.unarmed;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.events.skills.McMMOPlayerDisarmEvent;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.util.Misc;
public class DisarmEventHandler {
private UnarmedManager manager;
private Player defender;
private ItemStack inHand;
protected int skillModifier;
protected DisarmEventHandler(UnarmedManager manager, Player defender) {
this.manager = manager;
this.defender = defender;
this.inHand = defender.getItemInHand();
}
protected boolean isHoldingItem() {
return (inHand.getType() != Material.AIR);
}
protected void calculateSkillModifier() {
this.skillModifier = SkillTools.skillCheck(manager.getSkillLevel(), Unarmed.disarmMaxBonusLevel);
}
private void sendAbilityMessage() {
defender.sendMessage(LocaleLoader.getString("Skills.Disarmed"));
}
protected void handleDisarm() {
McMMOPlayerDisarmEvent event = new McMMOPlayerDisarmEvent(defender);
mcMMO.p.getServer().getPluginManager().callEvent(event);
if(!event.isCancelled()) {
Misc.dropItem(defender.getLocation(), inHand);
defender.setItemInHand(new ItemStack(Material.AIR));
sendAbilityMessage();
}
}
}

View File

@@ -1,30 +0,0 @@
package com.gmail.nossr50.skills.unarmed;
import org.bukkit.entity.Player;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Users;
public class IronGripEventHandler {
private UnarmedManager manager;
private Player defender;
protected int skillModifier;
protected IronGripEventHandler(UnarmedManager manager, Player defender) {
this.manager = manager;
this.defender = defender;
calculateSkillModifier();
}
protected void calculateSkillModifier() {
this.skillModifier = SkillTools.skillCheck(Users.getPlayer(defender).getProfile().getSkillLevel(SkillType.UNARMED), Unarmed.ironGripMaxBonusLevel);
}
protected void sendAbilityMessages() {
defender.sendMessage(LocaleLoader.getString("Unarmed.Ability.IronGrip.Defender"));
manager.getMcMMOPlayer().getPlayer().sendMessage(LocaleLoader.getString("Unarmed.Ability.IronGrip.Attacker"));
}
}

View File

@@ -1,7 +1,7 @@
package com.gmail.nossr50.skills.unarmed;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import com.gmail.nossr50.config.AdvancedConfig;
@@ -25,20 +25,22 @@ public class Unarmed {
public static double berserkDamageModifier = 1.5;
public static void blockCracker(Player player, Block block) {
if (SkillTools.blockBreakSimulate(block, player, false)) {
Material type = block.getType();
public static boolean blockCracker(Player player, BlockState blockState) {
if (SkillTools.blockBreakSimulate(blockState.getBlock(), player, false)) {
Material type = blockState.getType();
switch (type) {
case SMOOTH_BRICK:
if (blockCrackerSmoothBrick && block.getData() == 0x0) {
block.setData((byte) 0x2);
if (blockCrackerSmoothBrick && blockState.getRawData() == (byte) 0x0) {
blockState.setRawData((byte) 0x2);
}
return;
return true;
default:
return;
return false;
}
}
return false;
}
}

View File

@@ -1,32 +0,0 @@
package com.gmail.nossr50.skills.unarmed;
import org.bukkit.event.entity.EntityDamageEvent;
public class UnarmedBonusDamageEventHandler {
private UnarmedManager manager;
private EntityDamageEvent event;
protected int damageBonus;
protected UnarmedBonusDamageEventHandler(UnarmedManager manager, EntityDamageEvent event) {
this.manager = manager;
this.event = event;
}
protected void calculateDamageBonus() {
int damageBonus = 3 + (manager.getSkillLevel() / Unarmed.ironArmIncreaseLevel);
if (damageBonus > Unarmed.ironArmMaxBonusDamage) {
damageBonus = Unarmed.ironArmMaxBonusDamage;
}
this.damageBonus = damageBonus;
}
protected void modifyEventDamage() {
int damage = event.getDamage();
int unarmedBonus = damage + damageBonus;
event.setDamage(damage + unarmedBonus);
}
}

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