Update several perks to support vanilla damage system and kit progression

This commit is contained in:
AlexTheCoder 2017-05-04 18:59:41 -04:00
parent 7b70695e12
commit ac98213d28
4 changed files with 152 additions and 24 deletions

View File

@ -1,6 +1,16 @@
package nautilus.game.arcade.kit.perks;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
@ -13,20 +23,18 @@ import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.kit.Perk;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
public class PerkBomberHG extends Perk
{
private int _spawnRate;
private int _max;
private boolean _onlyRestrictNamed;
public PerkBomberHG(int spawnRate, int max)
{
this(spawnRate, max, false);
}
public PerkBomberHG(int spawnRate, int max, boolean onlyRestrictNamed)
{
super("Explosives", new String[]
{
@ -35,6 +43,7 @@ public class PerkBomberHG extends Perk
_spawnRate = spawnRate;
_max = max;
_onlyRestrictNamed = onlyRestrictNamed;
}
public void Apply(Player player)
@ -53,13 +62,19 @@ public class PerkBomberHG extends Perk
if (!Kit.HasKit(cur))
continue;
if (!hasPerk(cur))
continue;
if (!Manager.GetGame().IsAlive(cur))
continue;
if (!Recharge.Instance.use(cur, GetName(), _spawnRate*1000, false, false))
continue;
if (UtilInv.contains(cur, Material.TNT, (byte)0, _max))
if (_onlyRestrictNamed ? UtilInv.contains(cur, F.item("Throwing TNT"), Material.TNT, (byte)0, _max) : UtilInv.contains(cur, Material.TNT, (byte)0, _max))
continue;
if (UtilPlayer.isSpectator(cur))
continue;
//Add
@ -75,7 +90,13 @@ public class PerkBomberHG extends Perk
if (event.isCancelled())
return;
if (!UtilInv.IsItem(event.getItemDrop().getItemStack(), Material.TNT, (byte)0))
if (_onlyRestrictNamed ? !UtilInv.IsItem(event.getItemDrop().getItemStack(), F.item("Throwing TNT"), Material.TNT, (byte)0) : !UtilInv.IsItem(event.getItemDrop().getItemStack(), Material.TNT, (byte)0))
return;
if (!Kit.HasKit(event.getPlayer()))
return;
if (!hasPerk(event.getPlayer()))
return;
//Cancel
@ -91,23 +112,33 @@ public class PerkBomberHG extends Perk
//boolean containerOpen = !(event.getView().getTopInventory().getHolder() instanceof Player);
boolean clickInContainer = event.getClickedInventory() != null && !(event.getClickedInventory().getHolder() instanceof Player);
if(clickInContainer)
if (clickInContainer)
{
return;
}
if (!(event.getWhoClicked() instanceof Player))
return;
if (!Kit.HasKit((Player)event.getWhoClicked()))
return;
if (!hasPerk((Player)event.getWhoClicked()))
return;
UtilInv.DisallowMovementOf(event, "Throwing TNT", Material.TNT, (byte) 0, true);
}
@EventHandler
public void TNTDeathRemove(PlayerDeathEvent event)
{
HashSet<org.bukkit.inventory.ItemStack> remove = new HashSet<org.bukkit.inventory.ItemStack>();
Set<ItemStack> remove = new HashSet<>();
for (org.bukkit.inventory.ItemStack item : event.getDrops())
if (UtilInv.IsItem(item, Material.TNT, (byte)0))
for (ItemStack item : event.getDrops())
if (_onlyRestrictNamed ? UtilInv.IsItem(item, "Throwing TNT", Material.TNT, (byte)0) : UtilInv.IsItem(item, Material.TNT, (byte)0))
remove.add(item);
for (org.bukkit.inventory.ItemStack item : remove)
for (ItemStack item : remove)
event.getDrops().remove(item);
}
}

View File

@ -1,13 +1,16 @@
package nautilus.game.arcade.kit.perks;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.kit.Perk;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import mineplex.core.Managers;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import mineplex.minecraft.game.core.damage.DamageManager;
import nautilus.game.arcade.kit.Perk;
public class PerkFallModifier extends Perk
{
private double _fall;
@ -41,4 +44,28 @@ public class PerkFallModifier extends Perk
event.AddMod("Fall Modifier", "Reduce damage", _fall, false);
}
}
@EventHandler(priority = EventPriority.HIGH)
public void handle(EntityDamageEvent event)
{
if (Managers.get(DamageManager.class).IsEnabled())
{
return;
}
if (event.getCause() != DamageCause.FALL)
return;
if (!(event.getEntity() instanceof Player))
return;
Player player = (Player) event.getEntity();
if (!Kit.HasKit(player))
return;
if (!Manager.IsAlive(player))
return;
event.setDamage(event.getDamage() * _fall);
}
}

View File

@ -183,6 +183,9 @@ public class PerkFletcher extends Perk
if (!isFletchedArrow(event.getItemDrop().getItemStack()))
return;
if (!hasPerk(event.getPlayer()))
return;
//Cancel
event.setCancelled(true);
@ -207,6 +210,15 @@ public class PerkFletcher extends Perk
@EventHandler
public void FletchInvClick(InventoryClickEvent event)
{
if (!(event.getWhoClicked() instanceof Player))
{
return;
}
if (!hasPerk((Player)event.getWhoClicked()))
{
return;
}
UtilInv.DisallowMovementOf(event, _name, Material.ARROW, (byte)0, true);
}

View File

@ -3,23 +3,33 @@ package nautilus.game.arcade.kit.perks;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import mineplex.core.Managers;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import mineplex.minecraft.game.core.damage.DamageManager;
import nautilus.game.arcade.kit.Perk;
public class PerkIronSkin extends Perk
{
private double _reduction;
private boolean _percentage;
public PerkIronSkin(double d)
public PerkIronSkin(double d)
{
this(d, false);
}
public PerkIronSkin(double d, boolean percentage)
{
super("Iron Skin", new String[]
{
"You take " + d + " less damage from attacks",
"You take " + (d * (percentage ? 100 : 1)) + (percentage ? "%" : "") + " less damage from attacks",
});
_reduction = d;
_percentage = percentage;
}
@EventHandler(priority = EventPriority.HIGH)
@ -40,6 +50,54 @@ public class PerkIronSkin extends Perk
if (!Kit.HasKit(damagee))
return;
event.AddMod(damagee.getName(), GetName(), -_reduction, false);
if (!hasPerk(damagee))
return;
if (_percentage)
{
event.AddMult(damagee.getName(), GetName(), _reduction, false);
}
else
{
event.AddMod(damagee.getName(), GetName(), -_reduction, false);
}
}
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void damageDecrease(EntityDamageEvent event)
{
if (Managers.get(DamageManager.class).IsEnabled())
{
return;
}
if (event.getCause() == DamageCause.FIRE_TICK)
return;
if (event.getDamage() <= 1)
return;
if (!(event.getEntity() instanceof Player))
return;
Player damagee = (Player) event.getEntity();
if (!Kit.HasKit(damagee))
return;
if (!hasPerk(damagee))
return;
if (!Manager.IsAlive(damagee))
return;
if (_percentage)
{
event.setDamage(event.getDamage() * _reduction);
}
else
{
event.setDamage(event.getDamage() - _reduction);
}
}
}