Skip to content

Commit

Permalink
Added an OnPvP compatability event
Browse files Browse the repository at this point in the history
  • Loading branch information
VinyarionHyarmendacil committed Jul 29, 2019
1 parent 22b95eb commit f9c50aa
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package pvpmode.api.server.compatibility.events;

import cpw.mods.fml.common.eventhandler.*;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.DamageSource;
import pvpmode.api.common.EnumPvPMode;

/**
* Fired when a player attacks another player.
*
* @author Vinyarion
*
*/
@Cancelable
public class OnPvPEvent extends Event
{

private final EntityPlayer attacker;
private final EnumPvPMode attackerMode;
private final EntityPlayer victim;
private final EnumPvPMode victimMode;
private final float damageAmount;
private final DamageSource source;

public OnPvPEvent (EntityPlayer attacker, EnumPvPMode attackerMode, EntityPlayer victim, EnumPvPMode victimMode, float damageAmount, DamageSource source)
{
this.attacker = attacker;
this.attackerMode = attackerMode;
this.victim = victim;
this.victimMode = victimMode;
this.damageAmount = damageAmount;
this.source = source;
}

/**
* Returns the attacker
*/
public EntityPlayer getAttacker ()
{
return attacker;
}

/**
* Returns the attacker's mode
*/
public EnumPvPMode getAttackerMode ()
{
return attackerMode;
}

/**
* Returns the victim
*/
public EntityPlayer getVictim ()
{
return victim;
}

/**
* Returns the victim's mode
*/
public EnumPvPMode getVictimMode ()
{
return victimMode;
}

/**
* Returns the dealt damage amount
*/
public float getDamageAmount ()
{
return damageAmount;
}

/**
* Returns the damage source
*/
public DamageSource getSource ()
{
return source;
}

}
12 changes: 12 additions & 0 deletions src/main/java/pvpmode/internal/server/PvPServerEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import net.minecraftforge.event.entity.player.PlayerDropsEvent;
import pvpmode.PvPMode;
import pvpmode.api.common.EnumPvPMode;
import pvpmode.api.common.utils.PvPCommonUtils;
import pvpmode.api.common.version.*;
import pvpmode.api.server.PvPData;
import pvpmode.api.server.compatibility.events.*;
Expand Down Expand Up @@ -59,6 +60,17 @@ public void interceptPvP (LivingAttackEvent event)

boolean cancel = false;

if (MinecraftForge.EVENT_BUS.post (new OnPvPEvent (attacker, attackerMode, victim, victimMode, event.ammount, event.source)))
{
cancel = true;
}

if (cancel)
{
event.setCanceled (true);
return;
}

if (attackerMode != EnumPvPMode.ON)
{
if (attacker == event.source.getEntity ())
Expand Down

0 comments on commit f9c50aa

Please sign in to comment.