diff --git a/Changelog.txt b/Changelog.txt index bf0c121bc..1d9770bed 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -2,6 +2,9 @@ Changelog: #Versions without changelogs probably had very small misc fixes, like tweaks to the source code Version 2.0-dev - Fixed /mcability not respecting permissions + - Changed to use Bukkit's built-in ignoreCancelledEvents system + - Re-added mcMMO reporting damage events + - Added configuration option to control mcMMO reporting damage events Version 1.2.12 - Fixed issue that caused terrible MySQL performance and negative XP on levelup (Issue #134) diff --git a/src/main/java/com/gmail/nossr50/Combat.java b/src/main/java/com/gmail/nossr50/Combat.java index 5266690e4..d034c26ed 100644 --- a/src/main/java/com/gmail/nossr50/Combat.java +++ b/src/main/java/com/gmail/nossr50/Combat.java @@ -16,6 +16,7 @@ */ package com.gmail.nossr50; +import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.entity.*; import org.bukkit.event.entity.EntityDamageByEntityEvent; @@ -26,6 +27,7 @@ import org.bukkit.plugin.Plugin; import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; +import com.gmail.nossr50.events.FakeEntityDamageByEntityEvent; import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.party.Party; import com.gmail.nossr50.skills.Acrobatics; @@ -87,10 +89,12 @@ public class Combat event.setDamage(event.getDamage() + (event.getDamage() / 2)); //Handle Ability Interactions - if(PPa.getSkullSplitterMode() && m.isAxes(attacker.getItemInHand())) - Axes.applyAoeDamage(attacker, eventb, pluginx); - if(PPa.getSerratedStrikesMode() && m.isSwords(attacker.getItemInHand())) - Swords.applySerratedStrikes(attacker, eventb, pluginx); + if(!(event instanceof FakeEntityDamageByEntityEvent)) { + if(PPa.getSkullSplitterMode() && m.isAxes(attacker.getItemInHand())) + Axes.applyAoeDamage(attacker, eventb, pluginx); + if(PPa.getSerratedStrikesMode() && m.isSwords(attacker.getItemInHand())) + Swords.applySerratedStrikes(attacker, eventb, pluginx); + } //Experience if(event.getEntity() instanceof Player) @@ -358,8 +362,52 @@ public class Combat } } - public static void dealDamage(LivingEntity target, int dmg) { - target.damage(dmg); + /** + * Attempt to damage target for value dmg with reason CUSTOM + * + * @param target LivingEntity which to attempt to damage + * @param dmg Amount of damage to attempt to do + */ + public static void dealDamage(LivingEntity target, int dmg){ + dealDamage(target, dmg, EntityDamageEvent.DamageCause.CUSTOM); + } + + /** + * Attempt to damage target for value dmg with reason cause + * + * @param target LivingEntity which to attempt to damage + * @param dmg Amount of damage to attempt to do + * @param cause DamageCause to pass to damage event + */ + public static void dealDamage(LivingEntity target, int dmg, DamageCause cause) { + if(LoadProperties.eventCallback) { + EntityDamageEvent ede = new EntityDamageEvent(target, cause, dmg); + Bukkit.getPluginManager().callEvent(ede); + if(ede.isCancelled()) return; + + target.damage(ede.getDamage()); + } else { + target.damage(dmg); + } + } + + /** + * Attempt to damage target for value dmg with reason ENTITY_ATTACK with damager attacker + * + * @param target LivingEntity which to attempt to damage + * @param dmg Amount of damage to attempt to do + * @param attacker Player to pass to event as damager + */ + public static void dealDamage(LivingEntity target, int dmg, Player attacker) { + if(LoadProperties.eventCallback) { + EntityDamageEvent ede = (EntityDamageByEntityEvent) new FakeEntityDamageByEntityEvent(attacker, target, EntityDamageEvent.DamageCause.ENTITY_ATTACK, dmg); + Bukkit.getPluginManager().callEvent(ede); + if(ede.isCancelled()) return; + + target.damage(ede.getDamage()); + } else { + target.damage(dmg); + } } public static boolean pvpAllowed(EntityDamageByEntityEvent event, World world) diff --git a/src/main/java/com/gmail/nossr50/config/LoadProperties.java b/src/main/java/com/gmail/nossr50/config/LoadProperties.java index 3fa3b9c42..7fd941164 100644 --- a/src/main/java/com/gmail/nossr50/config/LoadProperties.java +++ b/src/main/java/com/gmail/nossr50/config/LoadProperties.java @@ -43,7 +43,7 @@ public class LoadProperties { diamondArmor, woodenTools, stoneTools, ironTools, goldTools, diamondTools, enderPearl, blazeRod, records, glowstoneDust, fishingDiamonds, aDisplayNames, pDisplayNames, enableSmoothToMossy, - enableDirtToGrass, statsTracking; + enableDirtToGrass, statsTracking, eventCallback; public static String MySQLtablePrefix, MySQLuserName, MySQLserverName, MySQLdbName, MySQLdbPass, nWood, nStone, @@ -299,6 +299,7 @@ public class LoadProperties { enableRegen = readBoolean("General.HP_Regeneration.Enabled", true); saveInterval = readInteger("General.Save_Interval", 10); statsTracking = readBoolean("General.Stats_Tracking", true); + eventCallback = readBoolean("General.Event_Callback", true); enableCobbleToMossy = readBoolean("Skills.Herbalism.Green_Thumb.Cobble_To_Mossy", true); enableSmoothToMossy = readBoolean("Skills.Herbalism.Green_Thumb.SmoothBrick_To_MossyBrick", true); diff --git a/src/main/java/com/gmail/nossr50/datatypes/FakeBlockBreakEvent.java b/src/main/java/com/gmail/nossr50/events/FakeBlockBreakEvent.java similarity index 93% rename from src/main/java/com/gmail/nossr50/datatypes/FakeBlockBreakEvent.java rename to src/main/java/com/gmail/nossr50/events/FakeBlockBreakEvent.java index d9d4595b0..f1e44f8ce 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/FakeBlockBreakEvent.java +++ b/src/main/java/com/gmail/nossr50/events/FakeBlockBreakEvent.java @@ -1,29 +1,29 @@ -/* - This file is part of mcMMO. - - mcMMO is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - mcMMO is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with mcMMO. If not, see . -*/ -package com.gmail.nossr50.datatypes; - -import org.bukkit.block.Block; -import org.bukkit.entity.Player; -import org.bukkit.event.block.BlockBreakEvent; - -public class FakeBlockBreakEvent extends BlockBreakEvent { - private static final long serialVersionUID = 1L; - - public FakeBlockBreakEvent(Block theBlock, Player player) { - super(theBlock, player); - } +/* + This file is part of mcMMO. + + mcMMO is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + mcMMO is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with mcMMO. If not, see . +*/ +package com.gmail.nossr50.events; + +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.block.BlockBreakEvent; + +public class FakeBlockBreakEvent extends BlockBreakEvent { + private static final long serialVersionUID = 1L; + + public FakeBlockBreakEvent(Block theBlock, Player player) { + super(theBlock, player); + } } \ No newline at end of file diff --git a/src/main/java/com/gmail/nossr50/events/FakeEntityDamageByEntityEvent.java b/src/main/java/com/gmail/nossr50/events/FakeEntityDamageByEntityEvent.java new file mode 100644 index 000000000..8ff2fb292 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/events/FakeEntityDamageByEntityEvent.java @@ -0,0 +1,11 @@ +package com.gmail.nossr50.events; + +import org.bukkit.entity.Entity; +import org.bukkit.event.entity.EntityDamageByEntityEvent; + +@SuppressWarnings("serial") +public class FakeEntityDamageByEntityEvent extends EntityDamageByEntityEvent { + public FakeEntityDamageByEntityEvent(Entity damager, Entity damagee, DamageCause cause, int damage) { + super(damager, damagee, cause, damage); + } +} diff --git a/src/main/java/com/gmail/nossr50/listeners/mcBlockListener.java b/src/main/java/com/gmail/nossr50/listeners/mcBlockListener.java index 9fc1f111a..e3805ede1 100644 --- a/src/main/java/com/gmail/nossr50/listeners/mcBlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/mcBlockListener.java @@ -47,7 +47,7 @@ import org.getspout.spoutapi.sound.SoundEffect; import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.skills.*; -import com.gmail.nossr50.datatypes.FakeBlockBreakEvent; +import com.gmail.nossr50.events.FakeBlockBreakEvent; public class mcBlockListener implements Listener { diff --git a/src/main/java/com/gmail/nossr50/m.java b/src/main/java/com/gmail/nossr50/m.java index 93097f06c..133672f48 100644 --- a/src/main/java/com/gmail/nossr50/m.java +++ b/src/main/java/com/gmail/nossr50/m.java @@ -29,8 +29,8 @@ import org.bukkit.entity.*; import org.bukkit.inventory.ItemStack; import com.gmail.nossr50.config.*; import com.gmail.nossr50.datatypes.PlayerProfile; -import com.gmail.nossr50.datatypes.FakeBlockBreakEvent; import com.gmail.nossr50.datatypes.SkillType; +import com.gmail.nossr50.events.FakeBlockBreakEvent; import com.gmail.nossr50.events.McMMOItemSpawnEvent; public class m diff --git a/src/main/java/com/gmail/nossr50/skills/Axes.java b/src/main/java/com/gmail/nossr50/skills/Axes.java index c15f2236b..c189db207 100644 --- a/src/main/java/com/gmail/nossr50/skills/Axes.java +++ b/src/main/java/com/gmail/nossr50/skills/Axes.java @@ -164,7 +164,7 @@ public class Axes { if(targets >= 1 && derp.getWorld().getPVP()) { - Combat.dealDamage(target, dmgAmount); + Combat.dealDamage(target, dmgAmount, attacker); target.sendMessage(ChatColor.DARK_RED+"Struck by CLEAVE!"); targets--; continue; @@ -174,7 +174,7 @@ public class Axes { else { LivingEntity target = (LivingEntity)derp; - Combat.dealDamage(target, dmgAmount); + Combat.dealDamage(target, dmgAmount, attacker); targets--; } } diff --git a/src/main/java/com/gmail/nossr50/skills/Swords.java b/src/main/java/com/gmail/nossr50/skills/Swords.java index c3065e94e..dc025f881 100644 --- a/src/main/java/com/gmail/nossr50/skills/Swords.java +++ b/src/main/java/com/gmail/nossr50/skills/Swords.java @@ -152,7 +152,7 @@ public class Swords continue; if(targets >= 1 && derp.getWorld().getPVP()) { - Combat.dealDamage(target, dmgAmount); + Combat.dealDamage(target, dmgAmount, attacker); target.sendMessage(ChatColor.DARK_RED+"Struck by Serrated Strikes!"); Users.getProfile(target).addBleedTicks(5); targets--; @@ -165,7 +165,7 @@ public class Swords pluginx.misc.addToBleedQue((LivingEntity)derp); LivingEntity target = (LivingEntity)derp; - Combat.dealDamage(target, dmgAmount); + Combat.dealDamage(target, dmgAmount, attacker); targets--; } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 320ccd371..1cb6de2b2 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -265,6 +265,8 @@ General: Save_Interval: 10 #Allow mcMMO to report on basic anonymous usage Stats_Tracking: true + #Allow mcMMO to inform other plugins of damage being dealt + Event_Callback: true Excavation: Drops: Cake: true