Skip to content

Commit

Permalink
1.20.6 (#16)
Browse files Browse the repository at this point in the history
* Update build.gradle.kts

* Update TurretManager.java

* Update PlayerInteractListener.java

* Update TurretManager.java

* Update build.gradle.kts
  • Loading branch information
TylerS1066 authored Sep 10, 2024
1 parent a7ba5d5 commit 847730e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 66 deletions.
8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
33 changes: 10 additions & 23 deletions src/main/java/com/snowleopard1863/APTurrets/TurretManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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();
Expand All @@ -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;
}

Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,87 +18,77 @@

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"
+ ChatColor.GOLD + "Velocity: " + ChatColor.GRAY + Config.ArrowVelocity + "\n"
+ 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;
}
}

0 comments on commit 847730e

Please sign in to comment.