diff --git a/src/main/java/rip/tilly/bedwars/BedWars.java b/src/main/java/rip/tilly/bedwars/BedWars.java index cbe979b..71b3e7f 100644 --- a/src/main/java/rip/tilly/bedwars/BedWars.java +++ b/src/main/java/rip/tilly/bedwars/BedWars.java @@ -8,6 +8,7 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; +import rip.tilly.bedwars.customitems.bridgeegg.BridgeEggListener; import rip.tilly.bedwars.game.Game; import rip.tilly.bedwars.listeners.*; import rip.tilly.bedwars.listeners.game.*; @@ -136,7 +137,8 @@ public final class BedWars extends JavaPlugin { Arrays.asList( new PlayerDataListener(), new RandomListeners(), new InteractListener(), new ButtonListener(), new MenuListener(), new GameStartListener(), new GameEndListener(), new WorldListener(), - new MovementListener(), new PlayerKillListener(), new DamageListener(), new PartyChatListener() + new MovementListener(), new PlayerKillListener(), new DamageListener(), new PartyChatListener(), + new BridgeEggListener() ).forEach(listener -> this.getServer().getPluginManager().registerEvents(listener, this)); } diff --git a/src/main/java/rip/tilly/bedwars/customitems/bridgeegg/BridgeEggListener.java b/src/main/java/rip/tilly/bedwars/customitems/bridgeegg/BridgeEggListener.java new file mode 100644 index 0000000..493de50 --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/customitems/bridgeegg/BridgeEggListener.java @@ -0,0 +1,57 @@ +package rip.tilly.bedwars.customitems.bridgeegg; + +import org.bukkit.entity.Egg; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.ProjectileHitEvent; +import org.bukkit.event.entity.ProjectileLaunchEvent; +import rip.tilly.bedwars.BedWars; +import rip.tilly.bedwars.game.Game; +import rip.tilly.bedwars.playerdata.PlayerTeam; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +@SuppressWarnings("WeakerAccess") +public class BridgeEggListener implements Listener { + + private final BedWars plugin = BedWars.getInstance(); + private static final HashMap currentTasks = new HashMap<>(); + + @EventHandler + public void onProjectileLaunch(ProjectileLaunchEvent event) { + if (event.getEntity() instanceof Egg) { + Egg egg = (Egg) event.getEntity(); + if (egg.getShooter() instanceof Player) { + Player player = (Player) egg.getShooter(); + Game game = this.plugin.getGameManager().getGame(player.getUniqueId()); + if (game != null) { + PlayerTeam playerTeam = this.plugin.getPlayerDataManager().getPlayerData(player.getUniqueId()).getPlayerTeam(); + currentTasks.put(egg, new BridgeEggRunnable(this.plugin, egg, playerTeam, player, game)); + } + } + } + } + + @EventHandler + public void onProjectileHit(ProjectileHitEvent event) { + if (event.getEntity() instanceof Egg) { + removeEgg((Egg) event.getEntity()); + } + } + + public static void removeEgg(Egg egg) { + if (currentTasks.containsKey(egg)) { + if (currentTasks.get(egg) != null) { + currentTasks.get(egg).cancel(); + } + currentTasks.remove(egg); + } + } + + public static Map getEggTasks() { + return Collections.unmodifiableMap(currentTasks); + } +} diff --git a/src/main/java/rip/tilly/bedwars/customitems/bridgeegg/BridgeEggRunnable.java b/src/main/java/rip/tilly/bedwars/customitems/bridgeegg/BridgeEggRunnable.java new file mode 100644 index 0000000..7be0e33 --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/customitems/bridgeegg/BridgeEggRunnable.java @@ -0,0 +1,83 @@ +package rip.tilly.bedwars.customitems.bridgeegg; + +import lombok.Getter; +import org.bukkit.Effect; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.block.Block; +import org.bukkit.entity.Egg; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitTask; +import rip.tilly.bedwars.BedWars; +import rip.tilly.bedwars.game.Game; +import rip.tilly.bedwars.playerdata.PlayerTeam; + +@Getter +@SuppressWarnings("WeakerAccess") +public class BridgeEggRunnable implements Runnable { + + private final BedWars plugin; + private final Egg egg; + private final PlayerTeam playerTeam; + private final Player player; + private final Game game; + private final BukkitTask bukkitTask; + + public BridgeEggRunnable(BedWars plugin, Egg egg, PlayerTeam playerTeam, Player player, Game game) { + this.plugin = plugin; + this.egg = egg; + this.playerTeam = playerTeam; + this.player = player; + this.game = game; + this.bukkitTask = this.plugin.getServer().getScheduler().runTaskTimer(this.plugin, this, 0, 1); + } + + public void run() { + Location location = this.egg.getLocation(); + if (this.egg.isDead() || this.player.getLocation().distance(location) > 27 || this.player.getLocation().getY() - location.getY() > 9) { + BridgeEggListener.removeEgg(this.egg); + return; + } + + if (this.player.getLocation().distance(location) > 4) { + + Block block1 = location.clone().subtract(0, 2, 0).getBlock(); + if (!this.game.isInside(block1.getLocation(), this.game)) { + if (block1.getType() == Material.AIR) { + block1.setType(Material.WOOL); + block1.setData((byte) this.playerTeam.getColorData()); + this.game.addPlacedBlock(block1); + location.getWorld().playEffect(block1.getLocation(), Effect.MOBSPAWNER_FLAMES, 3); + this.player.playSound(location, Sound.CHICKEN_EGG_POP, 1, 1); + } + } + + Block block2 = location.clone().subtract(1, 2, 0).getBlock(); + if (!this.game.isInside(block2.getLocation(), this.game)) { + if (block2.getType() == Material.AIR) { + block2.setType(Material.WOOL); + block2.setData((byte) this.playerTeam.getColorData()); + this.game.addPlacedBlock(block2); + location.getWorld().playEffect(block2.getLocation(), Effect.MOBSPAWNER_FLAMES, 3); + this.player.playSound(location, Sound.CHICKEN_EGG_POP, 1, 1); + } + } + + Block block3 = location.clone().subtract(0, 2, 1).getBlock(); + if (!this.game.isInside(block3.getLocation(), this.game)) { + if (block3.getType() == Material.AIR) { + block3.setType(Material.WOOL); + block3.setData((byte) this.playerTeam.getColorData()); + this.game.addPlacedBlock(block3); + location.getWorld().playEffect(block3.getLocation(), Effect.MOBSPAWNER_FLAMES, 3); + this.player.playSound(location, Sound.CHICKEN_EGG_POP, 1, 1); + } + } + } + } + + public void cancel() { + this.bukkitTask.cancel(); + } +} diff --git a/src/main/java/rip/tilly/bedwars/customitems/e.java b/src/main/java/rip/tilly/bedwars/customitems/e.java deleted file mode 100644 index d6fb9b4..0000000 --- a/src/main/java/rip/tilly/bedwars/customitems/e.java +++ /dev/null @@ -1,4 +0,0 @@ -package rip.tilly.bedwars.customitems; - -public class e { -} diff --git a/src/main/java/rip/tilly/bedwars/customitems/popuptower/CheckRotation.java b/src/main/java/rip/tilly/bedwars/customitems/popuptower/CheckRotation.java deleted file mode 100644 index e6b5ce3..0000000 --- a/src/main/java/rip/tilly/bedwars/customitems/popuptower/CheckRotation.java +++ /dev/null @@ -1,8 +0,0 @@ -package rip.tilly.bedwars.customitems.popuptower; - -public class CheckRotation { - - public CheckRotation(Double d) { - - } -} diff --git a/src/main/java/rip/tilly/bedwars/customitems/popuptower/PlaceTower.java b/src/main/java/rip/tilly/bedwars/customitems/popuptower/PlaceTower.java index 351a8b1..2d320e1 100644 --- a/src/main/java/rip/tilly/bedwars/customitems/popuptower/PlaceTower.java +++ b/src/main/java/rip/tilly/bedwars/customitems/popuptower/PlaceTower.java @@ -4,24 +4,30 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; import rip.tilly.bedwars.BedWars; +import rip.tilly.bedwars.game.Game; import rip.tilly.bedwars.playerdata.PlayerTeam; public class PlaceTower { + private final BedWars plugin = BedWars.getInstance(); + public PlaceTower(Block block, String xyz, PlayerTeam playerTeam, Player player, boolean ladder, int ladderData) { int x = Integer.parseInt(xyz.split(", ")[0]); int y = Integer.parseInt(xyz.split(", ")[1]); int z = Integer.parseInt(xyz.split(", ")[2]); Block relative = block.getRelative(x, y, z); - if (relative.getType() == Material.AIR) { - if (!ladder) { - relative.setType(Material.WOOL); - relative.setData((byte) playerTeam.getColorData()); - } else { - relative.setType(Material.LADDER); - relative.setData((byte) ladderData); + Game game = this.plugin.getGameManager().getGame(player.getUniqueId()); + if (!game.isInside(relative.getLocation(), game)) { + if (relative.getType() == Material.AIR) { + if (!ladder) { + relative.setType(Material.WOOL); + relative.setData((byte) playerTeam.getColorData()); + } else { + relative.setType(Material.LADDER); + relative.setData((byte) ladderData); + } + this.plugin.getGameManager().getGame(player.getUniqueId()).addPlacedBlock(relative); } - BedWars.getInstance().getGameManager().getGame(player.getUniqueId()).addPlacedBlock(relative); } } } diff --git a/src/main/java/rip/tilly/bedwars/customitems/popuptower/types/TowerEast.java b/src/main/java/rip/tilly/bedwars/customitems/popuptower/types/TowerEast.java index fa8d656..366e791 100644 --- a/src/main/java/rip/tilly/bedwars/customitems/popuptower/types/TowerEast.java +++ b/src/main/java/rip/tilly/bedwars/customitems/popuptower/types/TowerEast.java @@ -1,4 +1,170 @@ package rip.tilly.bedwars.customitems.popuptower.types; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.scheduler.BukkitTask; +import rip.tilly.bedwars.BedWars; +import rip.tilly.bedwars.customitems.popuptower.PlaceTower; +import rip.tilly.bedwars.playerdata.PlayerTeam; + +import java.util.ArrayList; +import java.util.List; + public class TowerEast { + + private BukkitTask bukkitTask; + + public TowerEast(Location location, Block block, PlayerTeam playerTeam, Player player) { + ItemStack hand = player.getItemInHand(); + if (hand.getAmount() == 1) { + hand.setType(Material.AIR); + player.setItemInHand(hand); + } else { + hand.setAmount(hand.getAmount() - 1); + } + List locList = new ArrayList<>(); + locList.add("2, 0, -1"); + locList.add("1, 0, -2"); + locList.add("0, 0, -2"); + locList.add("-1, 0, -1"); + locList.add("-1, 0, 0"); + locList.add("-1, 0, 1"); + locList.add("0, 0, 2"); + locList.add("1, 0, 2"); + locList.add("2, 0, 1"); + locList.add("0, 0, 0, ladder5"); + locList.add("2, 1, -1"); + locList.add("1, 1, -2"); + locList.add("0, 1, -2"); + locList.add("-1, 1, -1"); + locList.add("-1, 1, 0"); + locList.add("-1, 1, 1"); + locList.add("0, 1, 2"); + locList.add("1, 1, 2"); + locList.add("2, 1, 1"); + locList.add("0, 1, 0, ladder5"); + locList.add("2, 2, -1"); + locList.add("1, 2, -2"); + locList.add("0, 2, -2"); + locList.add("-1, 2, -1"); + locList.add("-1, 2, 0"); + locList.add("-1, 2, 1"); + locList.add("0, 2, 2"); + locList.add("1, 2, 2"); + locList.add("2, 2, 1"); + locList.add("0, 2, 0, ladder5"); + locList.add("2, 3, 0"); + locList.add("2, 3, -1"); + locList.add("1, 3, -2"); + locList.add("0, 3, -2"); + locList.add("-1, 3, -1"); + locList.add("-1, 3, 0"); + locList.add("-1, 3, 1"); + locList.add("0, 3, 2"); + locList.add("1, 3, 2"); + locList.add("2, 3, 1"); + locList.add("0, 3, 0, ladder5"); + locList.add("2, 4, 0"); + locList.add("2, 4, -1"); + locList.add("1, 4, -2"); + locList.add("0, 4, -2"); + locList.add("-1, 4, -1"); + locList.add("-1, 4, 0"); + locList.add("-1, 4, 1"); + locList.add("0, 4, 2"); + locList.add("1, 4, 2"); + locList.add("2, 4, 1"); + locList.add("0, 4, 0, ladder5"); + locList.add("-1, 5, -2"); + locList.add("0, 5, -2"); + locList.add("1, 5, -2"); + locList.add("2, 5, -2"); + locList.add("-1, 5, -1"); + locList.add("0, 5, -1"); + locList.add("1, 5, -1"); + locList.add("2, 5, -1"); + locList.add("-1, 5, 0"); + locList.add("1, 5, 0"); + locList.add("2, 5, 0"); + locList.add("-1, 5, 1"); + locList.add("0, 5, 0, ladder5"); + locList.add("0, 5, 1"); + locList.add("1, 5, 1"); + locList.add("2, 5, 1"); + locList.add("-1, 5, 2"); + locList.add("0, 5, 2"); + locList.add("1, 5, 2"); + locList.add("2, 5, 2"); + locList.add("2, 5, -3"); + locList.add("2, 6, -3"); + locList.add("2, 7, -3"); + locList.add("1, 6, -3"); + locList.add("0, 6, -3"); + locList.add("-1, 5, -3"); + locList.add("-1, 6, -3"); + locList.add("-1, 7, -3"); + locList.add("-2, 5, -2"); + locList.add("-2, 6, -2"); + locList.add("-2, 7, -2"); + locList.add("-2, 6, -1"); + locList.add("-2, 5, 0"); + locList.add("-2, 6, 0"); + locList.add("-2, 7, 0"); + locList.add("-2, 6, 1"); + locList.add("-2, 5, 2"); + locList.add("-2, 6, 2"); + locList.add("-2, 7, 2"); + locList.add("2, 5, 3"); + locList.add("2, 6, 3"); + locList.add("2, 7, 3"); + locList.add("1, 6, 3"); + locList.add("0, 6, 3"); + locList.add("-1, 5, 3"); + locList.add("-1, 6, 3"); + locList.add("-1, 7, 3"); + locList.add("3, 5, -2"); + locList.add("3, 6, -2"); + locList.add("3, 7, -2"); + locList.add("3, 6, -1"); + locList.add("3, 5, 0"); + locList.add("3, 6, 0"); + locList.add("3, 7, 0"); + locList.add("3, 6, 1"); + locList.add("3, 5, 2"); + locList.add("3, 6, 2"); + locList.add("3, 7, 2"); + + int[] i = { 0 }; + this.bukkitTask = Bukkit.getScheduler().runTaskTimer(BedWars.getInstance(), () -> { + location.getWorld().playSound(location, Sound.CHICKEN_EGG_POP, 1f, 0.5f); + if (locList.size() + 1 == i[0] + 1) { + this.bukkitTask.cancel(); + return; + } + String string = locList.get(i[0]); + if (string.contains("ladder")) { + int ladderData = Integer.parseInt(string.split("ladder")[1]); + new PlaceTower(block, string, playerTeam, player, true, ladderData); + } else { + new PlaceTower(block, string, playerTeam, player, false, 0); + } + if (locList.size() + 1 == i[0] + 2) { + this.bukkitTask.cancel(); + return; + } + String string2 = locList.get(i[0] + 1); + if (string2.contains("ladder")) { + int ladderData = Integer.parseInt(string2.split("ladder")[1]); + new PlaceTower(block, string2, playerTeam, player, true, ladderData); + } else { + new PlaceTower(block, string2, playerTeam, player, false, 0); + } + i[0] = i[0] + 2; + }, 0, 1); + } } diff --git a/src/main/java/rip/tilly/bedwars/customitems/popuptower/types/TowerNorth.java b/src/main/java/rip/tilly/bedwars/customitems/popuptower/types/TowerNorth.java index b8a7838..f168a68 100644 --- a/src/main/java/rip/tilly/bedwars/customitems/popuptower/types/TowerNorth.java +++ b/src/main/java/rip/tilly/bedwars/customitems/popuptower/types/TowerNorth.java @@ -1,4 +1,171 @@ package rip.tilly.bedwars.customitems.popuptower.types; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.scheduler.BukkitTask; +import rip.tilly.bedwars.BedWars; +import rip.tilly.bedwars.customitems.popuptower.PlaceTower; +import rip.tilly.bedwars.playerdata.PlayerTeam; + +import java.util.ArrayList; +import java.util.List; + public class TowerNorth { + + private BukkitTask bukkitTask; + + public TowerNorth(Location location, Block block, PlayerTeam playerTeam, Player player) { + ItemStack hand = player.getItemInHand(); + if (hand.getAmount() == 1) { + hand.setType(Material.AIR); + player.setItemInHand(hand); + } else { + hand.setAmount(hand.getAmount() - 1); + } + + List locList = new ArrayList<>(); + locList.add("-1, 0, -2"); + locList.add("-2, 0, -1"); + locList.add("-2, 0, 0"); + locList.add("-1, 0, 1"); + locList.add("0, 0, 1"); + locList.add("1, 0, 1"); + locList.add("2, 0, 0"); + locList.add("2, 0, -1"); + locList.add("1, 0, -2"); + locList.add("0, 0, 0, ladder2"); + locList.add("-1, 1, -2"); + locList.add("-2, 1, -1"); + locList.add("-2, 1, 0"); + locList.add("-1, 1, 1"); + locList.add("0, 1, 1"); + locList.add("1, 1, 1"); + locList.add("2, 1, 0"); + locList.add("2, 1, -1"); + locList.add("1, 1, -2"); + locList.add("0, 1, 0, ladder2"); + locList.add("-1, 2, -2"); + locList.add("-2, 2, -1"); + locList.add("-2, 2, 0"); + locList.add("-1, 2, 1"); + locList.add("0, 2, 1"); + locList.add("1, 2, 1"); + locList.add("2, 2, 0"); + locList.add("2, 2, -1"); + locList.add("1, 2, -2"); + locList.add("0, 2, 0, ladder2"); + locList.add("0, 3, -2"); + locList.add("-1, 3, -2"); + locList.add("-2, 3, -1"); + locList.add("-2, 3, 0"); + locList.add("-1, 3, 1"); + locList.add("0, 3, 1"); + locList.add("1, 3, 1"); + locList.add("2, 3, 0"); + locList.add("2, 3, -1"); + locList.add("1, 3, -2"); + locList.add("0, 3, 0, ladder2"); + locList.add("0, 4, -2"); + locList.add("-1, 4, -2"); + locList.add("-2, 4, -1"); + locList.add("-2, 4, 0"); + locList.add("-1, 4, 1"); + locList.add("0, 4, 1"); + locList.add("1, 4, 1"); + locList.add("2, 4, 0"); + locList.add("2, 4, -1"); + locList.add("1, 4, -2"); + locList.add("0, 4, 0, ladder2"); + locList.add("-2, 5, 1"); + locList.add("-2, 5, 0"); + locList.add("-2, 5, -1"); + locList.add("-2, 5, -2"); + locList.add("-1, 5, 1"); + locList.add("-1, 5, 0"); + locList.add("-1, 5, -1"); + locList.add("-1, 5, -2"); + locList.add("0, 5, 1"); + locList.add("0, 5, -1"); + locList.add("0, 5, -2"); + locList.add("1, 5, 1"); + locList.add("0, 5, 0, ladder2"); + locList.add("1, 5, 0"); + locList.add("1, 5, -1"); + locList.add("1, 5, -2"); + locList.add("2, 5, 1"); + locList.add("2, 5, 0"); + locList.add("2, 5, -1"); + locList.add("2, 5, -2"); + locList.add("-3, 5, -2"); + locList.add("-3, 6, -2"); + locList.add("-3, 7, -2"); + locList.add("-3, 6, -1"); + locList.add("-3, 6, 0"); + locList.add("-3, 5, 1"); + locList.add("-3, 6, 1"); + locList.add("-3, 7, 1"); + locList.add("-2, 5, 2"); + locList.add("-2, 6, 2"); + locList.add("-2, 7, 2"); + locList.add("-1, 6, 2"); + locList.add("0, 5, 2"); + locList.add("0, 6, 2"); + locList.add("0, 7, 2"); + locList.add("1, 6, 2"); + locList.add("2, 5, 2"); + locList.add("2, 6, 2"); + locList.add("2, 7, 2"); + locList.add("3, 5, -2"); + locList.add("3, 6, -2"); + locList.add("3, 7, -2"); + locList.add("3, 6, -1"); + locList.add("3, 6, 0"); + locList.add("3, 5, 1"); + locList.add("3, 6, 1"); + locList.add("3, 7, 1"); + locList.add("-2, 5, -3"); + locList.add("-2, 6, -3"); + locList.add("-2, 7, -3"); + locList.add("-1, 6, -3"); + locList.add("0, 5, -3"); + locList.add("0, 6, -3"); + locList.add("0, 7, -3"); + locList.add("1, 6, -3"); + locList.add("2, 5, -3"); + locList.add("2, 6, -3"); + locList.add("2, 7, -3"); + + int[] i = { 0 }; + this.bukkitTask = Bukkit.getScheduler().runTaskTimer(BedWars.getInstance(), () -> { + location.getWorld().playSound(location, Sound.CHICKEN_EGG_POP, 1f, 0.5f); + if (locList.size() + 1 == i[0] + 1) { + this.bukkitTask.cancel(); + return; + } + String string = locList.get(i[0]); + if (string.contains("ladder")) { + int ladderData = Integer.parseInt(string.split("ladder")[1]); + new PlaceTower(block, string, playerTeam, player, true, ladderData); + } else { + new PlaceTower(block, string, playerTeam, player, false, 0); + } + if (locList.size() + 1 == i[0] + 2) { + this.bukkitTask.cancel(); + return; + } + String string2 = locList.get(i[0] + 1); + if (string2.contains("ladder")) { + int ladderData = Integer.parseInt(string2.split("ladder")[1]); + new PlaceTower(block, string2, playerTeam, player, true, ladderData); + } else { + new PlaceTower(block, string2, playerTeam, player, false, 0); + } + i[0] = i[0] + 2; + }, 0, 1); + } } diff --git a/src/main/java/rip/tilly/bedwars/customitems/popuptower/types/TowerSouth.java b/src/main/java/rip/tilly/bedwars/customitems/popuptower/types/TowerSouth.java index 4e83e0d..34f35b8 100644 --- a/src/main/java/rip/tilly/bedwars/customitems/popuptower/types/TowerSouth.java +++ b/src/main/java/rip/tilly/bedwars/customitems/popuptower/types/TowerSouth.java @@ -1,4 +1,171 @@ package rip.tilly.bedwars.customitems.popuptower.types; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.scheduler.BukkitTask; +import rip.tilly.bedwars.BedWars; +import rip.tilly.bedwars.customitems.popuptower.PlaceTower; +import rip.tilly.bedwars.playerdata.PlayerTeam; + +import java.util.ArrayList; +import java.util.List; + public class TowerSouth { + + private BukkitTask bukkitTask; + + public TowerSouth(Location location, Block block, PlayerTeam playerTeam, Player player) { + ItemStack hand = player.getItemInHand(); + if (hand.getAmount() == 1) { + hand.setType(Material.AIR); + player.setItemInHand(hand); + } else { + hand.setAmount(hand.getAmount() - 1); + } + + List locList = new ArrayList<>(); + locList.add("1, 0, 2"); + locList.add("2, 0, 1"); + locList.add("2, 0, 0"); + locList.add("1, 0, -1"); + locList.add("0, 0, -1"); + locList.add("-1, 0, -1"); + locList.add("-2, 0, 0"); + locList.add("-2, 0, 1"); + locList.add("-1, 0, 2"); + locList.add("0, 0, 0, ladder3"); + locList.add("1, 1, 2"); + locList.add("2, 1, 1"); + locList.add("2, 1, 0"); + locList.add("1, 1, -1"); + locList.add("0, 1, -1"); + locList.add("-1, 1, -1"); + locList.add("-2, 1, 0"); + locList.add("-2, 1, 1"); + locList.add("-1, 1, 2"); + locList.add("0, 1, 0, ladder3"); + locList.add("1, 2, 2"); + locList.add("2, 2, 1"); + locList.add("2, 2, 0"); + locList.add("1, 2, -1"); + locList.add("0, 2, -1"); + locList.add("-1, 2, -1"); + locList.add("-2, 2, 0"); + locList.add("-2, 2, 1"); + locList.add("-1, 2, 2"); + locList.add("0, 2, 0, ladder3"); + locList.add("0, 3, 2"); + locList.add("1, 3, 2"); + locList.add("2, 3, 1"); + locList.add("2, 3, 0"); + locList.add("1, 3, -1"); + locList.add("0, 3, -1"); + locList.add("-1, 3, -1"); + locList.add("-2, 3, 0"); + locList.add("-2, 3, 1"); + locList.add("-1, 3, 2"); + locList.add("0, 3, 0, ladder3"); + locList.add("0, 4, 2"); + locList.add("1, 4, 2"); + locList.add("2, 4, 1"); + locList.add("2, 4, 0"); + locList.add("1, 4, -1"); + locList.add("0, 4, -1"); + locList.add("-1, 4, -1"); + locList.add("-2, 4, 0"); + locList.add("-2, 4, 1"); + locList.add("-1, 4, 2"); + locList.add("0, 4, 0, ladder3"); + locList.add("2, 5, -1"); + locList.add("2, 5, 0"); + locList.add("2, 5, 1"); + locList.add("2, 5, 2"); + locList.add("1, 5, -1"); + locList.add("1, 5, 0"); + locList.add("1, 5, 1"); + locList.add("1, 5, 2"); + locList.add("0, 5, -1"); + locList.add("0, 5, 1"); + locList.add("0, 5, 2"); + locList.add("-1, 5, -1"); + locList.add("0, 5, 0, ladder3"); + locList.add("-1, 5, 0"); + locList.add("-1, 5, 1"); + locList.add("-1, 5, 2"); + locList.add("-2, 5, -1"); + locList.add("-2, 5, 0"); + locList.add("-2, 5, 1"); + locList.add("-2, 5, 2"); + locList.add("3, 5, 2"); + locList.add("3, 6, 2"); + locList.add("3, 7, 2"); + locList.add("3, 6, 1"); + locList.add("3, 6, 0"); + locList.add("3, 5, -1"); + locList.add("3, 6, -1"); + locList.add("3, 7, -1"); + locList.add("2, 5, -2"); + locList.add("2, 6, -2"); + locList.add("2, 7, -2"); + locList.add("1, 6, -2"); + locList.add("0, 5, -2"); + locList.add("0, 6, -2"); + locList.add("0, 7, -2"); + locList.add("-1, 6, -2"); + locList.add("-2, 5, -2"); + locList.add("-2, 6, -2"); + locList.add("-2, 7, -2"); + locList.add("-3, 5, 2"); + locList.add("-3, 6, 2"); + locList.add("-3, 7, 2"); + locList.add("-3, 6, 1"); + locList.add("-3, 6, 0"); + locList.add("-3, 5, -1"); + locList.add("-3, 6, -1"); + locList.add("-3, 7, -1"); + locList.add("2, 5, 3"); + locList.add("2, 6, 3"); + locList.add("2, 7, 3"); + locList.add("1, 6, 3"); + locList.add("0, 5, 3"); + locList.add("0, 6, 3"); + locList.add("0, 7, 3"); + locList.add("-1, 6, 3"); + locList.add("-2, 5, 3"); + locList.add("-2, 6, 3"); + locList.add("-2, 7, 3"); + + int[] i = { 0 }; + this.bukkitTask = Bukkit.getScheduler().runTaskTimer(BedWars.getInstance(), () -> { + location.getWorld().playSound(location, Sound.CHICKEN_EGG_POP, 1f, 0.5f); + if (locList.size() + 1 == i[0] + 1) { + this.bukkitTask.cancel(); + return; + } + String string = locList.get(i[0]); + if (string.contains("ladder")) { + int ladderData = Integer.parseInt(string.split("ladder")[1]); + new PlaceTower(block, string, playerTeam, player, true, ladderData); + } else { + new PlaceTower(block, string, playerTeam, player, false, 0); + } + if (locList.size() + 1 == i[0] + 2) { + this.bukkitTask.cancel(); + return; + } + String string2 = locList.get(i[0] + 1); + if (string2.contains("ladder")) { + int ladderData = Integer.parseInt(string2.split("ladder")[1]); + new PlaceTower(block, string2, playerTeam, player, true, ladderData); + } else { + new PlaceTower(block, string2, playerTeam, player, false, 0); + } + i[0] = i[0] + 2; + }, 0, 1); + } } diff --git a/src/main/java/rip/tilly/bedwars/customitems/popuptower/types/TowerWest.java b/src/main/java/rip/tilly/bedwars/customitems/popuptower/types/TowerWest.java index 174305c..073385c 100644 --- a/src/main/java/rip/tilly/bedwars/customitems/popuptower/types/TowerWest.java +++ b/src/main/java/rip/tilly/bedwars/customitems/popuptower/types/TowerWest.java @@ -139,6 +139,7 @@ public class TowerWest { locList.add("-3, 5, -2"); locList.add("-3, 6, -2"); locList.add("-3, 7, -2"); + int[] i = { 0 }; this.bukkitTask = Bukkit.getScheduler().runTaskTimer(BedWars.getInstance(), () -> { location.getWorld().playSound(location, Sound.CHICKEN_EGG_POP, 1f, 0.5f); diff --git a/src/main/java/rip/tilly/bedwars/listeners/game/WorldListener.java b/src/main/java/rip/tilly/bedwars/listeners/game/WorldListener.java index 33c7039..13be7cf 100644 --- a/src/main/java/rip/tilly/bedwars/listeners/game/WorldListener.java +++ b/src/main/java/rip/tilly/bedwars/listeners/game/WorldListener.java @@ -14,6 +14,10 @@ import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.inventory.ItemStack; import rip.tilly.bedwars.BedWars; +import rip.tilly.bedwars.customitems.popuptower.types.TowerEast; +import rip.tilly.bedwars.customitems.popuptower.types.TowerNorth; +import rip.tilly.bedwars.customitems.popuptower.types.TowerSouth; +import rip.tilly.bedwars.customitems.popuptower.types.TowerWest; import rip.tilly.bedwars.game.Game; import rip.tilly.bedwars.game.GameState; import rip.tilly.bedwars.game.GameTeam; @@ -160,8 +164,27 @@ public class WorldListener implements Listener { Block chest = event.getBlockPlaced(); if (chest.getType() == Material.CHEST) { - Location location = event.getBlockPlaced().getLocation(); event.setCancelled(true); + + Location location = event.getBlockPlaced().getLocation(); + + double rotation = ((player.getLocation().getYaw() - 90) % 360); + if (rotation < 0) { + rotation += 360; + } + + if (45 <= rotation && rotation < 135) { + new TowerSouth(location, block, playerData.getPlayerTeam(), player); + } else if (225 <= rotation && rotation < 315) { + new TowerNorth(location, block, playerData.getPlayerTeam(), player); + } else if (135 <= rotation && rotation < 225) { + new TowerWest(location, block, playerData.getPlayerTeam(), player); + } else if (0 <= rotation && rotation < 45) { + new TowerEast(location, block, playerData.getPlayerTeam(), player); + } else if (315 <= rotation && rotation < 360) { + new TowerEast(location, block, playerData.getPlayerTeam(), player); + } + return; }