netsky blade gadget

This commit is contained in:
ImproperIssues
2023-06-02 23:20:53 -07:00
parent ba11d74a4a
commit 63c3461c21
3 changed files with 43 additions and 14 deletions

View File

@@ -3,10 +3,13 @@ package fun.ogre.ogredupealias.events;
import fun.ogre.ogredupealias.data.PlacedStructures; import fun.ogre.ogredupealias.data.PlacedStructures;
import fun.ogre.ogredupealias.plugin.InventoryPresets; import fun.ogre.ogredupealias.plugin.InventoryPresets;
import fun.ogre.ogredupealias.plugin.ItemPresets; import fun.ogre.ogredupealias.plugin.ItemPresets;
import fun.ogre.ogredupealias.utils.Cooldown;
import fun.ogre.ogredupealias.utils.ItemUtils; import fun.ogre.ogredupealias.utils.ItemUtils;
import fun.ogre.ogredupealias.utils.RaycastUtils; import fun.ogre.ogredupealias.utils.RaycastUtils;
import fun.ogre.ogredupealias.utils.SoundPlayer;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Particle; import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
@@ -22,18 +25,19 @@ import org.bukkit.util.Vector;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID;
public class InteractionListener implements Listener { public class InteractionListener implements Listener {
private static final Cooldown<UUID> netskySwordCooldown = new Cooldown<>();
@EventHandler @EventHandler
public void onClick(PlayerInteractEvent e) { public void onClick(PlayerInteractEvent e) {
try { try {
this.processTable(e); this.processTable(e);
this.handleNetskyBlade(e); this.handleNetskyBlade(e);
} }
catch (Exception ignore) { catch (Exception ignore) {}
ignore.printStackTrace();
}
} }
private void processTable(PlayerInteractEvent e) { private void processTable(PlayerInteractEvent e) {
@@ -51,17 +55,26 @@ public class InteractionListener implements Listener {
ItemStack stack = e.getItem(); ItemStack stack = e.getItem();
Action a = e.getAction(); Action a = e.getAction();
if (ItemUtils.matchDisplay(stack, ItemPresets.NETSKY_BLADE)) { if (ItemUtils.matchDisplay(stack, ItemPresets.NETSKY_BLADE) && !netskySwordCooldown.isOnCooldown(p.getUniqueId())) {
netskySwordCooldown.setCooldown(p.getUniqueId(), 1000);
switch (a) { switch (a) {
case LEFT_CLICK_BLOCK, LEFT_CLICK_AIR -> { case LEFT_CLICK_BLOCK, LEFT_CLICK_AIR -> {
Location start = p.getEyeLocation(); Location start = p.getEyeLocation();
Vector rotation = p.getLocation().getDirection().normalize(); Vector rotation = p.getLocation().getDirection().normalize();
SoundPlayer shootSound = new SoundPlayer(start, Sound.ENTITY_BLAZE_SHOOT, 1, 1);
shootSound.playWithin(20);
RaycastUtils.raycast(start, rotation, 20, 0.5, 1, point -> { RaycastUtils.raycast(start, rotation, 20, 0.5, 1, point -> {
if (point == null || point.getWorld() == null) return false; if (point == null || point.getWorld() == null) return false;
World w = point.getWorld(); World w = point.getWorld();
SoundPlayer popSound = new SoundPlayer(start, Sound.BLOCK_LAVA_POP, 1, 1);
SoundPlayer hissSound = new SoundPlayer(start, Sound.BLOCK_LAVA_EXTINGUISH, 1, 1);
w.spawnParticle(Particle.FLAME, point, 1, 0, 0, 0, 0); w.spawnParticle(Particle.FLAME, point, 1, 0, 0, 0, 0);
w.spawnParticle(Particle.LAVA, point, 1, 0, 0, 0, 0);
popSound.playWithin(3);
List<Entity> targets = new ArrayList<>(w.getNearbyEntities(point, 2, 2, 2, entity -> { List<Entity> targets = new ArrayList<>(w.getNearbyEntities(point, 2, 2, 2, entity -> {
return entity instanceof LivingEntity living && !living.isDead() && living != p; return entity instanceof LivingEntity living && !living.isDead() && living != p;
@@ -69,12 +82,21 @@ public class InteractionListener implements Listener {
targets.forEach(target -> { targets.forEach(target -> {
if (target instanceof LivingEntity living) { if (target instanceof LivingEntity living) {
living.damage(2.0, p); living.damage(5.0, p);
living.setFireTicks(60); living.setFireTicks(60);
hissSound.playWithin(20);
} }
}); });
return !targets.isEmpty(); return !targets.isEmpty();
}, result -> {
if (result == null || result.getWorld() == null) return;
World w = result.getWorld();
SoundPlayer explodeSound = new SoundPlayer(result, Sound.ENTITY_GENERIC_EXPLODE, 1, 1.5F);
w.spawnParticle(Particle.CAMPFIRE_COSY_SMOKE, result, 20, 0, 0, 0, 0.1);
explodeSound.playWithin(128);
}); });
} }
case RIGHT_CLICK_AIR, RIGHT_CLICK_BLOCK -> { case RIGHT_CLICK_AIR, RIGHT_CLICK_BLOCK -> {
@@ -83,7 +105,7 @@ public class InteractionListener implements Listener {
p.getWorld().spawn(start, Fireball.class, fireball -> { p.getWorld().spawn(start, Fireball.class, fireball -> {
fireball.setDirection(rotation); fireball.setDirection(rotation);
fireball.setVelocity(rotation.multiply(3)); fireball.setVelocity(rotation);
fireball.setShooter(p); fireball.setShooter(p);
}); });
} }

View File

@@ -5,6 +5,7 @@ import org.bukkit.Location;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.function.Predicate; import java.util.function.Predicate;
import static fun.ogre.ogredupealias.OgreDupeAlias.instance; import static fun.ogre.ogredupealias.OgreDupeAlias.instance;
@@ -33,20 +34,26 @@ public class RaycastUtils {
return start.clone().add(rotation.clone().multiply(distance)); return start.clone().add(rotation.clone().multiply(distance));
} }
public static Location raycast(Location start, Vector rotation, double distance, double frequency, long tickInterval, Predicate<Location> hitCondition) { public static void raycast(Location start, Vector rotation, double distance, double frequency, long tickInterval, Predicate<Location> hitCondition, Consumer<Location> onhit) {
AtomicReference<Location> result = new AtomicReference<>(); AtomicReference<Location> result = new AtomicReference<>();
final double[] i = { 0.0 }; AtomicReference<Double> val = new AtomicReference<>(0.0);
AtomicReference<Boolean> active = new AtomicReference<>(true);
Bukkit.getScheduler().scheduleSyncRepeatingTask(instance, () -> { Bukkit.getScheduler().scheduleSyncRepeatingTask(instance, () -> {
if ((i[0] += frequency) <= distance && result.get() == null) { if (val.get() <= distance && result.get() == null && active.get()) {
Location point = start.clone().add(rotation.clone().multiply(i[0])); Location point = start.clone().add(rotation.clone().multiply(val.get()));
if (hitCondition.test(point)) { if (hitCondition.test(point)) {
result.set(point); result.set(point);
} }
val.set(val.get() + frequency);
} }
else if (result.get() != null) { else if (result.get() == null) {
result.set(start.clone().add(rotation.clone().multiply(distance))); result.set(start.clone().add(rotation.clone().multiply(distance)));
} }
else if (active.get()) {
onhit.accept(result.get());
active.set(false);
}
}, 0, tickInterval); }, 0, tickInterval);
return result.get() != null ? result.get() : start.clone().add(rotation.clone().multiply(distance));
} }
} }

View File

@@ -58,7 +58,7 @@ public class SoundPlayer {
*/ */
public void playWithin(double distance) { public void playWithin(double distance) {
for (Player p : Bukkit.getOnlinePlayers()) { for (Player p : Bukkit.getOnlinePlayers()) {
if (p != null && p.getWorld() == this.location.getWorld() && p.getLocation().distanceSquared(this.location) < distance) { if (p != null && p.getWorld() == this.location.getWorld() && p.getLocation().distance(this.location) < distance) {
p.playSound(this.location,this.sound,this.volume,this.pitch); p.playSound(this.location,this.sound,this.volume,this.pitch);
} }
} }
@@ -71,7 +71,7 @@ public class SoundPlayer {
*/ */
public void playWithinAt(double distance) { public void playWithinAt(double distance) {
for (Player p : Bukkit.getOnlinePlayers()) { for (Player p : Bukkit.getOnlinePlayers()) {
if (p != null && p.getWorld() == this.location.getWorld() && p.getLocation().distanceSquared(this.location) < distance) { if (p != null && p.getWorld() == this.location.getWorld() && p.getLocation().distance(this.location) < distance) {
p.playSound(p.getLocation(),this.sound,this.volume,this.pitch); p.playSound(p.getLocation(),this.sound,this.volume,this.pitch);
} }
} }