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

Compare commits

..

25 Commits

Author SHA1 Message Date
t00thpick1
4c4def2a23 This entirely untested and made on a whim patch may or may not fix database lockups due to seperate threads accessing the db connection at the same time 2014-07-03 00:46:09 -04:00
TfT_02
2b9b5df1ee Alter original event and stop firing FakeDamageEvents
Fixes #2105
2014-07-02 11:28:21 +02:00
TfT_02
e7e62b8d40 SecondaryAbilityEvent now implements Cancellable
Fire SecondaryAbilityEvent for abilities with static chances

Also cleanup some of the event handling for Armor Impact, Greater
Impact and Fast Food
2014-07-02 11:25:13 +02:00
TfT_02
3d242bbdb6 Always call back events 2014-07-02 11:25:13 +02:00
TfT_02
e796eae3c3 Update for new damage API 2014-07-02 11:25:08 +02:00
TfT_02
a257e83a62 Update for new getOnlinePlayers behavior 2014-06-29 14:04:36 +02:00
Kane York
d527584248 A private method cannot be abstract >.> 2014-06-28 23:49:46 -07:00
Kane York
0a4de6e2fc Reword statement in standards.md 2014-06-28 23:48:12 -07:00
TfT_02
4b20f12eff Fix a NPE with getFlowerAndGrassXp()
Fixes #1975
2014-06-23 22:52:34 +02:00
TfT_02
0de1187012 Fixed setting custom names and lore with treasures 2014-06-22 20:42:48 +02:00
TfT_02
8e474170e4 Fix crafting with items received from Salvage
Only set metadata on Salvage items when it’s not set to -1
Fixes #2078

And cleanup some javadocs in Salvageable
2014-06-18 11:44:21 +02:00
TfT_02
2eeb9b1f35 Set a pretty repair material name in armor.yml
Adds #1863
2014-06-15 17:46:16 +02:00
TfT_02
3de6e2c3f1 Add full Repairable support in armor config files
You can now fully configure armor to be repairable from the armor.yml
config files.

Adds Repair_MinimumLevel and Repair_XpMultiplier to armor.yml
2014-06-15 17:46:16 +02:00
TfT_02
98d166808f Finish the tools.yml header 2014-06-15 17:45:52 +02:00
TfT_02
f75e15dfdc Set a pretty repair material name in tools.yml
Adds #1863
2014-06-15 17:31:50 +02:00
TfT_02
f2b892b7d5 Add full Repairable support in tools config files
You can now fully configure a tool to be repairable from the tools.yml
config files.

Adds Repair_MinimumLevel and Repair_XpMultiplier to tools.yml
2014-06-15 17:28:54 +02:00
TfT_02
883ada01f8 Fix typo with XP_Modifier in tools.default.yml 2014-06-15 17:18:49 +02:00
TfT_02
3a8f45a04d Fix bugs with pistons
This commit improves piston tracking and fixes a couple of bugs with
block tracking.

Fixes #2043
2014-06-15 14:26:02 +02:00
TfT_02
906609696b Workaround a CB bug by tracking piston events
There is a bug in Craftbukkit that causes piston events to fire
multiple times. We need to keep track of the extend and retract events
to see which piston events should be processed.
2014-06-15 14:26:02 +02:00
riking
66ccde4310 MCPC+ is now known as Cauldron 2014-06-14 11:34:35 -07:00
TfT_02
4970cdc3f4 Add mcmmo.skills.salvage permission to plugin.yml
Fixes issue where players would have access to the Salvage child skill
by default.

Mentioned in #2075
2014-06-12 13:42:42 +02:00
TfT_02
1becc874ba Check if input is a water bottle first 2014-06-09 22:55:03 +02:00
TfT_02
b107a8dc7c Fire brew event after outputs have changed
and before experience is granted.
Part 2 of fixing #2041
2014-06-09 02:04:59 +02:00
TfT_02
37aebc1716 Calculate Alchemy XP based on potion stage
Adds #1926
2014-06-09 01:56:07 +02:00
TfT_02
836877ff93 Alchemy should fire BrewEvents
Fixes #2041
2014-06-09 01:43:50 +02:00
45 changed files with 701 additions and 211 deletions

View File

@@ -15,16 +15,25 @@ Version 1.5.01-dev
+ Added support for `MATERIAL|data` format in treasures.yml
+ Added API to experience events to get XP gain reason
+ Added API to check if an entity is bleeding
+ Added options to tools.yml and armor.yml config files to set a pretty repair material name
+ Added full support for repairables in tools.yml and armor.yml config files
= Fixed bug where pistons would mess with the block tracking
= Fixed bug where the Updater was running on the main thread.
= Fixed bug when players would use /ptp without being in a party
= Fixed bug where player didn't have a mcMMOPlayer object in AsyncPlayerChatEvent
= Fixed bug where dodge would check the wrong player skill level
= Fixed bug which causes /party teleport to stop working
= Fixed bug where SaveTimerTask would produce an IndexOutOfBoundsException
= Fixed bug where Alchemy would not fire BrewEvents
= Fixed bug with setting custom names and lore in treasures config
= Fixed bug which would cause a NullPointerException with getFlowerAndGrassXp()
! Changed SecondaryAbilityEvent to implement Cancellable and it now gets fired for damage related secondary abilities
! Changed the way mcMMO handles bonus damage, updated for the new damage event API
! Changed player data saving. Save tasks are now asynchronous
! Vanished players no longer get hit by AoE effects
! Changed Alchemy config option 'Prevent_Hopper_Transfer' renamed to 'Prevent_Hopper_Transfer_Ingredients'
! Changed Alchemy XP distribution. XP is granted based on the stage of the potion.
! Updated for new getOnlinePlayers() behavior
- Removed salvage ability from Repair, salvage has it's own (child) skill now
Version 1.5.00

View File

