Re-added event calling

Re-added other dealDamage methods
Added FakeEntityDamageByEntityEvent for us to filter our own mess out, this was the issue with Skull Splitter and Serrated Strikes earlier (a loop)
Moved FakeBlockBreakEvent to be with other events
Added configuration option to control event calling
Learned how to changelog
Broke those cuffs
This commit is contained in:
NuclearW 2012-02-15 16:57:48 -05:00
parent 06d3d8a18f
commit 40af51fc05
10 changed files with 106 additions and 41 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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);

View File

@ -14,7 +14,7 @@
You should have received a copy of the GNU General Public License
along with mcMMO. If not, see <http://www.gnu.org/licenses/>.
*/
package com.gmail.nossr50.datatypes;
package com.gmail.nossr50.events;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;

View File

@ -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);
}
}

View File

@ -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
{

View File

@ -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

View File

@ -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--;
}
}

View File

@ -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--;
}
}

View File

@ -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