package nautilus.game.arcade.kit.perks; import java.util.HashMap; import java.util.HashSet; import mineplex.core.common.util.C; import mineplex.core.common.util.UtilAction; import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilEnt; import mineplex.core.common.util.UtilEvent; import mineplex.core.common.util.UtilGear; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilEvent.ActionType; import mineplex.core.projectile.IThrown; import mineplex.core.projectile.ProjectileUser; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.minecraft.game.core.damage.CustomDamageEvent; import nautilus.game.arcade.kit.Perk; import nautilus.game.arcade.kit.perks.event.PerkBlockGrabEvent; import nautilus.game.arcade.kit.perks.event.PerkBlockThrowEvent; import org.bukkit.Effect; import org.bukkit.block.Block; import org.bukkit.entity.FallingBlock; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.player.PlayerInteractEvent; public class PerkBlockToss extends Perk implements IThrown { private HashMap _holding = new HashMap(); private HashMap _charge = new HashMap(); private HashSet _charged = new HashSet(); private HashMap _falling = new HashMap(); public PerkBlockToss() { super("Block Toss", new String[] { C.cYellow + "Hold Block" + C.cGray + " to " + C.cGreen + "Grab Block", C.cYellow + "Release Block" + C.cGray + " to " + C.cGreen + "Throw Block" }); } @EventHandler public void Grab(PlayerInteractEvent event) { Player player = event.getPlayer(); if (!UtilEvent.isAction(event, ActionType.R_BLOCK)) return; if (!Kit.HasKit(player)) return; if (!UtilGear.isSword(player.getItemInHand())) return; if (_holding.containsKey(player)) return; Block grab = event.getClickedBlock(); if (UtilBlock.usable(grab)) return; //Event PerkBlockGrabEvent blockEvent = new PerkBlockGrabEvent(player, grab.getTypeId(), grab.getData()); UtilServer.getServer().getPluginManager().callEvent(blockEvent); System.out.println("grab event"); //Block to Item FallingBlock block = player.getWorld().spawnFallingBlock(player.getEyeLocation(), event.getClickedBlock().getType(), (byte)0); Manager.GetBlockRestore().Add(event.getClickedBlock(), 0, (byte)0, 10000); //Action player.eject(); player.setPassenger(block); _holding.put(player, block); _falling.put(block, player); _charge.put(player, System.currentTimeMillis()); //Effect player.getWorld().playEffect(event.getClickedBlock().getLocation(), Effect.STEP_SOUND, block.getMaterial().getId()); } @EventHandler public void Throw(UpdateEvent event) { if (event.getType() != UpdateType.TICK) return; HashSet voidSet = new HashSet(); HashSet throwSet = new HashSet(); for (Player cur : _holding.keySet()) { if (cur.getPassenger() == null) { voidSet.add(cur); continue; } if (_holding.get(cur).getVehicle() == null) { voidSet.add(cur); continue; } if (!_holding.get(cur).getVehicle().equals(cur)) { voidSet.add(cur); continue; } //Throw if (!cur.isBlocking()) throwSet.add(cur); //Charged Tick if (!_charged.contains(cur)) if (System.currentTimeMillis() - _charge.get(cur) > 1000) { _charged.add(cur); cur.playEffect(cur.getLocation(), Effect.CLICK1, 0); } } for (Player cur : voidSet) { FallingBlock block = _holding.remove(cur); _charge.remove(cur); _charged.remove(cur); block.remove(); //Event PerkBlockThrowEvent blockEvent = new PerkBlockThrowEvent(cur); UtilServer.getServer().getPluginManager().callEvent(blockEvent); } for (Player cur : throwSet) { FallingBlock block = _holding.remove(cur); _charged.remove(cur); long charge = System.currentTimeMillis() - _charge.remove(cur); //Throw cur.eject(); double mult = 1; if (charge < 1000) mult = mult * (charge/1000d); //Action UtilAction.velocity(block, cur.getLocation().getDirection(), mult, false, 0, 0, 1, true); Manager.GetProjectile().AddThrow(block, cur, this, -1, true, true, true, null, 0, 0, null, 0, UpdateType.FASTEST, 2d); //Event PerkBlockThrowEvent blockEvent = new PerkBlockThrowEvent(cur); UtilServer.getServer().getPluginManager().callEvent(blockEvent); } } @Override public void Collide(LivingEntity target, Block block, ProjectileUser data) { if (target == null) return; //Damage Event Manager.GetDamage().NewDamageEvent(target, data.GetThrower(), null, DamageCause.PROJECTILE, 2 + (data.GetThrown().getVelocity().length() * 10), true, true, false, UtilEnt.getName(data.GetThrower()), GetName()); //Block to Item if (data.GetThrown() instanceof FallingBlock) { FallingBlock thrown = (FallingBlock) data.GetThrown(); FallingBlock newThrown = data.GetThrown().getWorld().spawnFallingBlock(data.GetThrown().getLocation(), thrown.getMaterial(), (byte)0); //Remove Old _falling.remove(thrown); thrown.remove(); //Add New if (data.GetThrower() instanceof Player) _falling.put(newThrown, (Player)data.GetThrower()); } } @Override public void Idle(ProjectileUser data) { } @Override public void Expire(ProjectileUser data) { } @EventHandler public void BlockForm(EntityChangeBlockEvent event) { if (!(event.getEntity() instanceof FallingBlock)) return; FallingBlock falling = (FallingBlock)event.getEntity(); falling.getWorld().playEffect(event.getBlock().getLocation(), Effect.STEP_SOUND, falling.getBlockId()); _falling.remove(falling); falling.remove(); event.setCancelled(true); } @EventHandler public void Knockback(CustomDamageEvent event) { if (event.GetReason() == null || !event.GetReason().contains(GetName())) return; event.AddKnockback(GetName(), 2.5); } }