@@ -65,7 +65,7 @@ public class ArcheryCommand extends SkillCommand {
}
if (canDaze) {
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Archery.Effect.2"), LocaleLoader.getString("Archery.Effect.3", Archery.dazeModifier)));
messages.add(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Archery.Effect.2"), LocaleLoader.getString("Archery.Effect.3", Archery.dazeBonusDamage)));
}
if (canRetrieve) {

View File

@@ -134,7 +134,7 @@ public class AdvancedConfig extends AutoUpdateConfigLoader {
reason.add("Skills.Acrobatics.Daze.MaxBonusLevel should be at least 1!");
}
if (getDazeModifier() < 0) {
if (getDazeBonusDamage() < 0) {
reason.add("Skills.Acrobatics.Daze.BonusDamage should be at least 0!");
}
@@ -714,7 +714,7 @@ public class AdvancedConfig extends AutoUpdateConfigLoader {
public double getSkillShotBonusMax() { return config.getDouble("Skills.Archery.SkillShot.MaxBonus", 2.0D); }
public double getSkillShotDamageMax() { return config.getDouble("Skills.Archery.SkillShot.MaxDamage", 9.0D); }
public double getDazeModifier() { return config.getDouble("Skills.Archery.Daze.BonusDamage", 4.0D); }
public double getDazeBonusDamage() { return config.getDouble("Skills.Archery.Daze.BonusDamage", 4.0D); }
public double getForceMultiplier() { return config.getDouble("Skills.Archery.ForceMultiplier", 2.0D); }

View File

@@ -237,7 +237,6 @@ public class Config extends AutoUpdateConfigLoader {
public boolean getStatsTrackingEnabled() { return config.getBoolean("General.Stats_Tracking", true); }
public boolean getUpdateCheckEnabled() { return config.getBoolean("General.Update_Check", true); }
public boolean getPreferBeta() { return config.getBoolean("General.Prefer_Beta", false); }
public boolean getEventCallbackEnabled() { return config.getBoolean("General.Event_Callback", true); }
public boolean getVerboseLoggingEnabled() { return config.getBoolean("General.Verbose_Logging", false); }
public String getPartyChatPrefix() { return config.getString("Commands.partychat.Chat_Prefix_Format", "[[GREEN]]([[WHITE]]{0}[[GREEN]])"); }

View File

@@ -3,6 +3,7 @@ package com.gmail.nossr50.config.experience;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.GrassSpecies;
import org.bukkit.Material;
import org.bukkit.TreeSpecies;
import org.bukkit.entity.EntityType;
@@ -267,7 +268,12 @@ public class ExperienceConfig extends AutoUpdateConfigLoader {
}
else if (type == Material.LONG_GRASS) {
switch (((LongGrass) data).getSpecies()) {
GrassSpecies species = ((LongGrass) data).getSpecies();
if (species == null) {
return 0;
}
switch (species) {
case DEAD:
return config.getInt("Experience.Herbalism.Dead_Bush", 30);

View File

@@ -85,13 +85,17 @@ public class CustomArmorConfig extends ConfigLoader {
repairQuantity = config.getInt(armorType + "." + armorName + ".Repair_Material_Data_Quantity", 2);
}
String repairItemName = config.getString(armorType + "." + armorName + ".Repair_Material_Pretty_Name");
int repairMinimumLevel = config.getInt(armorType + "." + armorName + ".Repair_MinimumLevel", 0);
double repairXpMultiplier = config.getDouble(armorType + "." + armorName + ".Repair_XpMultiplier", 1);
short durability = armorMaterial.getMaxDurability();
if (durability == 0) {
durability = (short) config.getInt(armorType + "." + armorName + ".Durability", 70);
}
repairables.add(RepairableFactory.getRepairable(armorMaterial, repairMaterial, repairData, 0, repairQuantity, durability, ItemType.ARMOR, MaterialType.OTHER, 1.0));
repairables.add(RepairableFactory.getRepairable(armorMaterial, repairMaterial, repairData, repairItemName, repairMinimumLevel, repairQuantity, durability, ItemType.ARMOR, MaterialType.OTHER, repairXpMultiplier));
}
materialList.add(armorMaterial);

View File

@@ -93,13 +93,17 @@ public class CustomToolConfig extends ConfigLoader {
repairQuantity = config.getInt(toolType + "." + toolName + ".Repair_Material_Data_Quantity", 2);
}
String repairItemName = config.getString(toolType + "." + toolName + ".Repair_Material_Pretty_Name");
int repairMinimumLevel = config.getInt(toolType + "." + toolName + ".Repair_MinimumLevel", 0);
double repairXpMultiplier = config.getDouble(toolType + "." + toolName + ".Repair_XpMultiplier", 1);
short durability = toolMaterial.getMaxDurability();
if (durability == 0) {
durability = (short) config.getInt(toolType + "." + toolName + ".Durability", 60);
}
repairables.add(RepairableFactory.getRepairable(toolMaterial, repairMaterial, repairData, 0, repairQuantity, durability, ItemType.TOOL, MaterialType.OTHER, 1.0));
repairables.add(RepairableFactory.getRepairable(toolMaterial, repairMaterial, repairData, repairItemName, repairMinimumLevel, repairQuantity, durability, ItemType.TOOL, MaterialType.OTHER, repairXpMultiplier));
}
double multiplier = config.getDouble(toolType + "." + toolName + ".XP_Modifier", 1.0);

View File

@@ -259,13 +259,13 @@ public class TreasureConfig extends ConfigLoader {
if (config.contains(type + "." + treasureName + ".Custom_Name")) {
ItemMeta itemMeta = item.getItemMeta();
itemMeta.setDisplayName(config.getString(type + "." + treasureName + "Custom_Name"));
itemMeta.setDisplayName(config.getString(type + "." + treasureName + ".Custom_Name"));
item.setItemMeta(itemMeta);
}
if (config.contains(type + "." + treasureName + ".Lore")) {
ItemMeta itemMeta = item.getItemMeta();
itemMeta.setLore(config.getStringList(type + "." + treasureName + "Custom_Name"));
itemMeta.setLore(config.getStringList(type + "." + treasureName + ".Lore"));
item.setItemMeta(itemMeta);
}
}

View File

@@ -13,6 +13,8 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.bukkit.Bukkit;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.MobHealthbarType;
@@ -29,7 +31,8 @@ import com.gmail.nossr50.util.Misc;
public final class SQLDatabaseManager implements DatabaseManager {
private String connectionString;
private String tablePrefix = Config.getInstance().getMySQLTablePrefix();
private Connection connection = null;
private Connection primaryConnection = null;
private Connection secondaryConnection = null;
// Scale waiting time by this much per failed attempt
private final double SCALING_FACTOR = 40.0;
@@ -199,7 +202,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
PreparedStatement statement = null;
try {
statement = connection.prepareStatement("SELECT " + query + ", user, NOW() FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON (user_id = id) WHERE " + query + " > 0 ORDER BY " + query + " DESC, user LIMIT ?, ?");
statement = getConnection().prepareStatement("SELECT " + query + ", user, NOW() FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON (user_id = id) WHERE " + query + " > 0 ORDER BY " + query + " DESC, user LIMIT ?, ?");
statement.setInt(1, (pageNumber * statsPerPage) - statsPerPage);
statement.setInt(2, statsPerPage);
resultSet = statement.executeQuery();
@@ -245,7 +248,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
"AND " + skillName + " > (SELECT " + skillName + " FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id " +
"WHERE user = ?)";
PreparedStatement statement = connection.prepareStatement(sql);
PreparedStatement statement = getConnection().prepareStatement(sql);
statement.setString(1, playerName);
resultSet = statement.executeQuery();
@@ -259,7 +262,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
statement.close();
statement = connection.prepareStatement(sql);
statement = getConnection().prepareStatement(sql);
resultSet = statement.executeQuery();
while (resultSet.next()) {
@@ -278,7 +281,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
"(SELECT taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing+alchemy " +
"FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id WHERE user = ?)";
PreparedStatement statement = connection.prepareStatement(sql);
PreparedStatement statement = getConnection().prepareStatement(sql);
statement.setString(1, playerName);
resultSet = statement.executeQuery();
@@ -295,7 +298,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
"(SELECT taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing+alchemy " +
"FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id WHERE user = ?) ORDER BY user";
statement = connection.prepareStatement(sql);
statement = getConnection().prepareStatement(sql);
statement.setString(1, playerName);
resultSet = statement.executeQuery();
@@ -324,7 +327,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
PreparedStatement statement = null;
try {
statement = connection.prepareStatement("INSERT INTO " + tablePrefix + "users (user, lastlogin) VALUES (?, ?)", Statement.RETURN_GENERATED_KEYS);
statement = getConnection().prepareStatement("INSERT INTO " + tablePrefix + "users (user, lastlogin) VALUES (?, ?)", Statement.RETURN_GENERATED_KEYS);
statement.setString(1, playerName);
statement.setLong(2, System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR);
statement.execute();
@@ -359,7 +362,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
PreparedStatement statement = null;
try {
statement = connection.prepareStatement(
statement = getConnection().prepareStatement(
"SELECT "
+ "s.taming, s.mining, s.repair, s.woodcutting, s.unarmed, s.herbalism, s.excavation, s.archery, s.swords, s.axes, s.acrobatics, s.fishing, s.alchemy, "
+ "e.taming, e.mining, e.repair, e.woodcutting, e.unarmed, e.herbalism, e.excavation, e.archery, e.swords, e.axes, e.acrobatics, e.fishing, e.alchemy, "
@@ -435,7 +438,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
PreparedStatement statement = null;
try {
statement = connection.prepareStatement(
statement = getConnection().prepareStatement(
"SELECT "
+ "s.taming, s.mining, s.repair, s.woodcutting, s.unarmed, s.herbalism, s.excavation, s.archery, s.swords, s.axes, s.acrobatics, s.fishing, s.alchemy, "
+ "e.taming, e.mining, e.repair, e.woodcutting, e.unarmed, e.herbalism, e.excavation, e.archery, e.swords, e.axes, e.acrobatics, e.fishing, e.alchemy, "
@@ -500,6 +503,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
public boolean checkConnected() {
boolean isClosed = true;
boolean isValid = false;
Connection connection = getConnection();
boolean exists = (connection != null);
// If we're waiting for server to recover then leave early
@@ -547,7 +551,11 @@ public final class SQLDatabaseManager implements DatabaseManager {
}
// Try to connect again
connect();
if (Bukkit.isPrimaryThread()) {
connectPrimary();
} else {
connectSecondary();
}
// Leave if connection is good
try {
@@ -572,13 +580,47 @@ public final class SQLDatabaseManager implements DatabaseManager {
return false;
}
private void connectSecondary() {
connectionString = "jdbc:mysql://" + Config.getInstance().getMySQLServerName() + ":" + Config.getInstance().getMySQLServerPort() + "/" + Config.getInstance().getMySQLDatabaseName();
try {
mcMMO.p.getLogger().info("Attempting connection to MySQL...");
// Force driver to load if not yet loaded
Class.forName("com.mysql.jdbc.Driver");
Properties connectionProperties = new Properties();
connectionProperties.put("user", Config.getInstance().getMySQLUserName());
connectionProperties.put("password", Config.getInstance().getMySQLUserPassword());
connectionProperties.put("autoReconnect", "false");
connectionProperties.put("maxReconnects", "0");
secondaryConnection = DriverManager.getConnection(connectionString, connectionProperties);
mcMMO.p.getLogger().info("Connection to MySQL was a success!");
}
catch (SQLException ex) {
secondaryConnection = null;
if (reconnectAttempt == 0 || reconnectAttempt >= 11) {
mcMMO.p.getLogger().severe("Connection to MySQL failed!");
printErrors(ex);
}
}
catch (ClassNotFoundException ex) {
secondaryConnection = null;
if (reconnectAttempt == 0 || reconnectAttempt >= 11) {
mcMMO.p.getLogger().severe("MySQL database driver not found!");
}
}
}
public List<String> getStoredUsers() {
ArrayList<String> users = new ArrayList<String>();
if (checkConnected()) {
Statement stmt = null;
try {
stmt = connection.createStatement();
stmt = getConnection().createStatement();
ResultSet result = stmt.executeQuery("SELECT user FROM " + tablePrefix + "users");
while (result.next()) {
users.add(result.getString("user"));
@@ -603,10 +645,18 @@ public final class SQLDatabaseManager implements DatabaseManager {
return users;
}
private Connection getConnection() {
if (Bukkit.isPrimaryThread()) {
return primaryConnection;
} else {
return secondaryConnection;
}
}
/**
* Attempt to connect to the mySQL database.
*/
private void connect() {
private void connectPrimary() {
connectionString = "jdbc:mysql://" + Config.getInstance().getMySQLServerName() + ":" + Config.getInstance().getMySQLServerPort() + "/" + Config.getInstance().getMySQLDatabaseName();
try {
@@ -619,12 +669,12 @@ public final class SQLDatabaseManager implements DatabaseManager {
connectionProperties.put("password", Config.getInstance().getMySQLUserPassword());
connectionProperties.put("autoReconnect", "false");
connectionProperties.put("maxReconnects", "0");
connection = DriverManager.getConnection(connectionString, connectionProperties);
primaryConnection = DriverManager.getConnection(connectionString, connectionProperties);
mcMMO.p.getLogger().info("Connection to MySQL was a success!");
}
catch (SQLException ex) {
connection = null;
primaryConnection = null;
if (reconnectAttempt == 0 || reconnectAttempt >= 11) {
mcMMO.p.getLogger().severe("Connection to MySQL failed!");
@@ -632,7 +682,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
}
}
catch (ClassNotFoundException ex) {
connection = null;
primaryConnection = null;
if (reconnectAttempt == 0 || reconnectAttempt >= 11) {
mcMMO.p.getLogger().severe("MySQL database driver not found!");
@@ -806,7 +856,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
return;
}
statement = connection.prepareStatement(sql);
statement = getConnection().prepareStatement(sql);
resultSet = statement.executeQuery();
while (resultSet.next()) {
@@ -866,7 +916,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
PreparedStatement statement = null;
try {
statement = connection.prepareStatement(sql);
statement = getConnection().prepareStatement(sql);
statement.executeUpdate();
return true;
}
@@ -901,7 +951,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
PreparedStatement statement = null;
try {
statement = connection.prepareStatement(sql);
statement = getConnection().prepareStatement(sql);
rows = statement.executeUpdate();
}
catch (SQLException ex) {
@@ -936,7 +986,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
ResultSet resultSet;
try {
statement = connection.prepareStatement(sql);
statement = getConnection().prepareStatement(sql);
resultSet = statement.executeQuery();
while (resultSet.next()) {
@@ -1008,22 +1058,22 @@ public final class SQLDatabaseManager implements DatabaseManager {
PreparedStatement statement = null;
try {
statement = connection.prepareStatement("INSERT IGNORE INTO " + tablePrefix + "experience (user_id) VALUES (?)");
statement = getConnection().prepareStatement("INSERT IGNORE INTO " + tablePrefix + "experience (user_id) VALUES (?)");
statement.setInt(1, id);
statement.execute();
statement.close();
statement = connection.prepareStatement("INSERT IGNORE INTO " + tablePrefix + "skills (user_id) VALUES (?)");
statement = getConnection().prepareStatement("INSERT IGNORE INTO " + tablePrefix + "skills (user_id) VALUES (?)");
statement.setInt(1, id);
statement.execute();
statement.close();
statement = connection.prepareStatement("INSERT IGNORE INTO " + tablePrefix + "cooldowns (user_id) VALUES (?)");
statement = getConnection().prepareStatement("INSERT IGNORE INTO " + tablePrefix + "cooldowns (user_id) VALUES (?)");
statement.setInt(1, id);
statement.execute();
statement.close();
statement = connection.prepareStatement("INSERT IGNORE INTO " + tablePrefix + "huds (user_id, mobhealthbar) VALUES (? ,'" + Config.getInstance().getMobHealthbarDefault().name() + "')");
statement = getConnection().prepareStatement("INSERT IGNORE INTO " + tablePrefix + "huds (user_id, mobhealthbar) VALUES (? ,'" + Config.getInstance().getMobHealthbarDefault().name() + "')");
statement.setInt(1, id);
statement.execute();
statement.close();
@@ -1053,7 +1103,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
PreparedStatement statement = null;
try {
statement = connection.prepareStatement(sql);
statement = getConnection().prepareStatement(sql);
int i = 1;
for (int arg : args) {
@@ -1083,7 +1133,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
PreparedStatement statement = null;
try {
statement = connection.prepareStatement(sql);
statement = getConnection().prepareStatement(sql);
int i = 1;
for (long arg : args) {
@@ -1120,7 +1170,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
int id = -1;
try {
PreparedStatement statement = connection.prepareStatement("SELECT id FROM " + tablePrefix + "users WHERE user = ?");
PreparedStatement statement = getConnection().prepareStatement("SELECT id FROM " + tablePrefix + "users WHERE user = ?");
statement.setString(1, playerName);
id = readInt(statement);
}
@@ -1135,7 +1185,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
PreparedStatement statement = null;
try {
statement = connection.prepareStatement("UPDATE " + tablePrefix + "users SET lastlogin = ? WHERE id = ?");
statement = getConnection().prepareStatement("UPDATE " + tablePrefix + "users SET lastlogin = ? WHERE id = ?");
statement.setLong(1, login);
statement.setInt(2, id);
statement.execute();
@@ -1161,7 +1211,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
PreparedStatement statement = null;
try {
statement = connection.prepareStatement("UPDATE " + tablePrefix + "huds SET mobhealthbar = ? WHERE user_id = ?");
statement = getConnection().prepareStatement("UPDATE " + tablePrefix + "huds SET mobhealthbar = ? WHERE user_id = ?");
statement.setString(1, mobHealthBar);
statement.setInt(2, userId);
statement.execute();

View File

@@ -33,13 +33,17 @@ public enum PotionStage {
public static PotionStage getPotionStage(AlchemyPotion input, AlchemyPotion output) {
PotionStage potionStage = getPotionStage(output);
if (getPotionStage(input) == potionStage) {
if (!isWaterBottle(input) && getPotionStage(input) == potionStage) {
potionStage = PotionStage.FIVE;
}
return potionStage;
}
private static boolean isWaterBottle(AlchemyPotion input) {
return input.getEffects().isEmpty();
}
public static PotionStage getPotionStage(AlchemyPotion alchemyPotion) {
Potion potion = Potion.fromItemStack(new ItemStack(Material.POTION, 1, alchemyPotion.getDataValue()));

View File

@@ -0,0 +1,11 @@
package com.gmail.nossr50.events.fake;
import org.bukkit.block.Block;
import org.bukkit.event.inventory.BrewEvent;
import org.bukkit.inventory.BrewerInventory;
public class FakeBrewEvent extends BrewEvent {
public FakeBrewEvent(Block brewer, BrewerInventory contents) {
super(brewer, contents);
}
}

View File

@@ -1,5 +1,7 @@
package com.gmail.nossr50.events.fake;
import java.util.Map;
import org.bukkit.entity.Entity;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
@@ -7,6 +9,11 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent;
* Called when mcMMO applies damage from an entity due to special abilities.
*/
public class FakeEntityDamageByEntityEvent extends EntityDamageByEntityEvent {
public FakeEntityDamageByEntityEvent(Entity damager, Entity damagee, DamageCause cause, final Map<DamageModifier, Double> modifiers) {
super(damager, damagee, cause, modifiers);
}
@Deprecated
public FakeEntityDamageByEntityEvent(Entity damager, Entity damagee, DamageCause cause, double damage) {
super(damager, damagee, cause, damage);
}

View File

@@ -1,5 +1,7 @@
package com.gmail.nossr50.events.fake;
import java.util.Map;
import org.bukkit.entity.Entity;
import org.bukkit.event.entity.EntityDamageEvent;
@@ -7,6 +9,11 @@ import org.bukkit.event.entity.EntityDamageEvent;
* Called when mcMMO applies damage due to special abilities.
*/
public class FakeEntityDamageEvent extends EntityDamageEvent {
public FakeEntityDamageEvent(Entity damagee, DamageCause cause, final Map<DamageModifier, Double> modifiers) {
super(damagee, cause, modifiers);
}
@Deprecated
public FakeEntityDamageEvent(Entity damagee, DamageCause cause, double damage) {
super(damagee, cause, damage);
}

View File

@@ -1,18 +1,20 @@
package com.gmail.nossr50.events.skills.secondaryabilities;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import com.gmail.nossr50.datatypes.skills.SecondaryAbility;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.events.skills.McMMOPlayerSkillEvent;
public abstract class SecondaryAbilityEvent extends McMMOPlayerSkillEvent {
public class SecondaryAbilityEvent extends McMMOPlayerSkillEvent implements Cancellable {
private SecondaryAbility secondaryAbility;
private boolean cancelled;
public SecondaryAbilityEvent(Player player, SecondaryAbility secondaryAbility) {
super(player, SkillType.bySecondaryAbility(secondaryAbility));
this.secondaryAbility = secondaryAbility;
cancelled = false;
}
/**
@@ -22,4 +24,12 @@ public abstract class SecondaryAbilityEvent extends McMMOPlayerSkillEvent {
public SecondaryAbility getSecondaryAbility() {
return secondaryAbility;
}
public boolean isCancelled() {
return cancelled;
}
public void setCancelled(boolean newValue) {
this.cancelled = newValue;
}
}

View File

@@ -5,7 +5,6 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.skills.SecondaryAbility;
public class SecondaryAbilityWeightedActivationCheckEvent extends SecondaryAbilityEvent {
private double chance;
public SecondaryAbilityWeightedActivationCheckEvent(Player player, SecondaryAbility ability, double chance) {

View File

@@ -31,6 +31,7 @@ import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.datatypes.skills.ToolType;
import com.gmail.nossr50.events.fake.FakeBlockBreakEvent;
import com.gmail.nossr50.events.fake.FakeBlockDamageEvent;
import com.gmail.nossr50.runnables.PistonTrackerTask;
import com.gmail.nossr50.runnables.StickyPistonTrackerTask;
import com.gmail.nossr50.skills.alchemy.Alchemy;
import com.gmail.nossr50.skills.excavation.ExcavationManager;
@@ -63,27 +64,27 @@ public class BlockListener implements Listener {
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
List<Block> blocks = event.getBlocks();
if (!EventUtils.shouldProcessEvent(event.getBlock(), true)) {
return;
}
BlockFace direction = event.getDirection();
Block futureEmptyBlock = event.getBlock().getRelative(direction); // Block that would be air after piston is finished
if (futureEmptyBlock.getType() == Material.AIR) {
return;
}
List<Block> blocks = event.getBlocks();
for (Block b : blocks) {
if (BlockUtils.shouldBeWatched(b.getState()) && mcMMO.getPlaceStore().isTrue(b)) {
b.getRelative(direction).setMetadata(mcMMO.blockMetadataKey, mcMMO.metadataValue);
if (b.equals(futureEmptyBlock) && futureEmptyBlock.getType() == Material.AIR) {
mcMMO.getPlaceStore().setFalse(b);
}
}
}
for (Block b : blocks) {
Block nextBlock = b.getRelative(direction);
if (nextBlock.hasMetadata(mcMMO.blockMetadataKey)) {
mcMMO.getPlaceStore().setTrue(nextBlock);
nextBlock.removeMetadata(mcMMO.blockMetadataKey, plugin);
}
}
// Needed because blocks sometimes don't move when two pistons push towards each other
new PistonTrackerTask(blocks, direction, futureEmptyBlock).runTaskLater(plugin, 2);
}
/**
@@ -93,6 +94,10 @@ public class BlockListener implements Listener {
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockPistonRetract(BlockPistonRetractEvent event) {
if (!EventUtils.shouldProcessEvent(event.getBlock(), false)) {
return;
}
if (!event.isSticky()) {
return;
}

View File

@@ -147,7 +147,7 @@ public class EntityListener implements Listener {
return;
}
double damage = event.getDamage();
double damage = event.getFinalDamage();
if (damage <= 0) {
return;
@@ -211,7 +211,7 @@ public class EntityListener implements Listener {
}
CombatUtils.processCombatAttack(event, attacker, target);
CombatUtils.handleHealthbars(attacker, target, event.getDamage());
CombatUtils.handleHealthbars(attacker, target, event.getFinalDamage());
}
/**
@@ -225,7 +225,7 @@ public class EntityListener implements Listener {
return;
}
double damage = event.getDamage();
double damage = event.getFinalDamage();
if (damage <= 0) {
return;
@@ -276,7 +276,7 @@ public class EntityListener implements Listener {
if (acrobaticsManager.canRoll()) {
event.setDamage(acrobaticsManager.rollCheck(event.getDamage()));
if (event.getDamage() == 0) {
if (event.getFinalDamage() == 0) {
event.setCancelled(true);
return;
}
@@ -289,7 +289,7 @@ public class EntityListener implements Listener {
if (miningManager.canUseDemolitionsExpertise()) {
event.setDamage(miningManager.processDemolitionsExpertise(event.getDamage()));
if (event.getDamage() == 0) {
if (event.getFinalDamage() == 0) {
event.setCancelled(true);
return;
}
@@ -300,7 +300,7 @@ public class EntityListener implements Listener {
break;
}
if (event.getDamage() >= 1) {
if (event.getFinalDamage() >= 1) {
mcMMOPlayer.actualizeRecentlyHurt();
}
}
@@ -334,7 +334,7 @@ public class EntityListener implements Listener {
if (tamingManager.canUseThickFur()) {
event.setDamage(Taming.processThickFur(wolf, event.getDamage()));
if (event.getDamage() == 0) {
if (event.getFinalDamage() == 0) {
event.setCancelled(true);
}
}
@@ -360,7 +360,7 @@ public class EntityListener implements Listener {
if (tamingManager.canUseShockProof()) {
event.setDamage(Taming.processShockProof(wolf, event.getDamage()));
if (event.getDamage() == 0) {
if (event.getFinalDamage() == 0) {
event.setCancelled(true);
}
}

View File

@@ -112,6 +112,7 @@ public class mcMMO extends JavaPlugin {
public final static String disarmedItemKey = "mcMMO: Disarmed Item";
public final static String playerDataKey = "mcMMO: Player Data";
public final static String greenThumbDataKey = "mcMMO: Green Thumb";
public final static String pistonDataKey = "mcMMO: Piston State";
public static FixedMetadataValue metadataValue;
@@ -138,7 +139,7 @@ public class mcMMO extends JavaPlugin {
return;
}
if (getServer().getName().equals("MCPC+")) {
if (getServer().getName().equals("Cauldron") || getServer().getName().equals("MCPC+")) {
checkModConfigs();
}
@@ -485,22 +486,22 @@ public class mcMMO extends JavaPlugin {
private void checkModConfigs() {
if (!Config.getInstance().getToolModsEnabled()) {
getLogger().info("MCPC+ implementation found, but the custom tool config for mcMMO is disabled!");
getLogger().warning("Cauldron implementation found, but the custom tool config for mcMMO is disabled!");
getLogger().info("To enable, set Mods.Tool_Mods_Enabled to TRUE in config.yml.");
}
if (!Config.getInstance().getArmorModsEnabled()) {
getLogger().info("MCPC+ implementation found, but the custom armor config for mcMMO is disabled!");
getLogger().warning("Cauldron implementation found, but the custom armor config for mcMMO is disabled!");
getLogger().info("To enable, set Mods.Armor_Mods_Enabled to TRUE in config.yml.");
}
if (!Config.getInstance().getBlockModsEnabled()) {
getLogger().info("MCPC+ implementation found, but the custom block config for mcMMO is disabled!");
getLogger().warning("Cauldron implementation found, but the custom block config for mcMMO is disabled!");
getLogger().info("To enable, set Mods.Block_Mods_Enabled to TRUE in config.yml.");
}
if (!Config.getInstance().getEntityModsEnabled()) {
getLogger().info("MCPC+ implementation found, but the custom entity config for mcMMO is disabled!");
getLogger().warning("Cauldron implementation found, but the custom entity config for mcMMO is disabled!");
getLogger().info("To enable, set Mods.Entity_Mods_Enabled to TRUE in config.yml.");
}
}

View File

@@ -0,0 +1,47 @@
package com.gmail.nossr50.runnables;
import java.util.List;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.BlockUtils;
public class PistonTrackerTask extends BukkitRunnable {
private List<Block> blocks;
private BlockFace direction;
private Block futureEmptyBlock;
public PistonTrackerTask(List<Block> blocks, BlockFace direction, Block futureEmptyBlock) {
this.blocks = blocks;
this.direction = direction;
this.futureEmptyBlock = futureEmptyBlock;
}
@Override
public void run() {
// Check to see if futureEmptyBlock is empty - if it isn't; the blocks didn't move
if (!BlockUtils.isPistonPiece(futureEmptyBlock.getState())) {
return;
}
if (mcMMO.getPlaceStore().isTrue(futureEmptyBlock)) {
mcMMO.getPlaceStore().setFalse(futureEmptyBlock);
}
for (Block b : blocks) {
Block nextBlock = b.getRelative(direction);
if (nextBlock.hasMetadata(mcMMO.blockMetadataKey)) {
mcMMO.getPlaceStore().setTrue(nextBlock);
nextBlock.removeMetadata(mcMMO.blockMetadataKey, mcMMO.p);
}
else if (mcMMO.getPlaceStore().isTrue(nextBlock)) {
// Block doesn't have metadatakey but isTrue - set it to false
mcMMO.getPlaceStore().setFalse(nextBlock);
}
}
}
}

View File

@@ -2,7 +2,6 @@ package com.gmail.nossr50.runnables;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.PistonMoveReaction;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.mcMMO;
@@ -21,10 +20,16 @@ public class StickyPistonTrackerTask extends BukkitRunnable {
@Override
public void run() {
if (!BlockUtils.shouldBeWatched(movedBlock.getState()) || movedBlock.getPistonMoveReaction() != PistonMoveReaction.MOVE || !mcMMO.getPlaceStore().isTrue(movedBlock)) {
if (!mcMMO.getPlaceStore().isTrue(movedBlock)) {
return;
}
if (!BlockUtils.isPistonPiece(movedBlock.getState())) {
// The block didn't move
return;
}
// The sticky piston actually pulled the block so move the PlaceStore data
mcMMO.getPlaceStore().setFalse(movedBlock);
mcMMO.getPlaceStore().setTrue(block.getRelative(direction));
}

View File

@@ -1,5 +1,6 @@
package com.gmail.nossr50.skills.alchemy;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Material;
@@ -18,6 +19,7 @@ import com.gmail.nossr50.config.skills.alchemy.PotionConfig;
import com.gmail.nossr50.datatypes.skills.SecondaryAbility;
import com.gmail.nossr50.datatypes.skills.alchemy.AlchemyPotion;
import com.gmail.nossr50.datatypes.skills.alchemy.PotionStage;
import com.gmail.nossr50.events.fake.FakeBrewEvent;
import com.gmail.nossr50.runnables.player.PlayerUpdateInventoryTask;
import com.gmail.nossr50.runnables.skills.AlchemyBrewCheckTask;
import com.gmail.nossr50.util.Permissions;
@@ -101,6 +103,8 @@ public final class AlchemyPotionBrewer {
return;
}
List<AlchemyPotion> inputList = new ArrayList<AlchemyPotion>();
for (int i = 0; i < 3; i++) {
ItemStack item = inventory.getItem(i);
@@ -111,13 +115,26 @@ public final class AlchemyPotionBrewer {
AlchemyPotion input = PotionConfig.getInstance().getPotion(item.getDurability());
AlchemyPotion output = PotionConfig.getInstance().getPotion(input.getChildDataValue(ingredient));
inputList.add(input);
if (output != null) {
inventory.setItem(i, output.toItemStack(item.getAmount()).clone());
}
}
if (player != null) {
PotionStage potionStage = PotionStage.getPotionStage(input, output);
UserManager.getPlayer(player).getAlchemyManager().handlePotionBrewSuccesses(potionStage, 1);
}
FakeBrewEvent event = new FakeBrewEvent(brewingStand.getBlock(), inventory);
mcMMO.p.getServer().getPluginManager().callEvent(event);
if (event.isCancelled() || inputList.isEmpty()) {
return;
}
for (AlchemyPotion input : inputList) {
AlchemyPotion output = PotionConfig.getInstance().getPotion(input.getChildDataValue(ingredient));
if (output != null && player != null) {
PotionStage potionStage = PotionStage.getPotionStage(input, output);
UserManager.getPlayer(player).getAlchemyManager().handlePotionBrewSuccesses(potionStage, 1);
}
}

View File

@@ -19,7 +19,7 @@ public class Archery {
public static double skillShotMaxBonusPercentage = AdvancedConfig.getInstance().getSkillShotBonusMax();
public static double skillShotMaxBonusDamage = AdvancedConfig.getInstance().getSkillShotDamageMax();
public static double dazeModifier = AdvancedConfig.getInstance().getDazeModifier();
public static double dazeBonusDamage = AdvancedConfig.getInstance().getDazeBonusDamage();
public static final double DISTANCE_XP_MULTIPLIER = 0.025;

View File

@@ -1,11 +1,9 @@
package com.gmail.nossr50.skills.archery;
import org.bukkit.Location;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
@@ -18,7 +16,6 @@ import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.skills.CombatUtils;
import com.gmail.nossr50.util.skills.SkillUtils;
public class ArcheryManager extends SkillManager {
@@ -70,9 +67,8 @@ public class ArcheryManager extends SkillManager {
* Handle the effects of the Daze ability
*
* @param defender The {@link Player} being affected by the ability
* @param arrow The {@link Arrow} that was fired
*/
public double daze(Player defender, Arrow arrow) {
public double daze(Player defender) {
if (!SkillUtils.activationSuccessful(SecondaryAbility.DAZE, getPlayer(), getSkillLevel(), activationChance)) {
return 0;
}
@@ -91,20 +87,21 @@ public class ArcheryManager extends SkillManager {
getPlayer().sendMessage(LocaleLoader.getString("Combat.TargetDazed"));
}
return CombatUtils.callFakeDamageEvent(arrow, defender, DamageCause.PROJECTILE, Archery.dazeModifier);
return Archery.dazeBonusDamage;
}
/**
* Handle the effects of the Skill Shot ability
*
* @param target The {@link LivingEntity} being affected by the ability
* @param damage The amount of damage initially dealt by the event
* @param arrow The {@link Arrow} that was fired
*/
public double skillShot(LivingEntity target, double damage, Arrow arrow) {
double damageBonusPercent = Math.min(((getSkillLevel() / Archery.skillShotIncreaseLevel) * Archery.skillShotIncreasePercentage), Archery.skillShotMaxBonusPercentage);
double archeryBonus = Math.min(damage * damageBonusPercent, Archery.skillShotMaxBonusDamage);
public double skillShot(double damage) {
if (!SkillUtils.activationSuccessful(SecondaryAbility.SKILL_SHOT, getPlayer())) {
return damage;
}
return CombatUtils.callFakeDamageEvent(arrow, target, DamageCause.PROJECTILE, archeryBonus);
double damageBonusPercent = Math.min(((getSkillLevel() / Archery.skillShotIncreaseLevel) * Archery.skillShotIncreasePercentage), Archery.skillShotMaxBonusPercentage);
return Math.min(damage * damageBonusPercent, Archery.skillShotMaxBonusDamage);
}
}

View File

@@ -1,20 +1,20 @@
package com.gmail.nossr50.skills.axes;
import java.util.Map;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent.DamageModifier;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SecondaryAbility;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.datatypes.skills.ToolType;
import com.gmail.nossr50.events.skills.secondaryabilities.SecondaryAbilityWeightedActivationCheckEvent;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.ItemUtils;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.skills.CombatUtils;
@@ -52,13 +52,13 @@ public class AxesManager extends SkillManager {
/**
* Handle the effects of the Axe Mastery ability
*
* @param target The {@link LivingEntity} being affected by the ability
*/
public double axeMastery(LivingEntity target) {
double axeBonus = Math.min(getSkillLevel() / (Axes.axeMasteryMaxBonusLevel / Axes.axeMasteryMaxBonus), Axes.axeMasteryMaxBonus);
public double axeMastery() {
if (!SkillUtils.activationSuccessful(SecondaryAbility.AXE_MASTERY, getPlayer())) {
return 0;
}
return CombatUtils.callFakeDamageEvent(getPlayer(), target, axeBonus);
return Math.min(getSkillLevel() / (Axes.axeMasteryMaxBonusLevel / Axes.axeMasteryMaxBonus), Axes.axeMasteryMaxBonus);
}
/**
@@ -85,7 +85,7 @@ public class AxesManager extends SkillManager {
damage = (damage * Axes.criticalHitPVEModifier) - damage;
}
return CombatUtils.callFakeDamageEvent(player, target, damage);
return damage;
}
/**
@@ -98,10 +98,7 @@ public class AxesManager extends SkillManager {
for (ItemStack armor : target.getEquipment().getArmorContents()) {
if (ItemUtils.isArmor(armor)) {
double chance = Axes.impactChance / activationChance;
SecondaryAbilityWeightedActivationCheckEvent event = new SecondaryAbilityWeightedActivationCheckEvent(getPlayer(), SecondaryAbility.ARMOR_IMPACT, chance);
mcMMO.p.getServer().getPluginManager().callEvent(event);
if ((event.getChance() * activationChance) > Misc.getRandom().nextInt(activationChance)) {
if (SkillUtils.activationSuccessful(SecondaryAbility.ARMOR_IMPACT, getPlayer(), Axes.impactChance, activationChance)) {
SkillUtils.handleDurabilityChange(armor, durabilityDamage, Axes.impactMaxDurabilityModifier);
}
}
@@ -114,10 +111,7 @@ public class AxesManager extends SkillManager {
* @param target The {@link LivingEntity} being affected by the ability
*/
public double greaterImpact(LivingEntity target) {
double chance = Axes.greaterImpactChance / activationChance;
SecondaryAbilityWeightedActivationCheckEvent event = new SecondaryAbilityWeightedActivationCheckEvent(getPlayer(), SecondaryAbility.GREATER_IMPACT, chance);
mcMMO.p.getServer().getPluginManager().callEvent(event);
if ((event.getChance() * activationChance) <= Misc.getRandom().nextInt(activationChance)) {
if (!SkillUtils.activationSuccessful(SecondaryAbility.GREATER_IMPACT, getPlayer(), Axes.greaterImpactChance, activationChance)) {
return 0;
}
@@ -138,7 +132,7 @@ public class AxesManager extends SkillManager {
}
}
return CombatUtils.callFakeDamageEvent(player, target, Axes.greaterImpactBonusDamage);
return Axes.greaterImpactBonusDamage;
}
/**
@@ -147,7 +141,7 @@ public class AxesManager extends SkillManager {
* @param target The {@link LivingEntity} being affected by the ability
* @param damage The amount of damage initially dealt by the event
*/
public void skullSplitterCheck(LivingEntity target, double damage) {
CombatUtils.applyAbilityAoE(getPlayer(), target, damage / Axes.skullSplitterModifier, skill);
public void skullSplitterCheck(LivingEntity target, double damage, Map<DamageModifier, Double> modifiers) {
CombatUtils.applyAbilityAoE(getPlayer(), target, damage / Axes.skullSplitterModifier, modifiers, skill);
}
}

View File

@@ -97,7 +97,8 @@ public class RepairManager extends SkillManager {
// Check if they have the proper material to repair with
if (!inventory.contains(repairMaterial)) {
String message = LocaleLoader.getString("Skills.NeedMore", StringUtils.getPrettyItemString(repairMaterial));
String prettyName = repairable.getRepairMaterialPrettyName() == null ? StringUtils.getPrettyItemString(repairMaterial) : repairable.getRepairMaterialPrettyName();
String message = LocaleLoader.getString("Skills.NeedMore", prettyName);
if (repairMaterialMetadata != (byte) -1 && !inventory.containsAtLeast(toRemove, 1)) {
message += ":" + repairMaterialMetadata;

View File

@@ -28,6 +28,13 @@ public interface Repairable {
*/
public byte getRepairMaterialMetadata();
/**
* Gets the pretty name of the material used to repair this item
*
* @return the pretty name of the repair material
*/
public String getRepairMaterialPrettyName();
/**
* Gets the RepairItemType value for this repairable item
*

View File

@@ -8,11 +8,15 @@ import com.gmail.nossr50.datatypes.skills.MaterialType;
public class RepairableFactory {
public static Repairable getRepairable(Material itemMaterial, Material repairMaterial, byte repairMetadata, int minimumQuantity, short maximumDurability) {
return getRepairable(itemMaterial, repairMaterial, repairMetadata, 0, minimumQuantity, maximumDurability, ItemType.OTHER, MaterialType.OTHER, 1);
return getRepairable(itemMaterial, repairMaterial, repairMetadata, null, 0, minimumQuantity, maximumDurability, ItemType.OTHER, MaterialType.OTHER, 1);
}
public static Repairable getRepairable(Material itemMaterial, Material repairMaterial, byte repairMetadata, int minimumLevel, int minimumQuantity, short maximumDurability, ItemType repairItemType, MaterialType repairMaterialType, double xpMultiplier) {
return getRepairable(itemMaterial, repairMaterial, repairMetadata, null, minimumLevel, minimumQuantity, maximumDurability, repairItemType, repairMaterialType, xpMultiplier);
}
public static Repairable getRepairable(Material itemMaterial, Material repairMaterial, byte repairMetadata, String repairMaterialPrettyName, int minimumLevel, int minimumQuantity, short maximumDurability, ItemType repairItemType, MaterialType repairMaterialType, double xpMultiplier) {
// TODO: Add in loading from config what type of repairable we want.
return new SimpleRepairable(itemMaterial, repairMaterial, repairMetadata, minimumLevel, minimumQuantity, maximumDurability, repairItemType, repairMaterialType, xpMultiplier);
return new SimpleRepairable(itemMaterial, repairMaterial, repairMetadata, repairMaterialPrettyName, minimumLevel, minimumQuantity, maximumDurability, repairItemType, repairMaterialType, xpMultiplier);
}
}

View File

@@ -11,14 +11,16 @@ public class SimpleRepairable implements Repairable {
private final int minimumQuantity, minimumLevel;
private final short maximumDurability, baseRepairDurability;
private final byte repairMetadata;
private String repairMaterialPrettyName;
private final ItemType repairItemType;
private final MaterialType repairMaterialType;
private final double xpMultiplier;
protected SimpleRepairable(Material type, Material repairMaterial, byte repairMetadata, int minimumLevel, int minimumQuantity, short maximumDurability, ItemType repairItemType, MaterialType repairMaterialType, double xpMultiplier) {
protected SimpleRepairable(Material type, Material repairMaterial, byte repairMetadata, String repairMaterialPrettyName, int minimumLevel, int minimumQuantity, short maximumDurability, ItemType repairItemType, MaterialType repairMaterialType, double xpMultiplier) {
this.itemMaterial = type;
this.repairMaterial = repairMaterial;
this.repairMetadata = repairMetadata;
this.repairMaterialPrettyName = repairMaterialPrettyName;
this.repairItemType = repairItemType;
this.repairMaterialType = repairMaterialType;
this.minimumLevel = minimumLevel;
@@ -43,6 +45,11 @@ public class SimpleRepairable implements Repairable {
return repairMetadata;
}
@Override
public String getRepairMaterialPrettyName() {
return repairMaterialPrettyName;
}
@Override
public ItemType getRepairItemType() {
return repairItemType;

View File

@@ -84,8 +84,6 @@ public class SalvageManager extends SkillManager {
return;
}
byte salvageMaterialMetadata = salvageable.getSalvageMaterialMetadata();
int salvageableAmount = Salvage.calculateSalvageableAmount(item.getDurability(), salvageable.getMaximumDurability(), salvageable.getMaximumQuantity());
if (salvageableAmount == 0) {
@@ -108,6 +106,8 @@ public class SalvageManager extends SkillManager {
}
}
byte salvageMaterialMetadata = (salvageable.getSalvageMaterialMetadata() != (byte) -1) ? salvageable.getSalvageMaterialMetadata() : 0;
Misc.dropItems(location, new MaterialData(salvageable.getSalvageMaterial(), salvageMaterialMetadata).toItemStack(salvageableAmount), 1);
// BWONG BWONG BWONG - CLUNK!

View File

@@ -7,37 +7,37 @@ import com.gmail.nossr50.datatypes.skills.MaterialType;
public interface Salvageable {
/**
* Gets the type of this repairable item
* Gets the type of this salvageable item
*
* @return the type of this repairable
* @return the type of this salvageable
*/
public Material getItemMaterial();
/**
* Gets the id of the material used to repair this item
* Gets the material of the items dropped when salvaging this item
*
* @return the id of the repair material
* @return the material of the salvage drop
*/
public Material getSalvageMaterial();
/**
* Gets the metadata byte value of the material used to repair this item
* Gets the metadata byte value of the items dropped when salvaging this item
*
* @return the byte metadata of the repair material
* @return the byte metadata of the salvage drop
*/
public byte getSalvageMaterialMetadata();
/**
* Gets the RepairItemType value for this repairable item
* Gets the ItemType value for this salvageable item
*
* @return the RepairItemType for this repairable
* @return the ItemType for this salvageable
*/
public ItemType getSalvageItemType();
/**
* Gets the RepairMaterialType value for this repairable item
* Gets the MaterialType value for this salvageable item
*
* @return the RepairMaterialType for this repairable
* @return the MaterialType for this salvageable
*/
public MaterialType getSalvageMaterialType();
@@ -58,25 +58,25 @@ public interface Salvageable {
public short getMaximumDurability();
/**
* Gets the base repair durability on which to calculate bonuses.
* Gets the base salvage durability on which to calculate bonuses.
*
* This is actually the maximum durability divided by the minimum quantity
*
* @return the base repair durability
* @return the base salvage durability
*/
public short getBaseSalvageDurability();
/**
* Gets the minimum repair level needed to repair this item
* Gets the minimum salvage level needed to salvage this item
*
* @return the minimum level to repair this item, or 0 for no minimum
* @return the minimum level to salvage this item, or 0 for no minimum
*/
public int getMinimumLevel();
/**
* Gets the xpMultiplier for this repairable
* Gets the xpMultiplier for this salvageable
*
* @return the xpMultiplier of this repairable
* @return the xpMultiplier of this salvageable
*/
public double getXpMultiplier();
}

View File

@@ -1,8 +1,11 @@
package com.gmail.nossr50.skills.swords;
import java.util.Map;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent.DamageModifier;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
@@ -96,8 +99,8 @@ public class SwordsManager extends SkillManager {
* @param target The {@link LivingEntity} being affected by the ability
* @param damage The amount of damage initially dealt by the event
*/
public void serratedStrikes(LivingEntity target, double damage) {
CombatUtils.applyAbilityAoE(getPlayer(), target, damage / Swords.serratedStrikesModifier, skill);
public void serratedStrikes(LivingEntity target, double damage, Map<DamageModifier, Double> modifiers) {
CombatUtils.applyAbilityAoE(getPlayer(), target, damage / Swords.serratedStrikesModifier, modifiers, skill);
BleedTimerTask.add(target, Swords.serratedStrikesBleedTicks);
}
}

View File

@@ -18,14 +18,12 @@ import com.gmail.nossr50.datatypes.skills.SecondaryAbility;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.datatypes.skills.XPGainReason;
import com.gmail.nossr50.events.fake.FakeEntityTameEvent;
import com.gmail.nossr50.events.skills.secondaryabilities.SecondaryAbilityWeightedActivationCheckEvent;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.runnables.skills.BleedTimerTask;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.skills.CombatUtils;
import com.gmail.nossr50.util.skills.SkillUtils;
public class TamingManager extends SkillManager {
@@ -96,18 +94,16 @@ public class TamingManager extends SkillManager {
* @param damage The damage being absorbed by the wolf
*/
public void fastFoodService(Wolf wolf, double damage) {
double chance = Taming.fastFoodServiceActivationChance / activationChance;
SecondaryAbilityWeightedActivationCheckEvent event = new SecondaryAbilityWeightedActivationCheckEvent(getPlayer(), SecondaryAbility.FAST_FOOD, chance);
mcMMO.p.getServer().getPluginManager().callEvent(event);
if ((event.getChance() * activationChance) > Misc.getRandom().nextInt(activationChance)) {
if (!SkillUtils.activationSuccessful(SecondaryAbility.FAST_FOOD, getPlayer(), Taming.fastFoodServiceActivationChance, activationChance)) {
return;
}
double health = wolf.getHealth();
double maxHealth = wolf.getMaxHealth();
double health = wolf.getHealth();
double maxHealth = wolf.getMaxHealth();
if (health < maxHealth) {
double newHealth = health + damage;
wolf.setHealth(Math.min(newHealth, maxHealth));
}
if (health < maxHealth) {
double newHealth = health + damage;
wolf.setHealth(Math.min(newHealth, maxHealth));
}
}
@@ -116,9 +112,8 @@ public class TamingManager extends SkillManager {
*
* @param target The LivingEntity to apply Gore on
* @param damage The initial damage
* @param wolf The wolf using the ability
*/
public double gore(LivingEntity target, double damage, Wolf wolf) {
public double gore(LivingEntity target, double damage) {
if (!SkillUtils.activationSuccessful(SecondaryAbility.GORE, getPlayer(), getSkillLevel(), activationChance)) {
return 0;
}
@@ -132,11 +127,11 @@ public class TamingManager extends SkillManager {
getPlayer().sendMessage(LocaleLoader.getString("Combat.Gore"));
damage = (damage * Taming.goreModifier) - damage;
return CombatUtils.callFakeDamageEvent(wolf, target, damage);
return damage;
}
public double sharpenedClaws(LivingEntity target, Wolf wolf) {
return CombatUtils.callFakeDamageEvent(wolf, target, Taming.sharpenedClawsBonusDamage);
public double sharpenedClaws() {
return Taming.sharpenedClawsBonusDamage;
}
/**

View File

@@ -22,7 +22,6 @@ import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.skills.CombatUtils;
import com.gmail.nossr50.util.skills.SkillUtils;
public class UnarmedManager extends SkillManager {
@@ -57,6 +56,10 @@ public class UnarmedManager extends SkillManager {
}
public boolean blockCrackerCheck(BlockState blockState) {
if (!SkillUtils.activationSuccessful(SecondaryAbility.BLOCK_CRACKER, getPlayer())) {
return false;
}
MaterialData data = blockState.getData();
switch (blockState.getType()) {
@@ -117,24 +120,23 @@ public class UnarmedManager extends SkillManager {
/**
* Handle the effects of the Berserk ability
*
* @param target The {@link LivingEntity} being affected by the ability
* @param damage The amount of damage initially dealt by the event
*/
public double berserkDamage(LivingEntity target, double damage) {
public double berserkDamage(double damage) {
damage = (damage * Unarmed.berserkDamageModifier) - damage;
return CombatUtils.callFakeDamageEvent(getPlayer(), target, damage);
return damage;
}
/**
* Handle the effects of the Iron Arm ability
*
* @param target The {@link LivingEntity} being affected by the ability
*/
public double ironArm(LivingEntity target) {
double unarmedBonus = Math.min(Unarmed.ironArmMinBonusDamage + (getSkillLevel() / Unarmed.ironArmIncreaseLevel), Unarmed.ironArmMaxBonusDamage);
public double ironArm() {
if (!SkillUtils.activationSuccessful(SecondaryAbility.IRON_ARM, getPlayer())) {
return 0;
}
return CombatUtils.callFakeDamageEvent(getPlayer(), target, unarmedBonus);
return Math.min(Unarmed.ironArmMinBonusDamage + (getSkillLevel() / Unarmed.ironArmIncreaseLevel), Unarmed.ironArmMaxBonusDamage);
}
/**

View File

@@ -173,5 +173,4 @@ public class WoodcuttingManager extends SkillManager {
applyXpGain(xp, XPGainReason.PVE);
}
}

View File

@@ -308,6 +308,12 @@ public final class BlockUtils {
return type == Repair.anvilMaterial || type == Salvage.anvilMaterial;
}
public static boolean isPistonPiece(BlockState blockState) {
Material type = blockState.getType();
return type == Material.PISTON_MOVING_PIECE || type == Material.AIR;
}
/**
* Get a HashSet containing every transparent block
*

View File

@@ -8,6 +8,7 @@ import org.bukkit.entity.Fish;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.plugin.PluginManager;
import com.gmail.nossr50.mcMMO;
@@ -15,6 +16,7 @@ import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SecondaryAbility;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.datatypes.skills.XPGainReason;
import com.gmail.nossr50.events.experience.McMMOPlayerLevelChangeEvent;
@@ -34,6 +36,7 @@ import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityDeactivateEve
import com.gmail.nossr50.events.skills.fishing.McMMOPlayerFishingTreasureEvent;
import com.gmail.nossr50.events.skills.fishing.McMMOPlayerMagicHunterEvent;
import com.gmail.nossr50.events.skills.repair.McMMOPlayerRepairCheckEvent;
import com.gmail.nossr50.events.skills.secondaryabilities.SecondaryAbilityEvent;
import com.gmail.nossr50.events.skills.unarmed.McMMOPlayerDisarmEvent;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.player.UserManager;
@@ -46,6 +49,13 @@ public class EventUtils {
return event;
}
public static SecondaryAbilityEvent callSecondaryAbilityEvent(Player player, SecondaryAbility secondaryAbility) {
SecondaryAbilityEvent event = new SecondaryAbilityEvent(player, secondaryAbility);
mcMMO.p.getServer().getPluginManager().callEvent(event);
return event;
}
public static FakePlayerAnimationEvent callFakeArmSwingEvent(Player player) {
FakePlayerAnimationEvent event = new FakePlayerAnimationEvent(player);
mcMMO.p.getServer().getPluginManager().callEvent(event);
@@ -194,4 +204,26 @@ public class EventUtils {
return event;
}
/**
* There is a bug in CraftBukkit that causes piston events to
* fire multiple times. Check this method to see if the piston event
* should be processed.
*
* @param block Block object of the piston block
* @param isExtendEvent should be true when called from BlockPistonExtendEvent
*
* @return true if the PistonEvent should be processed, false otherwise
*/
public static boolean shouldProcessEvent(Block block, boolean isExtendEvent) {
String pistonAction = isExtendEvent ? "EXTEND" : "RETRACT";
String lastAction = block.hasMetadata(mcMMO.pistonDataKey) ? block.getMetadata(mcMMO.pistonDataKey).get(0).asString() : "";
if (!lastAction.equals(pistonAction)) {
block.setMetadata(mcMMO.pistonDataKey, new FixedMetadataValue(mcMMO.p, pistonAction));
return true;
}
return false;
}
}

View File

@@ -11,6 +11,8 @@ import org.bukkit.metadata.FixedMetadataValue;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.google.common.collect.ImmutableList;
public final class UserManager {
private UserManager() {}
@@ -50,8 +52,8 @@ public final class UserManager {
* Save all users ON THIS THREAD.
*/
public static void saveAll() {
Player[] onlinePlayers = mcMMO.p.getServer().getOnlinePlayers();
mcMMO.p.debug("Saving mcMMOPlayers... (" + onlinePlayers.length + ")");
ImmutableList<Player> onlinePlayers = ImmutableList.copyOf(mcMMO.p.getServer().getOnlinePlayers());
mcMMO.p.debug("Saving mcMMOPlayers... (" + onlinePlayers.size() + ")");
for (Player player : onlinePlayers) {
getPlayer(player).getProfile().save();

View File

@@ -22,6 +22,7 @@ import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.player.UserManager;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
@@ -158,8 +159,8 @@ public class ScoreboardManager {
// Called in onDisable()
public static void teardownAll() {
Player[] onlinePlayers = mcMMO.p.getServer().getOnlinePlayers();
mcMMO.p.debug("Tearing down scoreboards... (" + onlinePlayers.length + ")");
ImmutableList<Player> onlinePlayers = ImmutableList.copyOf(mcMMO.p.getServer().getOnlinePlayers());
mcMMO.p.debug("Tearing down scoreboards... (" + onlinePlayers.size() + ")");
for (Player player : onlinePlayers) {
teardownPlayer(player);
}

View File

@@ -1,5 +1,9 @@
package com.gmail.nossr50.util.skills;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Material;
import org.bukkit.entity.AnimalTamer;
import org.bukkit.entity.Animals;
@@ -15,11 +19,11 @@ import org.bukkit.entity.Wolf;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityDamageEvent.DamageModifier;
import org.bukkit.inventory.ItemStack;
import org.bukkit.projectiles.ProjectileSource;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.SkillType;
@@ -44,12 +48,16 @@ import com.gmail.nossr50.util.MobHealthbarUtils;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager;
import com.google.common.collect.ImmutableMap;
public final class CombatUtils {
private CombatUtils() {}
private static void processSwordCombat(LivingEntity target, Player player, double damage) {
private static void processSwordCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event) {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
SwordsManager swordsManager = mcMMOPlayer.getSwordsManager();
double initialDamage = event.getDamage();
Map<DamageModifier, Double> modifiers = getModifiers(event);
if (swordsManager.canActivateAbility()) {
mcMMOPlayer.checkAbilityActivation(SkillType.SWORDS);
@@ -60,7 +68,7 @@ public final class CombatUtils {
}
if (swordsManager.canUseSerratedStrike()) {
swordsManager.serratedStrikes(target, damage);
swordsManager.serratedStrikes(target, initialDamage, modifiers);
}
startGainXp(mcMMOPlayer, target, SkillType.SWORDS);
@@ -69,6 +77,7 @@ public final class CombatUtils {
private static void processAxeCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event) {
double initialDamage = event.getDamage();
double finalDamage = initialDamage;
Map<DamageModifier, Double> modifiers = getModifiers(event);
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
AxesManager axesManager = mcMMOPlayer.getAxesManager();
@@ -78,7 +87,7 @@ public final class CombatUtils {
}
if (axesManager.canUseAxeMastery()) {
finalDamage += axesManager.axeMastery(target);
finalDamage += axesManager.axeMastery();
}
if (axesManager.canCriticalHit(target)) {
@@ -93,10 +102,10 @@ public final class CombatUtils {
}
if (axesManager.canUseSkullSplitter(target)) {
axesManager.skullSplitterCheck(target, initialDamage);
axesManager.skullSplitterCheck(target, initialDamage, modifiers);
}
event.setDamage(finalDamage);
applyScaledModifiers(initialDamage, finalDamage, event);
startGainXp(mcMMOPlayer, target, SkillType.AXES);
}
@@ -112,18 +121,18 @@ public final class CombatUtils {
}
if (unarmedManager.canUseIronArm()) {
finalDamage += unarmedManager.ironArm(target);
finalDamage += unarmedManager.ironArm();
}
if (unarmedManager.canUseBerserk()) {
finalDamage += unarmedManager.berserkDamage(target, initialDamage);
finalDamage += unarmedManager.berserkDamage(initialDamage);
}
if (unarmedManager.canDisarm(target)) {
unarmedManager.disarmCheck((Player) target);
}
event.setDamage(finalDamage);
applyScaledModifiers(initialDamage, finalDamage, event);
startGainXp(mcMMOPlayer, target, SkillType.UNARMED);
}
@@ -139,14 +148,14 @@ public final class CombatUtils {
}
if (tamingManager.canUseSharpenedClaws()) {
finalDamage += tamingManager.sharpenedClaws(target, wolf);
finalDamage += tamingManager.sharpenedClaws();
}
if (tamingManager.canUseGore()) {
finalDamage += tamingManager.gore(target, initialDamage, wolf);
finalDamage += tamingManager.gore(target, initialDamage);
}
event.setDamage(finalDamage);
applyScaledModifiers(initialDamage, finalDamage, event);
startGainXp(mcMMOPlayer, target, SkillType.TAMING);
}
@@ -170,11 +179,11 @@ public final class CombatUtils {
}
if (archeryManager.canSkillShot()) {
finalDamage += archeryManager.skillShot(target, initialDamage, arrow);
finalDamage += archeryManager.skillShot(initialDamage);
}
if (archeryManager.canDaze(target)) {
finalDamage += archeryManager.daze((Player) target, arrow);
finalDamage += archeryManager.daze((Player) target);
}
if (!arrow.hasMetadata(mcMMO.infiniteArrowKey) && archeryManager.canRetrieveArrows()) {
@@ -183,7 +192,7 @@ public final class CombatUtils {
archeryManager.distanceXpBonus(target, arrow);
event.setDamage(finalDamage);
applyScaledModifiers(initialDamage, finalDamage, event);
startGainXp(mcMMOPlayer, target, SkillType.ARCHERY, arrow.getMetadata(mcMMO.bowForceKey).get(0).asDouble());
}
@@ -227,7 +236,7 @@ public final class CombatUtils {
}
if (SkillType.SWORDS.getPermissions(player)) {
processSwordCombat(target, player, event.getDamage());
processSwordCombat(target, player, event);
}
}
else if (ItemUtils.isAxe(heldItem)) {
@@ -308,6 +317,7 @@ public final class CombatUtils {
* @param target LivingEntity which to attempt to damage
* @param damage Amount of damage to attempt to do
*/
@Deprecated
public static void dealDamage(LivingEntity target, double damage) {
dealDamage(target, damage, DamageCause.CUSTOM, null);
}
@@ -319,6 +329,7 @@ public final class CombatUtils {
* @param damage Amount of damage to attempt to do
* @param attacker Player to pass to event as damager
*/
@Deprecated
public static void dealDamage(LivingEntity target, double damage, LivingEntity attacker) {
dealDamage(target, damage, DamageCause.ENTITY_ATTACK, attacker);
}
@@ -330,6 +341,23 @@ public final class CombatUtils {
* @param damage Amount of damage to attempt to do
* @param attacker Player to pass to event as damager
*/
public static void dealDamage(LivingEntity target, double damage, Map<DamageModifier, Double> modifiers, LivingEntity attacker) {
if (target.isDead()) {
return;
}
// Aren't we applying the damage twice????
target.damage(callFakeDamageEvent(attacker, target, damage, modifiers));
}
/**
* Attempt to damage target for value dmg with reason ENTITY_ATTACK with damager attacker
*
* @param target LivingEntity which to attempt to damage
* @param damage Amount of damage to attempt to do
* @param attacker Player to pass to event as damager
*/
@Deprecated
public static void dealDamage(LivingEntity target, double damage, DamageCause cause, Entity attacker) {
if (target.isDead()) {
return;
@@ -346,7 +374,7 @@ public final class CombatUtils {
* @param damage The initial damage amount
* @param type The type of skill being used
*/
public static void applyAbilityAoE(Player attacker, LivingEntity target, double damage, SkillType type) {
public static void applyAbilityAoE(Player attacker, LivingEntity target, double damage, Map<DamageModifier, Double> modifiers, SkillType type) {
int numberOfTargets = getTier(attacker.getItemInHand()); // The higher the weapon tier, the more targets you hit
double damageAmount = Math.max(damage, 1);
@@ -382,7 +410,7 @@ public final class CombatUtils {
break;
}
dealDamage(livingEntity, damageAmount, attacker);
dealDamage(livingEntity, damageAmount, modifiers, attacker);
numberOfTargets--;
}
}
@@ -567,23 +595,79 @@ public final class CombatUtils {
return false;
}
@Deprecated
public static double callFakeDamageEvent(Entity attacker, Entity target, double damage) {
return callFakeDamageEvent(attacker, target, DamageCause.ENTITY_ATTACK, damage);
return callFakeDamageEvent(attacker, target, DamageCause.ENTITY_ATTACK, new EnumMap<DamageModifier, Double>(ImmutableMap.of(DamageModifier.BASE, damage)));
}
public static double callFakeDamageEvent(Entity attacker, Entity target, DamageCause cause, double damage) {
if (Config.getInstance().getEventCallbackEnabled()) {
EntityDamageEvent damageEvent = attacker == null ? new FakeEntityDamageEvent(target, cause, damage) : new FakeEntityDamageByEntityEvent(attacker, target, cause, damage);
mcMMO.p.getServer().getPluginManager().callEvent(damageEvent);
@Deprecated
public static double callFakeDamageEvent(Entity attacker, Entity target, DamageCause damageCause, double damage) {
return callFakeDamageEvent(attacker, target, damageCause, new EnumMap<DamageModifier, Double>(ImmutableMap.of(DamageModifier.BASE, damage)));
}
if (damageEvent.isCancelled()) {
return 0;
}
public static double callFakeDamageEvent(Entity attacker, Entity target, Map<DamageModifier, Double> modifiers) {
return callFakeDamageEvent(attacker, target, DamageCause.ENTITY_ATTACK, modifiers);
}
damage = damageEvent.getDamage();
public static double callFakeDamageEvent(Entity attacker, Entity target, double damage, Map<DamageModifier, Double> modifiers) {
return callFakeDamageEvent(attacker, target, DamageCause.ENTITY_ATTACK, getScaledModifiers(damage, modifiers));
}
public static double callFakeDamageEvent(Entity attacker, Entity target, DamageCause cause, Map<DamageModifier, Double> modifiers) {
EntityDamageEvent damageEvent = attacker == null ? new FakeEntityDamageEvent(target, cause, modifiers) : new FakeEntityDamageByEntityEvent(attacker, target, cause, modifiers);
mcMMO.p.getServer().getPluginManager().callEvent(damageEvent);
if (damageEvent.isCancelled()) {
return 0;
}
return damage;
return damageEvent.getFinalDamage();
}
private static Map<DamageModifier, Double> getModifiers(EntityDamageEvent event) {
Map<DamageModifier, Double> modifiers = new HashMap<DamageModifier, Double>();
for (DamageModifier modifier : DamageModifier.values()) {
modifiers.put(modifier, event.getDamage(modifier));
}
return modifiers;
}
private static Map<DamageModifier, Double> getScaledModifiers(double damage, Map<DamageModifier, Double> modifiers) {
Map<DamageModifier, Double> scaledModifiers = new HashMap<DamageModifier, Double>();
for (DamageModifier modifier : DamageModifier.values()) {
if (modifier == DamageModifier.BASE) {
modifiers.put(modifier, damage);
continue;
}
scaledModifiers.put(modifier, damage * modifiers.get(modifier));
}
return scaledModifiers;
}
public static EntityDamageByEntityEvent applyScaledModifiers(double initialDamage, double finalDamage, EntityDamageByEntityEvent event) {
// No additional damage
if (initialDamage == finalDamage) {
return event;
}
for (DamageModifier modifier : DamageModifier.values()) {
if (!event.isApplicable(modifier)) {
continue;
}
if (modifier == DamageModifier.BASE) {
event.setDamage(modifier, finalDamage);
continue;
}
event.setDamage(modifier, finalDamage / initialDamage * event.getDamage(modifier));
}
return event;
}
/**

View File

@@ -24,8 +24,10 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SecondaryAbility;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.events.skills.secondaryabilities.SecondaryAbilityEvent;
import com.gmail.nossr50.events.skills.secondaryabilities.SecondaryAbilityWeightedActivationCheckEvent;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.ItemUtils;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.StringUtils;
@@ -205,13 +207,25 @@ public class SkillUtils {
double chance = (maxChance / maxLevel) * Math.min(skillLevel, maxLevel) / activationChance;
SecondaryAbilityWeightedActivationCheckEvent event = new SecondaryAbilityWeightedActivationCheckEvent(player, skillAbility, chance);
mcMMO.p.getServer().getPluginManager().callEvent(event);
return (event.getChance() * activationChance) > Misc.getRandom().nextInt(activationChance);
return (event.getChance() * activationChance) > Misc.getRandom().nextInt(activationChance) && !event.isCancelled();
}
public static boolean activationSuccessful(SecondaryAbility skillAbility, Player player, double staticChance, int activationChance) {
double chance = staticChance / activationChance;
SecondaryAbilityWeightedActivationCheckEvent event = new SecondaryAbilityWeightedActivationCheckEvent(player, skillAbility, chance);
mcMMO.p.getServer().getPluginManager().callEvent(event);
return (event.getChance() * activationChance) > Misc.getRandom().nextInt(activationChance) && !event.isCancelled();
}
public static boolean activationSuccessful(SecondaryAbility skillAbility, Player player) {
SecondaryAbilityEvent event = EventUtils.callSecondaryAbilityEvent(player, skillAbility);
return !event.isCancelled();
}
public static boolean treasureDropSuccessful(Player player, double dropChance, int activationChance) {
SecondaryAbilityWeightedActivationCheckEvent event = new SecondaryAbilityWeightedActivationCheckEvent(player, SecondaryAbility.EXCAVATION_TREASURE_HUNTER, dropChance / activationChance);
mcMMO.p.getServer().getPluginManager().callEvent(event);
return (event.getChance() * activationChance) > (Misc.getRandom().nextDouble() * activationChance);
return (event.getChance() * activationChance) > (Misc.getRandom().nextDouble() * activationChance) && !event.isCancelled();
}
private static boolean isLocalizedSkill(String skillName) {

View File

@@ -17,8 +17,6 @@ General:
# Allow mcMMO to check if a new version is available
Update_Check: true
Prefer_Beta: false
# Allow mcMMO to inform other plugins of damage being dealt
Event_Callback: true
Power_Level_Cap: 0
# Should mcMMO print out debug messages?
Verbose_Logging: false

View File

@@ -1,4 +1,47 @@
#
# Armor example configuration
# Last updated on ${project.version}-b${BUILD_NUMBER}
#
# Any file named armor.*.yml in the mod folder will be loaded as a armor config
# For every armor type there is a separate section.
# The names of each subitem should be the exact material name.
# The bare minimum of an Armor piece is that it has a Repair_Material
#
#
# Repairable: Whether or not the item is repairable
## This defaults to true
#
# Repair_Material: This is the material name of the item used to repair this armor.
## This is required to be set if you want to be able to repair the item.
#
# Repair_Material_Data_Value: This is the metadata of the item used to repair this armor.
## A value of -1 means to ignore all metadata when repairing.
## This defaults to -1
#
# Repair_Material_Quantity: This is the minimum number of items needed to repair this item ignoring all other repair bonuses.
## This is typically the number of the repair material needed to create a new item, for example for a sword it is 2, for an axe it is 3
## This defaults to 9
#
# Repair_Material_Pretty_Name: The pretty name of the repair material.
## Used in the feedback message when not enough repair materials are found.
## This defaults to the Repair_Material converted to string.
#
# Repair_Material_Pretty_Name: The pretty name of the repair material.
## Used in the feedback message when not enough repair materials are found.
## This defaults to the Repair_Material converted to string.
#
# Repair_MinimumLevel: This is the minimum repair level needed to repair this item.
## Valid values are => 0
## This defaults to 0
#
# Repair_XpMultiplier: This is the amount to multiply the xp bonus by.
## This defaults to 1
#
# Durability: This is the maximum durability of the armor.
## Valid values are >= 1
#
###
#
# Settings for Boots
###
Boots:
@@ -7,12 +50,18 @@ Boots:
Repair_Material: REPAIR_MATERIAL_NAME
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9
Repair_Material_Pretty_Name: Repair Item Name
Repair_MinimumLevel: 0
Repair_XpMultiplier: 1.0
Durability: 999
Boot_2:
Repairable: true
Repair_Material: REPAIR_MATERIAL_NAME
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9
Repair_Material_Pretty_Name: Repair Item Name
Repair_MinimumLevel: 0
Repair_XpMultiplier: 1.0
Durability: 999
#
# Settings for Chestplates
@@ -23,12 +72,18 @@ Chestplates:
Repair_Material: REPAIR_MATERIAL_NAME
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9
Repair_Material_Pretty_Name: Repair Item Name
Repair_MinimumLevel: 0
Repair_XpMultiplier: 1.0
Durability: 999
Chestplate_2:
Repairable: true
Repair_Material: REPAIR_MATERIAL_NAME
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9
Repair_Material_Pretty_Name: Repair Item Name
Repair_MinimumLevel: 0
Repair_XpMultiplier: 1.0
Durability: 999
#
# Settings for Helmets
@@ -39,12 +94,18 @@ Helmets:
Repair_Material: REPAIR_MATERIAL_NAME
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9
Repair_Material_Pretty_Name: Repair Item Name
Repair_MinimumLevel: 0
Repair_XpMultiplier: 1.0
Durability: 999
Helmet_2:
Repairable: true
Repair_Material: REPAIR_MATERIAL_NAME
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9
Repair_Material_Pretty_Name: Repair Item Name
Repair_MinimumLevel: 0
Repair_XpMultiplier: 1.0
Durability: 999
#
# Settings for Leggings
@@ -55,10 +116,16 @@ Leggings:
Repair_Material: REPAIR_MATERIAL_NAME
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9
Repair_Material_Pretty_Name: Repair Item Name
Repair_MinimumLevel: 0
Repair_XpMultiplier: 1.0
Durability: 999
Legging_2:
Repairable: true
Repair_Material: REPAIR_MATERIAL_NAME
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9
Repair_Material_Pretty_Name: Repair Item Name
Repair_MinimumLevel: 0
Repair_XpMultiplier: 1.0
Durability: 999

View File

@@ -1,132 +1,220 @@
#
# Tools example configuration
# Last updated on ${project.version}-b${BUILD_NUMBER}
#
# Any file named tools.*.yml in the mod folder will be loaded as a tools config
# For every tool type there is a separate section.
# The names of each subitem should be the exact material name.
# The bare minimum of a Tool is that it has a Repair_Material
#
#
#
# XP_Modifier: This is the xp modifier of the tool, xp is multiplied by this modifier.
## Valid values are > 0
## This defaults to 1.0.
#
# Tier: The tier of the tool
## Used to determine the capabilities of AoE abilities with certain skills
## Valid values range from 1 to 4
## This defaults to 1
#
# Ability_Enabled: Whether or not abilities are enabled with this tool
## This defaults to true
#
# Repairable: Whether or not the item is repairable
## This defaults to true
#
# Repair_Material: This is the material name of the item used to repair this tool.
## This is required to be set if you want to be able to repair the item.
#
# Repair_Material_Data_Value: This is the metadata of the item used to repair this tool.
## A value of -1 means to ignore all metadata when repairing.
## This defaults to -1
#
# Repair_Material_Quantity: This is the minimum number of items needed to repair this item ignoring all other repair bonuses.
## This is typically the number of the repair material needed to create a new item, for example for a sword it is 2, for an axe it is 3
## This defaults to 9
#
# Repair_Material_Pretty_Name: The pretty name of the repair material.
## Used in the feedback message when not enough repair materials are found.
## This defaults to the Repair_Material converted to string.
#
# Repair_MinimumLevel: This is the minimum repair level needed to repair this item.
## Valid values are => 0
## This defaults to 0
#
# Repair_XpMultiplier: This is the amount to multiply the xp bonus by.
## This defaults to 1
#
# Durability: This is the maximum durability of the tool.
## Valid values are >= 1
#
###
#
# Settings for Axes
###
Axes:
Axe_1:
XP_Modifer: 1.0
XP_Modifier: 1.0
Ability_Enabled: true
Tier: 1
Repairable: true
Repair_Material: REPAIR_MATERIAL_NAME
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9
Repair_Material_Pretty_Name: Repair Item Name
Repair_MinimumLevel: 0
Repair_XpMultiplier: 1.0
Durability: 9999
Axe_2:
XP_Modifer: 1.0
XP_Modifier: 1.0
Ability_Enabled: true
Tier: 1
Repairable: true
Repair_Material: REPAIR_MATERIAL_NAME
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9
Repair_Material_Pretty_Name: Repair Item Name
Repair_MinimumLevel: 0
Repair_XpMultiplier: 1.0
Durability: 9999
#
# Settings for Bows
###
Bows:
Bow_1:
XP_Modifer: 1.0
XP_Modifier: 1.0
Ability_Enabled: true
Tier: 1
Repairable: true
Repair_Material: REPAIR_MATERIAL_NAME
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9
Repair_Material_Pretty_Name: Repair Item Name
Repair_MinimumLevel: 0
Repair_XpMultiplier: 1.0
Durability: 9999
Bow_2:
XP_Modifer: 1.0
XP_Modifier: 1.0
Ability_Enabled: true
Tier: 1
Repairable: true
Repair_Material: REPAIR_MATERIAL_NAME
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9
Repair_Material_Pretty_Name: Repair Item Name
Repair_MinimumLevel: 0
Repair_XpMultiplier: 1.0
Durability: 9999
#
# Settings for Hoes
###
Hoes:
Hoe_1:
XP_Modifer: 1.0
XP_Modifier: 1.0
Ability_Enabled: true
Tier: 1
Repairable: true
Repair_Material: REPAIR_MATERIAL_NAME
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9
Repair_Material_Pretty_Name: Repair Item Name
Repair_MinimumLevel: 0
Repair_XpMultiplier: 1.0
Durability: 9999
Hoe_2:
XP_Modifer: 1.0
XP_Modifier: 1.0
Ability_Enabled: true
Tier: 1
Repairable: true
Repair_Material: REPAIR_MATERIAL_NAME
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9
Repair_Material_Pretty_Name: Repair Item Name
Repair_MinimumLevel: 0
Repair_XpMultiplier: 1.0
Durability: 9999
#
# Settings for Pickaxes
###
Pickaxes:
Pickaxe_1:
XP_Modifer: 1.0
XP_Modifier: 1.0
Ability_Enabled: true
Tier: 1
Repairable: true
Repair_Material: REPAIR_MATERIAL_NAME
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9
Repair_Material_Pretty_Name: Repair Item Name
Repair_MinimumLevel: 0
Repair_XpMultiplier: 1.0
Durability: 9999
Pickaxe_2:
XP_Modifer: 1.0
XP_Modifier: 1.0
Ability_Enabled: true
Tier: 1
Repairable: true
Repair_Material: REPAIR_MATERIAL_NAME
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9
Repair_Material_Pretty_Name: Repair Item Name
Repair_MinimumLevel: 0
Repair_XpMultiplier: 1.0
Durability: 9999
#
# Settings for Shovels
###
Shovels:
Shovel_1:
XP_Modifer: 1.0
XP_Modifier: 1.0
Ability_Enabled: true
Tier: 1
Repairable: true
Repair_Material: REPAIR_MATERIAL_NAME
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9
Repair_Material_Pretty_Name: Repair Item Name
Repair_MinimumLevel: 0
Repair_XpMultiplier: 1.0
Durability: 9999
Shovel_2:
XP_Modifer: 1.0
XP_Modifier: 1.0
Ability_Enabled: true
Tier: 1
Repairable: true
Repair_Material: REPAIR_MATERIAL_NAME
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9
Repair_Material_Pretty_Name: Repair Item Name
Repair_MinimumLevel: 0
Repair_XpMultiplier: 1.0
Durability: 9999
#
# Settings for Swords
###
Swords:
Sword_1:
XP_Modifer: 1.0
XP_Modifier: 1.0
Ability_Enabled: true
Tier: 1
Repairable: true
Repair_Material: REPAIR_MATERIAL_NAME
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9
Repair_Material_Pretty_Name: Repair Item Name
Repair_MinimumLevel: 0
Repair_XpMultiplier: 1.0
Durability: 9999
Sword_2:
XP_Modifer: 1.0
XP_Modifier: 1.0
Ability_Enabled: true
Tier: 1
Repairable: true
Repair_Material: REPAIR_MATERIAL_NAME
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 9
Repair_Material_Pretty_Name: Repair Item Name
Repair_MinimumLevel: 0
Repair_XpMultiplier: 1.0
Durability: 9999

View File

@@ -1954,6 +1954,11 @@ permissions:
children:
mcmmo.ability.repair.all: true
mcmmo.commands.repair: true
mcmmo.skills.salvage:
description: Allows access to the Salvage skill
children:
mcmmo.ability.salvage.all: true
mcmmo.commands.salvage: true
mcmmo.skills.smelting:
description: Allows access to the Smelting skill
children:

View File

@@ -58,12 +58,13 @@ finally () {</pre>
break;
case 2:</pre>
* Whenever possible, check for a negative, rather than a positive
* <pre>if (!something) {
// Do things
* Prefer early returns over method indentation. Example:
* <pre>if (!precondition) {
// Possibly cleanup
return;
}
// Do other things</pre>
// Continue with task</pre>
* Java standard class and method naming, with exception to McMMO in a class name
* <pre>thisIsAMethod()</pre>
* <pre>ThisIsAClass</pre>
@@ -88,8 +89,6 @@ finally () {</pre>
* protected
* static protected
* abstract protected
* override private
* private
* static private
* abstract private
* No one-line if statements, they should all have brackets
* No one-line if statements, they should all have brackets