Skip to content

Commit

Permalink
Fix Ice Bridger
Browse files Browse the repository at this point in the history
  • Loading branch information
MetallicGoat committed May 16, 2024
1 parent 763556c commit 2144337
Showing 1 changed file with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
import me.metallicgoat.specialItems.ExtraSpecialItemsPlugin;
import me.metallicgoat.specialItems.config.ConfigValue;
import me.metallicgoat.specialItems.customitems.CustomSpecialItemUseSession;
import org.bukkit.*;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector;


public class IceBridgerHandler extends CustomSpecialItemUseSession {

Expand All @@ -25,28 +30,31 @@ public void run(PlayerUseSpecialItemEvent event) {
this.takeItem();

this.arena = event.getArena();
final Location playerLocation = event.getPlayer().getLocation().clone();
final Location playerLocation = event.getPlayer().getLocation().clone().add(0, -1, 0);

// The bridge should be flat
playerLocation.setPitch(0);

final Vector directionUnitVec = playerLocation.getDirection();
final int yaw = (int) playerLocation.getYaw() % 180;
final boolean xAxis = (yaw < 45 || yaw >= 135) && (yaw < -135 || yaw >= -45);

this.task = Bukkit.getScheduler().runTaskTimer(ExtraSpecialItemsPlugin.getInstance(), new Runnable() {
int i = 2;

@Override
public void run() {
if (this.i <= ConfigValue.ice_bridger_max_distance && isActive()) {
final int yaw = (int) playerLocation.getYaw() % 180;
final Location blockLoc = playerLocation.add(playerLocation.getDirection().multiply(this.i)).add(0, -1, 0);
final Location blockLoc = playerLocation.add(directionUnitVec);
final Block block = blockLoc.getBlock();
final World world = block.getWorld();
final Sound sound = Helper.get().getSoundByName("BLOCK_SNOW_BREAK"); // TODO move to config

setIce(block);

if (sound != null)
world.playSound(blockLoc, sound, 1, 1);
block.getWorld().playSound(blockLoc, sound, 1, 1);

if ((yaw < 45 || yaw >= 135) && (yaw < -135 || yaw >= -45)) {
if (xAxis) {
setIce(block.getRelative(1, 0, 0));
setIce(block.getRelative(-1, 0, 0));
setIce(block.getRelative(2, 0, 0));
Expand Down

0 comments on commit 2144337

Please sign in to comment.