Make throwable tnt track the damager

This commit is contained in:
Sam 2018-01-10 14:22:57 +00:00 committed by Alexander Meech
parent 6471e00af5
commit 7c533df0a5

View File

@ -1,12 +1,18 @@
package nautilus.game.arcade.game.modules; package nautilus.game.arcade.game.modules;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Effect; import org.bukkit.Effect;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed; import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -17,15 +23,23 @@ import mineplex.core.common.util.UtilEvent.ActionType;
import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.itemstack.ItemBuilder; import mineplex.core.itemstack.ItemBuilder;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
public class ThrowableTNTModule extends Module public class ThrowableTNTModule extends Module
{ {
private final Map<Entity, Player> _throwers;
private ItemStack _tntItem; private ItemStack _tntItem;
private int _fuseTicks = 60; private int _fuseTicks = 60;
private boolean _throwAndDrop; private boolean _throwAndDrop;
private double _throwStrength = 1.3; private double _throwStrength = 1.3;
public ThrowableTNTModule()
{
_throwers = new HashMap<>();
}
@Override @Override
protected void setup() protected void setup()
{ {
@ -97,4 +111,21 @@ public class ThrowableTNTModule extends Module
player.playEffect(location, Effect.GHAST_SHOOT, 0); player.playEffect(location, Effect.GHAST_SHOOT, 0);
} }
} }
@EventHandler(priority = EventPriority.LOWEST)
public void explosion(CustomDamageEvent event)
{
if (event.GetCause() != DamageCause.ENTITY_EXPLOSION)
{
return;
}
Entity entity = event.GetDamagerEntity(false);
Player thrower = _throwers.get(entity);
if (thrower != null)
{
event.SetDamager(thrower);
}
}
} }