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 #Versions without changelogs probably had very small misc fixes, like tweaks to the source code
Version 2.0-dev Version 2.0-dev
- Fixed /mcability not respecting permissions - 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 Version 1.2.12
- Fixed issue that caused terrible MySQL performance and negative XP on levelup (Issue #134) - Fixed issue that caused terrible MySQL performance and negative XP on levelup (Issue #134)

View File

@ -16,6 +16,7 @@
*/ */
package com.gmail.nossr50; package com.gmail.nossr50;
import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.*; import org.bukkit.entity.*;
import org.bukkit.event.entity.EntityDamageByEntityEvent; 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.config.LoadProperties;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.events.FakeEntityDamageByEntityEvent;
import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.locale.mcLocale;
import com.gmail.nossr50.party.Party; import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.skills.Acrobatics; import com.gmail.nossr50.skills.Acrobatics;
@ -87,10 +89,12 @@ public class Combat
event.setDamage(event.getDamage() + (event.getDamage() / 2)); event.setDamage(event.getDamage() + (event.getDamage() / 2));
//Handle Ability Interactions //Handle Ability Interactions
if(PPa.getSkullSplitterMode() && m.isAxes(attacker.getItemInHand())) if(!(event instanceof FakeEntityDamageByEntityEvent)) {
Axes.applyAoeDamage(attacker, eventb, pluginx); if(PPa.getSkullSplitterMode() && m.isAxes(attacker.getItemInHand()))
if(PPa.getSerratedStrikesMode() && m.isSwords(attacker.getItemInHand())) Axes.applyAoeDamage(attacker, eventb, pluginx);
Swords.applySerratedStrikes(attacker, eventb, pluginx); if(PPa.getSerratedStrikesMode() && m.isSwords(attacker.getItemInHand()))
Swords.applySerratedStrikes(attacker, eventb, pluginx);
}
//Experience //Experience
if(event.getEntity() instanceof Player) 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) public static boolean pvpAllowed(EntityDamageByEntityEvent event, World world)

View File

@ -43,7 +43,7 @@ public class LoadProperties {
diamondArmor, woodenTools, stoneTools, ironTools, goldTools, diamondArmor, woodenTools, stoneTools, ironTools, goldTools,
diamondTools, enderPearl, blazeRod, records, glowstoneDust, diamondTools, enderPearl, blazeRod, records, glowstoneDust,
fishingDiamonds, aDisplayNames, pDisplayNames, enableSmoothToMossy, fishingDiamonds, aDisplayNames, pDisplayNames, enableSmoothToMossy,
enableDirtToGrass, statsTracking; enableDirtToGrass, statsTracking, eventCallback;
public static String MySQLtablePrefix, MySQLuserName, public static String MySQLtablePrefix, MySQLuserName,
MySQLserverName, MySQLdbName, MySQLdbPass, nWood, nStone, MySQLserverName, MySQLdbName, MySQLdbPass, nWood, nStone,
@ -299,6 +299,7 @@ public class LoadProperties {
enableRegen = readBoolean("General.HP_Regeneration.Enabled", true); enableRegen = readBoolean("General.HP_Regeneration.Enabled", true);
saveInterval = readInteger("General.Save_Interval", 10); saveInterval = readInteger("General.Save_Interval", 10);
statsTracking = readBoolean("General.Stats_Tracking", true); statsTracking = readBoolean("General.Stats_Tracking", true);
eventCallback = readBoolean("General.Event_Callback", true);
enableCobbleToMossy = readBoolean("Skills.Herbalism.Green_Thumb.Cobble_To_Mossy", true); enableCobbleToMossy = readBoolean("Skills.Herbalism.Green_Thumb.Cobble_To_Mossy", true);
enableSmoothToMossy = readBoolean("Skills.Herbalism.Green_Thumb.SmoothBrick_To_MossyBrick", true); enableSmoothToMossy = readBoolean("Skills.Herbalism.Green_Thumb.SmoothBrick_To_MossyBrick", true);

View File

@ -1,29 +1,29 @@
/* /*
This file is part of mcMMO. This file is part of mcMMO.
mcMMO is free software: you can redistribute it and/or modify mcMMO is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
mcMMO is distributed in the hope that it will be useful, mcMMO is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with mcMMO. If not, see <http://www.gnu.org/licenses/>. 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.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
public class FakeBlockBreakEvent extends BlockBreakEvent { public class FakeBlockBreakEvent extends BlockBreakEvent {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public FakeBlockBreakEvent(Block theBlock, Player player) { public FakeBlockBreakEvent(Block theBlock, Player player) {
super(theBlock, player); super(theBlock, 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.locale.mcLocale;
import com.gmail.nossr50.skills.*; import com.gmail.nossr50.skills.*;
import com.gmail.nossr50.datatypes.FakeBlockBreakEvent; import com.gmail.nossr50.events.FakeBlockBreakEvent;
public class mcBlockListener implements Listener public class mcBlockListener implements Listener
{ {

View File

@ -29,8 +29,8 @@ import org.bukkit.entity.*;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.config.*; import com.gmail.nossr50.config.*;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.FakeBlockBreakEvent;
import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.events.FakeBlockBreakEvent;
import com.gmail.nossr50.events.McMMOItemSpawnEvent; import com.gmail.nossr50.events.McMMOItemSpawnEvent;
public class m public class m

View File

@ -164,7 +164,7 @@ public class Axes {
if(targets >= 1 && derp.getWorld().getPVP()) if(targets >= 1 && derp.getWorld().getPVP())
{ {
Combat.dealDamage(target, dmgAmount); Combat.dealDamage(target, dmgAmount, attacker);
target.sendMessage(ChatColor.DARK_RED+"Struck by CLEAVE!"); target.sendMessage(ChatColor.DARK_RED+"Struck by CLEAVE!");
targets--; targets--;
continue; continue;
@ -174,7 +174,7 @@ public class Axes {
else else
{ {
LivingEntity target = (LivingEntity)derp; LivingEntity target = (LivingEntity)derp;
Combat.dealDamage(target, dmgAmount); Combat.dealDamage(target, dmgAmount, attacker);
targets--; targets--;
} }
} }

View File

@ -152,7 +152,7 @@ public class Swords
continue; continue;
if(targets >= 1 && derp.getWorld().getPVP()) if(targets >= 1 && derp.getWorld().getPVP())
{ {
Combat.dealDamage(target, dmgAmount); Combat.dealDamage(target, dmgAmount, attacker);
target.sendMessage(ChatColor.DARK_RED+"Struck by Serrated Strikes!"); target.sendMessage(ChatColor.DARK_RED+"Struck by Serrated Strikes!");
Users.getProfile(target).addBleedTicks(5); Users.getProfile(target).addBleedTicks(5);
targets--; targets--;
@ -165,7 +165,7 @@ public class Swords
pluginx.misc.addToBleedQue((LivingEntity)derp); pluginx.misc.addToBleedQue((LivingEntity)derp);
LivingEntity target = (LivingEntity)derp; LivingEntity target = (LivingEntity)derp;
Combat.dealDamage(target, dmgAmount); Combat.dealDamage(target, dmgAmount, attacker);
targets--; targets--;
} }
} }

View File

@ -265,6 +265,8 @@ General:
Save_Interval: 10 Save_Interval: 10
#Allow mcMMO to report on basic anonymous usage #Allow mcMMO to report on basic anonymous usage
Stats_Tracking: true Stats_Tracking: true
#Allow mcMMO to inform other plugins of damage being dealt
Event_Callback: true
Excavation: Excavation:
Drops: Drops:
Cake: true Cake: true