package de.leafbla.meinkraft.roleplay.fighter; import de.leafbla.meinkraft.Main; import de.leafbla.meinkraft.roleplay.ManaAble; import de.leafbla.meinkraft.roleplay.PlayerRole; import de.leafbla.meinkraft.roleplay.Role; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.block.Action; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; import java.util.List; import java.util.stream.Collectors; public class FighterRole extends PlayerRole implements ManaAble { private int mana; private boolean powerfist; public FighterRole(Main plugin, Player player) { super(plugin, player, Role.FIGHTER); } @Override public void start() { this.setMana(0); this.player.setWalkSpeed(0.3f); this.powerfist = false; this.player.setGravity(true); } @Override public void end() { player.setExp(0.5f); this.player.setWalkSpeed(0.2f); } @Override public int getMana() { return this.mana; } @Override public void setManaRaw(int mana) { this.mana = mana; } @Override public void onUpdateMana() { player.setExp((this.mana * 1.0f) / 100f); } boolean inAir = false; public void attackEntity(Entity entity, EntityDamageByEntityEvent event) { if (!(entity instanceof LivingEntity)) return; LivingEntity len = ((LivingEntity) entity); if (inAir) { event.setCancelled(true); len.damage(event.getDamage()); } this.player.playSound(player.getLocation(), Sound.BLOCK_ANVIL_LAND, 1, 1); if (powerfist) { event.setDamage(event.getDamage() * 4); entity.getWorld().createExplosion(entity.getLocation(), 0f, false, false, player); this.powerfist = false; } else this.addMana(10); } public void onInteract(PlayerInteractEvent event) { Player p = event.getPlayer(); if (p.getItemInHand().getType() == Material.AIR && (event.getAction() == Action.RIGHT_CLICK_BLOCK) && !this.powerfist) { if (this.mana < 30) return; this.addMana(-30); this.powerfist = true; p.playSound(p.getLocation(), Sound.BLOCK_STONE_BREAK, 1f, 1f); p.sendMessage("§eYou ready your fists."); } else if (p.getItemInHand().getType() == Material.CLAY_BALL) { roundHouseKick(); } if (p.getItemInHand().getType() == Material.BLAZE_ROD) { for (Entity en : p.getNearbyEntities(5, 5, 5)) { if (en instanceof LivingEntity) { LivingEntity len = ((LivingEntity) en); Vector dir = len.getLocation().toVector().subtract(p.getLocation().toVector()); if (Math.abs(dir.angle(p.getLocation().getDirection())) < 1.6) { len.setVelocity(dir.multiply(2).add(new Vector(0, .3, 0))); } } } } else if (!((LivingEntity) p).isOnGround()) { if (this.player.getLocation().getPitch() < 80) return; groundPound(); } if (this.player.getLocation().getPitch() > -80) return; upPunch(); } private void oldUpDown360Kick() { player.setVelocity(new Vector(0, 1, 0)); new BukkitRunnable() { @Override public void run() { player.setGravity(false); Location loc = player.getLocation(); loc.setPitch(0); player.teleport(loc); new BukkitRunnable() { int i = 0; final int MAX = 15; @Override public void run() { if (++i == MAX) { this.cancel(); new BukkitRunnable() { boolean once = true; @Override public void run() { if (once) { loc.setPitch(38); player.teleport(loc); player.setGravity(true); player.setFallDistance(0); player.setNoDamageTicks(40); player.setVelocity(new Vector(0, -2, 0)); once = false; } if (((LivingEntity) player).isOnGround()) { player.getWorld().createExplosion(player.getLocation(), 0f, false, false, player); for (Entity en : player.getNearbyEntities(2, 1, 2)) { if (en instanceof LivingEntity) { LivingEntity len = ((LivingEntity) en); Vector dir = len.getLocation().toVector().subtract(player.getLocation().toVector()).normalize(); len.setVelocity(dir.multiply(2).add(new Vector(0, 1, 0))); } } this.cancel(); } } }.runTaskTimer(plugin, 2, 1); return; } loc.setYaw(((loc.getYaw() + 180 + 360 / MAX) % 360) - 180); player.teleport(loc); } }.runTaskTimer(plugin, 0, 1); } }.runTaskLater(plugin, 15); } private void groundPound() { double startpos = this.player.getLocation().getY(); player.setVelocity(new Vector(0, -2, 0)); new BukkitRunnable() { @Override public void run() { player.setFallDistance(0); if (((LivingEntity) player).isOnGround()) { double falldistance = startpos - player.getLocation().getY(); if (falldistance > 7) player.getWorld().createExplosion(player.getLocation(), 2f, false, false, player); //for (Entity en : p.getNearbyEntities(2, 1, 2)) { // if (en instanceof LivingEntity) { // LivingEntity len = ((LivingEntity) en); // Vector dir = len.getLocation().toVector().subtract(p.getLocation().toVector()).normalize(); // len.setVelocity(dir.multiply(2).add(new Vector(0, 1, 0))); // } //} this.cancel(); } } }.runTaskTimer(plugin, 0, 1); } private void upPunch() { List affected = player.getNearbyEntities(1, 1, 1).stream().filter(en -> en instanceof LivingEntity).map(en -> (LivingEntity) en).collect(Collectors.toList()); affected.add(player); inAir = true; affected.forEach(e -> e.setVelocity(new Vector(0, 2, 0))); new BukkitRunnable() { @Override public void run() { //player.setGravity(false); affected.forEach(e -> e.setGravity(false)); affected.forEach(e -> e.setVelocity(new Vector(0, 0, 0))); new BukkitRunnable() { @Override public void run() { affected.forEach(e -> e.setGravity(true)); inAir = false; } }.runTaskLater(plugin, 20); } }.runTaskLater(plugin, 12); } private void roundHouseKick() { Location loc = player.getLocation(); new BukkitRunnable() { int i = 0; final int MAX = 10; @Override public void run() { if (++i == MAX) { this.cancel(); } loc.setYaw(((loc.getYaw() + 180 + 360 / MAX) % 360) - 180); player.teleport(loc); for (Entity en : player.getNearbyEntities(3, 2, 3)) { if (en instanceof LivingEntity) { LivingEntity len = ((LivingEntity) en); Vector dir = len.getLocation().toVector().subtract(player.getLocation().toVector()).normalize(); if (Math.abs(dir.angle(player.getLocation().getDirection())) < (2 * Math.PI / MAX)) { len.setVelocity(dir.multiply(2)); len.damage(3, player); } } } } }.runTaskTimer(plugin, 0, 1); } }