From c1092197593a52b3f983a622b1e708922c8cca19 Mon Sep 17 00:00:00 2001 From: Trixkz Date: Tue, 23 Nov 2021 10:14:40 -0500 Subject: [PATCH] t --- .../bedwars/commands/arena/ArenaCommand.java | 20 ++++++++ .../commands/arena/SetTeamAShopCommand.java | 48 +++++++++++++++++++ .../arena/SetTeamAUpgradesCommand.java | 48 +++++++++++++++++++ .../commands/arena/SetTeamBShopCommand.java | 48 +++++++++++++++++++ .../arena/SetTeamBUpgradesCommand.java | 48 +++++++++++++++++++ .../java/rip/tilly/bedwars/game/Game.java | 19 ++++++++ .../bedwars/listeners/InteractListener.java | 37 ++++++++++++++ .../listeners/game/GameStartListener.java | 3 +- 8 files changed, 270 insertions(+), 1 deletion(-) create mode 100644 src/main/java/rip/tilly/bedwars/commands/arena/SetTeamAShopCommand.java create mode 100644 src/main/java/rip/tilly/bedwars/commands/arena/SetTeamAUpgradesCommand.java create mode 100644 src/main/java/rip/tilly/bedwars/commands/arena/SetTeamBShopCommand.java create mode 100644 src/main/java/rip/tilly/bedwars/commands/arena/SetTeamBUpgradesCommand.java diff --git a/src/main/java/rip/tilly/bedwars/commands/arena/ArenaCommand.java b/src/main/java/rip/tilly/bedwars/commands/arena/ArenaCommand.java index 211c45e..300a051 100644 --- a/src/main/java/rip/tilly/bedwars/commands/arena/ArenaCommand.java +++ b/src/main/java/rip/tilly/bedwars/commands/arena/ArenaCommand.java @@ -46,6 +46,10 @@ public class ArenaCommand implements CommandExecutor { player.sendMessage(CC.translate("&7⚫ &9/arena setTeamGenerator &7- &eSet the team's generator")); player.sendMessage(CC.translate("&7⚫ &9/arena setDiamondGenerator &7- &eSet the diamond generator")); player.sendMessage(CC.translate("&7⚫ &9/arena setEmeraldGenerator &7- &eSet the emerald generator")); + player.sendMessage(CC.translate("&7⚫ &9/arena setTeamAShop &7- &eSet team A shop")); + player.sendMessage(CC.translate("&7⚫ &9/arena setTeamBShop &7- &eSet team B shop")); + player.sendMessage(CC.translate("&7⚫ &9/arena setTeamAUpgrades &7- &eSet team A upgrades")); + player.sendMessage(CC.translate("&7⚫ &9/arena setTeamBUpgrades &7- &eSet team B upgrades")); player.sendMessage(CC.translate("&7⚫ &9/arena list &7- &eLook at all of the arenas")); player.sendMessage(CC.translate("&7⚫ &9/arena save &7- &eSave all of the arenas")); player.sendMessage(CC.translate("&7⚫ &9/arena manage &7- &eOpen the arena manage menu")); @@ -125,6 +129,22 @@ public class ArenaCommand implements CommandExecutor { case "setemeraldgenerator": new SetEmeraldGeneratorCommand().executeAs(sender, cmd, label, args); + break; + case "setteamashop": + new SetTeamAShopCommand().executeAs(sender, cmd, label, args); + + break; + case "setteambshop": + new SetTeamBShopCommand().executeAs(sender, cmd, label, args); + + break; + case "setteamaupgrades": + new SetTeamAUpgradesCommand().executeAs(sender, cmd, label, args); + + break; + case "setteambupgrades": + new SetTeamBUpgradesCommand().executeAs(sender, cmd, label, args); + break; case "list": player.sendMessage(CC.translate("&9&lArenas List &7(&eTotal: " + this.main.getArenaManager().getArenas().size() + "&7)")); diff --git a/src/main/java/rip/tilly/bedwars/commands/arena/SetTeamAShopCommand.java b/src/main/java/rip/tilly/bedwars/commands/arena/SetTeamAShopCommand.java new file mode 100644 index 0000000..97355b5 --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/commands/arena/SetTeamAShopCommand.java @@ -0,0 +1,48 @@ +package rip.tilly.bedwars.commands.arena; + +import org.bukkit.Location; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import rip.tilly.bedwars.BedWars; +import rip.tilly.bedwars.commands.BaseCommand; +import rip.tilly.bedwars.game.arena.Arena; +import rip.tilly.bedwars.utils.CC; +import rip.tilly.bedwars.utils.CustomLocation; + +import java.util.ArrayList; +import java.util.List; + +public class SetTeamAShopCommand extends BaseCommand { + + private BedWars main = BedWars.getInstance(); + + @Override + public void executeAs(CommandSender sender, Command cmd, String label, String[] args) { + Player player = (Player) sender; + + if (args.length == 0) { + player.sendMessage(CC.translate("&cError: no arena found! /arena ")); + return; + } + + Arena arena = this.main.getArenaManager().getArena(args[1]); + + if (arena != null) { + Location location = player.getLocation(); + + arena.setTeamAshop(CustomLocation.fromBukkitLocation(location)); + + player.sendMessage(CC.translate("&aSuccessfully set the Team A shop position for the arena called &a&l" + args[1])); + } else { + player.sendMessage(CC.translate("&cThis arena does not exist")); + } + } + + @Override + public List getTabCompletions(CommandSender sender, Command cmd, String label, String[] args) { + List tabCompletions = new ArrayList(); + + return tabCompletions; + } +} diff --git a/src/main/java/rip/tilly/bedwars/commands/arena/SetTeamAUpgradesCommand.java b/src/main/java/rip/tilly/bedwars/commands/arena/SetTeamAUpgradesCommand.java new file mode 100644 index 0000000..8dce16c --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/commands/arena/SetTeamAUpgradesCommand.java @@ -0,0 +1,48 @@ +package rip.tilly.bedwars.commands.arena; + +import org.bukkit.Location; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import rip.tilly.bedwars.BedWars; +import rip.tilly.bedwars.commands.BaseCommand; +import rip.tilly.bedwars.game.arena.Arena; +import rip.tilly.bedwars.utils.CC; +import rip.tilly.bedwars.utils.CustomLocation; + +import java.util.ArrayList; +import java.util.List; + +public class SetTeamAUpgradesCommand extends BaseCommand { + + private BedWars main = BedWars.getInstance(); + + @Override + public void executeAs(CommandSender sender, Command cmd, String label, String[] args) { + Player player = (Player) sender; + + if (args.length == 0) { + player.sendMessage(CC.translate("&cError: no arena found! /arena ")); + return; + } + + Arena arena = this.main.getArenaManager().getArena(args[1]); + + if (arena != null) { + Location location = player.getLocation(); + + arena.setTeamAupgrades(CustomLocation.fromBukkitLocation(location)); + + player.sendMessage(CC.translate("&aSuccessfully set the Team A upgrades position for the arena called &a&l" + args[1])); + } else { + player.sendMessage(CC.translate("&cThis arena does not exist")); + } + } + + @Override + public List getTabCompletions(CommandSender sender, Command cmd, String label, String[] args) { + List tabCompletions = new ArrayList(); + + return tabCompletions; + } +} diff --git a/src/main/java/rip/tilly/bedwars/commands/arena/SetTeamBShopCommand.java b/src/main/java/rip/tilly/bedwars/commands/arena/SetTeamBShopCommand.java new file mode 100644 index 0000000..276c196 --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/commands/arena/SetTeamBShopCommand.java @@ -0,0 +1,48 @@ +package rip.tilly.bedwars.commands.arena; + +import org.bukkit.Location; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import rip.tilly.bedwars.BedWars; +import rip.tilly.bedwars.commands.BaseCommand; +import rip.tilly.bedwars.game.arena.Arena; +import rip.tilly.bedwars.utils.CC; +import rip.tilly.bedwars.utils.CustomLocation; + +import java.util.ArrayList; +import java.util.List; + +public class SetTeamBShopCommand extends BaseCommand { + + private BedWars main = BedWars.getInstance(); + + @Override + public void executeAs(CommandSender sender, Command cmd, String label, String[] args) { + Player player = (Player) sender; + + if (args.length == 0) { + player.sendMessage(CC.translate("&cError: no arena found! /arena ")); + return; + } + + Arena arena = this.main.getArenaManager().getArena(args[1]); + + if (arena != null) { + Location location = player.getLocation(); + + arena.setTeamBshop(CustomLocation.fromBukkitLocation(location)); + + player.sendMessage(CC.translate("&aSuccessfully set the Team B shop position for the arena called &a&l" + args[1])); + } else { + player.sendMessage(CC.translate("&cThis arena does not exist")); + } + } + + @Override + public List getTabCompletions(CommandSender sender, Command cmd, String label, String[] args) { + List tabCompletions = new ArrayList(); + + return tabCompletions; + } +} diff --git a/src/main/java/rip/tilly/bedwars/commands/arena/SetTeamBUpgradesCommand.java b/src/main/java/rip/tilly/bedwars/commands/arena/SetTeamBUpgradesCommand.java new file mode 100644 index 0000000..6ec64c6 --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/commands/arena/SetTeamBUpgradesCommand.java @@ -0,0 +1,48 @@ +package rip.tilly.bedwars.commands.arena; + +import org.bukkit.Location; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import rip.tilly.bedwars.BedWars; +import rip.tilly.bedwars.commands.BaseCommand; +import rip.tilly.bedwars.game.arena.Arena; +import rip.tilly.bedwars.utils.CC; +import rip.tilly.bedwars.utils.CustomLocation; + +import java.util.ArrayList; +import java.util.List; + +public class SetTeamBUpgradesCommand extends BaseCommand { + + private BedWars main = BedWars.getInstance(); + + @Override + public void executeAs(CommandSender sender, Command cmd, String label, String[] args) { + Player player = (Player) sender; + + if (args.length == 0) { + player.sendMessage(CC.translate("&cError: no arena found! /arena ")); + return; + } + + Arena arena = this.main.getArenaManager().getArena(args[1]); + + if (arena != null) { + Location location = player.getLocation(); + + arena.setTeamBupgrades(CustomLocation.fromBukkitLocation(location)); + + player.sendMessage(CC.translate("&aSuccessfully set the Team B upgrades position for the arena called &a&l" + args[1])); + } else { + player.sendMessage(CC.translate("&cThis arena does not exist")); + } + } + + @Override + public List getTabCompletions(CommandSender sender, Command cmd, String label, String[] args) { + List tabCompletions = new ArrayList(); + + return tabCompletions; + } +} diff --git a/src/main/java/rip/tilly/bedwars/game/Game.java b/src/main/java/rip/tilly/bedwars/game/Game.java index aa1dee5..48e0f43 100644 --- a/src/main/java/rip/tilly/bedwars/game/Game.java +++ b/src/main/java/rip/tilly/bedwars/game/Game.java @@ -10,6 +10,7 @@ import org.bukkit.Sound; import org.bukkit.block.Block; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; +import org.bukkit.entity.Villager; import org.bukkit.inventory.ItemStack; import org.github.paperspigot.Title; import rip.tilly.bedwars.BedWars; @@ -279,4 +280,22 @@ public class Game { public double secondsToMinutes(int seconds) { return seconds / 60D; } + + public void spawnVillagers() { + Villager teamAShopVillager = this.arena.getTeamAshop().toBukkitLocation().getWorld().spawn(this.arena.getTeamAshop().toBukkitLocation(), Villager.class); + teamAShopVillager.setCustomName(CC.translate("&aItem Shop")); + teamAShopVillager.setCustomNameVisible(true); + + Villager teamBShopVillager = this.arena.getTeamBshop().toBukkitLocation().getWorld().spawn(this.arena.getTeamBshop().toBukkitLocation(), Villager.class); + teamBShopVillager.setCustomName(CC.translate("&aItem Shop")); + teamBShopVillager.setCustomNameVisible(true); + + Villager teamAUpgradesVillager = this.arena.getTeamAupgrades().toBukkitLocation().getWorld().spawn(this.arena.getTeamAupgrades().toBukkitLocation(), Villager.class); + teamAUpgradesVillager.setCustomName(CC.translate("&aUpgrades Shop")); + teamAUpgradesVillager.setCustomNameVisible(true); + + Villager teamBUpgradesVillager = this.arena.getTeamBupgrades().toBukkitLocation().getWorld().spawn(this.arena.getTeamBupgrades().toBukkitLocation(), Villager.class); + teamBUpgradesVillager.setCustomName(CC.translate("&aUpgrades Shop")); + teamBUpgradesVillager.setCustomNameVisible(true); + } } diff --git a/src/main/java/rip/tilly/bedwars/listeners/InteractListener.java b/src/main/java/rip/tilly/bedwars/listeners/InteractListener.java index 9e5f840..2b61a4f 100644 --- a/src/main/java/rip/tilly/bedwars/listeners/InteractListener.java +++ b/src/main/java/rip/tilly/bedwars/listeners/InteractListener.java @@ -2,10 +2,12 @@ package rip.tilly.bedwars.listeners; import org.bukkit.GameMode; import org.bukkit.Material; +import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.material.TrapDoor; @@ -16,6 +18,7 @@ import rip.tilly.bedwars.menus.settings.SettingsMenu; import rip.tilly.bedwars.menus.shop.blocks.BlocksMenu; import rip.tilly.bedwars.playerdata.PlayerData; import rip.tilly.bedwars.playerdata.PlayerState; +import rip.tilly.bedwars.utils.CC; public class InteractListener implements Listener { @@ -128,4 +131,38 @@ public class InteractListener implements Listener { break; } } + + @EventHandler + public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { + Player player = event.getPlayer(); + + if (event.getRightClicked() instanceof ArmorStand) { + event.setCancelled(true); + } + + String name = event.getRightClicked().getCustomName(); + + if (name == null) { + return; + } + + switch (name) { + case "&aItem Shop": + event.setCancelled(true); + + // open item shop gui + + player.sendMessage(CC.translate("&aItem shop menu opened")); + + break; + case "&aUpgrades Shop": + event.setCancelled(true); + + // open upgrades shop gui + + player.sendMessage(CC.translate("&aUpgrades shop menu opened")); + + break; + } + } } diff --git a/src/main/java/rip/tilly/bedwars/listeners/game/GameStartListener.java b/src/main/java/rip/tilly/bedwars/listeners/game/GameStartListener.java index ec78a67..8be2c64 100644 --- a/src/main/java/rip/tilly/bedwars/listeners/game/GameStartListener.java +++ b/src/main/java/rip/tilly/bedwars/listeners/game/GameStartListener.java @@ -37,8 +37,8 @@ public class GameStartListener implements Listener { return; } - CopiedArena currentArena = game.getCopiedArena(); + for (CustomLocation location : currentArena.getTeamGenerators()) { Generator teamGen1 = new Generator(location.toBukkitLocation(), GeneratorType.IRON, true, game); teamGen1.setActivated(true); @@ -65,6 +65,7 @@ public class GameStartListener implements Listener { game.getActivatedGenerators().add(emeGen); } + game.spawnVillagers(); Set gamePlayers = new HashSet<>(); game.getTeams().forEach(team -> team.playingPlayers().forEach(player -> {