From 847730efe3c1dd65eed6e07bdd0ee0146eec4ded Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Mon, 9 Sep 2024 20:36:18 -0500 Subject: [PATCH] 1.20.6 (#16) * Update build.gradle.kts * Update TurretManager.java * Update PlayerInteractListener.java * Update TurretManager.java * Update build.gradle.kts --- build.gradle.kts | 8 +-- .../APTurrets/TurretManager.java | 33 +++------ .../listener/PlayerInteractListener.java | 68 ++++++++----------- 3 files changed, 43 insertions(+), 66 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 0371f24..24eb142 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -18,17 +18,17 @@ repositories { dependencies { api("org.jetbrains:annotations-java5:24.1.0") - paperweight.paperDevBundle("1.18.2-R0.1-SNAPSHOT") + paperweight.paperDevBundle("1.20.6-R0.1-SNAPSHOT") compileOnly("net.countercraft:movecraft:+") compileOnly("net.countercraft.movecraft.worldguard:movecraft-worldguard:+") - compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.0.7") + compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.0.10") compileOnly("com.github.MilkBowl:VaultAPI:1.7.1") } group = "com.snowleopard" -version = "3.0.0_beta-2_gradle" +version = "3.0.0_beta-3" description = "APTurrets" -java.toolchain.languageVersion = JavaLanguageVersion.of(17) +java.toolchain.languageVersion = JavaLanguageVersion.of(21) tasks.reobfJar { outputJar = layout.buildDirectory.file("libs/AP-Turrets.jar") diff --git a/src/main/java/com/snowleopard1863/APTurrets/TurretManager.java b/src/main/java/com/snowleopard1863/APTurrets/TurretManager.java index ae28b75..ae45585 100644 --- a/src/main/java/com/snowleopard1863/APTurrets/TurretManager.java +++ b/src/main/java/com/snowleopard1863/APTurrets/TurretManager.java @@ -74,8 +74,8 @@ public void mount(Player player, @NotNull Location signPos) { player.teleport(signPos); // Effects to add zoom and lock a player from jumping - player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 1000000, 6)); - player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 1000000, 200)); + player.addPotionEffect(new PotionEffect(PotionEffectType.SLOWNESS, 1000000, 6)); + player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP_BOOST, 1000000, 200)); } public void demount(Player player, @Nullable Location signPos) { @@ -90,8 +90,8 @@ public void demount(Player player, @Nullable Location signPos) { } // Remove potion effects and set their walking speed back to normal - player.removePotionEffect(PotionEffectType.JUMP); - player.removePotionEffect(PotionEffectType.SLOW); + player.removePotionEffect(PotionEffectType.JUMP_BOOST); + player.removePotionEffect(PotionEffectType.SLOWNESS); } public void fire(Player player) { @@ -115,7 +115,7 @@ public void fire(Player player) { if (runRaycast(player)) return; - Arrow arrow = launchArrow(player); + Arrow arrow = launchArrow(player, Config.TurretAmmo); // TODO: Support tags arrow.setCritical(true); World world = player.getWorld(); @@ -124,29 +124,16 @@ public void fire(Player player) { } @NotNull - private Arrow launchArrow(Player player) { - Arrow arrow; - try { - ServerPlayer nmsPlayer = (ServerPlayer) player.getClass().getMethod("getHandle").invoke(player); - ServerLevel nmsWorld = nmsPlayer.getLevel(); - net.minecraft.world.entity.projectile.Arrow nmsArrow = new net.minecraft.world.entity.projectile.Arrow(nmsWorld, nmsPlayer); - nmsArrow.setNoGravity(true); - nmsWorld.addFreshEntity(nmsArrow); - arrow = (Arrow) nmsArrow.getBukkitEntity(); - } catch (Exception e) { - throw new ArrowLaunchException("Something went wrong when trying to launch an arrow", e); - } - + private Arrow launchArrow(@NotNull Player player, ItemStack item) { + Arrow arrow = player.launchProjectile(Arrow.class); arrow.setShooter(player); + arrow.setGravity(false); Location offset = player.getLocation().add(player.getLocation().getDirection().multiply(4)); arrow.setVelocity(offset.getDirection().multiply(Config.ArrowVelocity)); - arrow.setBounce(false); arrow.setMetadata("isTurretBullet", new FixedMetadataValue(TurretsMain.getInstance(), true)); arrow.setKnockbackStrength(Config.KnockbackStrength); - double rand = Math.random(); - if (rand <= Config.IncindiaryChance) + if (Math.random() <= Config.IncindiaryChance) arrow.setFireTicks(500); - return arrow; } @@ -157,7 +144,7 @@ private boolean takeAmmo(Player player) { Block adjacentBlock = getBlockSignAttachedTo(signBlock); if (adjacentBlock instanceof InventoryHolder) { Inventory i = ((InventoryHolder) adjacentBlock.getState()).getInventory(); - if (i.containsAtLeast(new ItemStack(Config.TurretAmmo), 1)) { + if (i.containsAtLeast(Config.TurretAmmo, 1)) { i.remove(Config.TurretAmmo); return true; } diff --git a/src/main/java/com/snowleopard1863/APTurrets/listener/PlayerInteractListener.java b/src/main/java/com/snowleopard1863/APTurrets/listener/PlayerInteractListener.java index 2275561..8ea3802 100644 --- a/src/main/java/com/snowleopard1863/APTurrets/listener/PlayerInteractListener.java +++ b/src/main/java/com/snowleopard1863/APTurrets/listener/PlayerInteractListener.java @@ -18,38 +18,28 @@ public class PlayerInteractListener implements Listener { @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = false) - public void onClick(PlayerInteractEvent event) { - switch (event.getAction()) { - case RIGHT_CLICK_AIR: - rightClick(event); - break; - case RIGHT_CLICK_BLOCK: - rightClickBlock(event); - break; - case LEFT_CLICK_BLOCK: - leftClickBlock(event); - break; - case LEFT_CLICK_AIR: - case PHYSICAL: - default: - break; - } + public void onClick(@NotNull PlayerInteractEvent event) { + event.setCancelled(switch (event.getAction()) { + case RIGHT_CLICK_AIR -> rightClick(event); + case RIGHT_CLICK_BLOCK -> rightClickBlock(event); + case LEFT_CLICK_BLOCK -> leftClickBlock(event); + default -> false; + }); } - private void leftClickBlock(@NotNull PlayerInteractEvent event) { - if (event.getPlayer().getInventory().getItemInMainHand().getType() != Material.STONE_BUTTON) - return; - + private boolean leftClickBlock(@NotNull PlayerInteractEvent event) { Material type = event.getClickedBlock().getType(); - if(!Tag.SIGNS.isTagged(type)) - return; + if (!Tag.SIGNS.isTagged(type)) + return false; Sign sign = (Sign) event.getClickedBlock().getState(); if (!sign.getLine(0).equalsIgnoreCase("Mounted") || !sign.getLine(1).equalsIgnoreCase("Gun")) - return; - - // If a player left clicks the mounted gun with a stone button in hand, - // show them the statistics for the plugin (Damage, Knockback, Velocity, etc.) + return false; + + if (event.getPlayer().getInventory().getItemInMainHand().getType() != Material.STONE_BUTTON) + return true; + + // If a player left-clicks the mounted gun with a stone button in hand, show them the statistics for the plugin (Damage, Knockback, Velocity, etc.) event.getPlayer().sendMessage("\n" + ChatColor.GOLD + "Damage/Shot: " + ChatColor.GRAY + Config.Damage + "\n" + ChatColor.GOLD + "Delay Between Shots: " + ChatColor.GRAY + Config.DelayBetweenShots + "\n" @@ -57,48 +47,48 @@ private void leftClickBlock(@NotNull PlayerInteractEvent event) { + ChatColor.GOLD + "Fire Chance: " + ChatColor.GRAY + Config.IncindiaryChance * 100.0D + "%\n" + ChatColor.GOLD + "Knockback: " + ChatColor.GRAY + Config.KnockbackStrength + "\n" + ChatColor.GOLD + "Cost to Place: $" + ChatColor.GRAY + Config.CostToPlace); - event.setCancelled(true); + return true; } - private void rightClickBlock(@NotNull PlayerInteractEvent event) { + private boolean rightClickBlock(@NotNull PlayerInteractEvent event) { Material type = event.getClickedBlock().getType(); - if(!Tag.SIGNS.isTagged(type)) - return; + if (!Tag.SIGNS.isTagged(type)) + return false; Sign sign = (Sign) event.getClickedBlock().getState(); if (!sign.getLine(0).equalsIgnoreCase("Mounted") || !sign.getLine(1).equalsIgnoreCase("Gun")) - return; + return false; if (event.getClickedBlock().getRelative(BlockFace.DOWN).getType() == Material.SLIME_BLOCK) - return; + return true; Location signPos = event.getClickedBlock().getLocation(); signPos.setPitch(event.getPlayer().getLocation().getPitch()); signPos.setDirection(event.getPlayer().getVelocity()); TurretsMain.getInstance().getTurretManager().mount(event.getPlayer(), signPos); + return true; } - private void rightClick(PlayerInteractEvent event) { + private boolean rightClick(@NotNull PlayerInteractEvent event) { Player player = event.getPlayer(); if (!TurretsMain.getInstance().getTurretManager().isOnTurret(player) || !player.hasPermission("ap-turrets.use")) - return; + return false; if (player.getInventory().getItemInMainHand().getType() == Material.MILK_BUCKET || player.getInventory().getItemInOffHand().getType() == Material.MILK_BUCKET) { // If the player tries to use milk to clear the effects, cancel the event to keep that from happening - event.setCancelled(true); - return; + return true; } if (player.getInventory().getItemInMainHand().getType() != Material.STONE_BUTTON && player.getInventory().getItemInOffHand().getType() != Material.STONE_BUTTON) - return; + return false; if (TurretsMain.getInstance().getTurretManager().isReloading(player)) - return; + return false; // Fires the turret and keeps them from interacting with something else and placing the button accidentally TurretsMain.getInstance().getTurretManager().fire(player); - event.setCancelled(true); + return true; } }