weapons/src/main/java/pw/kaboom/weapons/modules/weapons/WeaponSniper.java

70 lines
2.4 KiB
Java
Raw Normal View History

2019-12-17 15:12:51 +00:00
package pw.kaboom.weapons.modules.weapons;
2019-09-19 15:33:22 +00:00
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.entity.Snowball;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextDecoration;
2019-12-17 15:12:51 +00:00
public final class WeaponSniper {
2022-05-20 01:44:37 +00:00
private WeaponSniper() {
}
2019-12-17 15:12:51 +00:00
public static void leftClick(final Material item, final Component name,
final PlayerInteractEvent event) {
if (item == Material.IRON_HORSE_ARMOR && Component.text("Sniper")
.decoration(TextDecoration.ITALIC, false).equals(name)) {
2022-05-20 01:44:37 +00:00
final Player player = event.getPlayer();
final Location eyeLocation = player.getEyeLocation();
final Vector velocity = eyeLocation.getDirection().multiply(12);
2019-09-19 15:33:22 +00:00
2022-05-20 01:44:37 +00:00
final Snowball snowball = player.launchProjectile(Snowball.class);
snowball.setShooter(player);
snowball.setVelocity(velocity);
2019-09-19 15:33:22 +00:00
2022-05-20 01:44:37 +00:00
final World world = player.getWorld();
final float volume = 1.0F;
final float pitch = 63.0F;
2019-09-19 15:33:22 +00:00
2022-05-20 01:44:37 +00:00
world.playSound(
eyeLocation,
Sound.BLOCK_PISTON_CONTRACT,
volume,
pitch
);
event.setCancelled(true);
}
}
2019-09-19 15:33:22 +00:00
public static void rightClick(final Material item, final Component name,
final PlayerInteractEvent event) {
if (item == Material.IRON_HORSE_ARMOR && Component.text("Sniper")
.decoration(TextDecoration.ITALIC, false).equals(name)) {
2022-05-20 01:44:37 +00:00
final Player player = event.getPlayer();
2019-12-17 15:12:51 +00:00
2022-05-20 01:44:37 +00:00
if (player.hasPotionEffect(PotionEffectType.SLOW)) {
player.removePotionEffect(PotionEffectType.SLOW);
} else {
final int duration = 90000;
final int amplifier = 7;
2019-09-19 15:33:22 +00:00
2022-05-20 01:44:37 +00:00
final PotionEffect effect = new PotionEffect(
PotionEffectType.SLOW,
duration,
amplifier
);
player.addPotionEffect(effect);
}
event.setCancelled(true);
}
}
2019-09-19 15:33:22 +00:00
}