diff --git a/BedWars.iml b/BedWars.iml index 8ec5bdf..f570be0 100644 --- a/BedWars.iml +++ b/BedWars.iml @@ -41,14 +41,5 @@ - - - - - - - - - \ No newline at end of file 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 f621adc..4d0b6ff 100644 --- a/src/main/java/rip/tilly/bedwars/commands/arena/ArenaCommand.java +++ b/src/main/java/rip/tilly/bedwars/commands/arena/ArenaCommand.java @@ -43,6 +43,9 @@ public class ArenaCommand implements CommandExecutor { player.sendMessage(CC.translate("&7⚫ &9/arena setTeamBMax &7- &eSet team B max")); player.sendMessage(CC.translate("&7⚫ &9/arena setDeadZone &7- &eSet the dead zone")); player.sendMessage(CC.translate("&7⚫ &9/arena setBuildMax &7- &eSet the build max")); + player.sendMessage(CC.translate("&7⚫ &9/arena setPlayerGenerator <&7- &eSet the player'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 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")); @@ -110,6 +113,18 @@ public class ArenaCommand implements CommandExecutor { case "setbuildmax": new SetBuildMaxCommand().executeAs(sender, cmd, label, args); + break; + case "setplayergenerator": + new SetPlayerGeneratorCommand().executeAs(sender, cmd, label, args); + + break; + case "setdiamondgenerator": + new SetDiamondGeneratorCommand().executeAs(sender, cmd, label, args); + + break; + case "setemeraldgenerator": + new SetEmeraldGeneratorCommand().executeAs(sender, cmd, label, args); + break; case "list": player.sendMessage(CC.translate("&b&lArenas List &7(&3Total: " + this.main.getArenaManager().getArenas().size() + "&7)")); diff --git a/src/main/java/rip/tilly/bedwars/commands/arena/SetDiamondGeneratorCommand.java b/src/main/java/rip/tilly/bedwars/commands/arena/SetDiamondGeneratorCommand.java new file mode 100644 index 0000000..1a36a0b --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/commands/arena/SetDiamondGeneratorCommand.java @@ -0,0 +1,49 @@ +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.generators.Generator; +import rip.tilly.bedwars.generators.GeneratorType; +import rip.tilly.bedwars.utils.CC; + +import java.util.ArrayList; +import java.util.List; + +public class SetDiamondGeneratorCommand extends BaseCommand { + + private BedWars main = BedWars.getInstance(); + + @Override + public void executeAs(CommandSender sender, Command cmd, String label, String[] args) { + Player player = (Player) sender; + + Arena arena = this.main.getArenaManager().getArena(args[1]); + + if (arena != null) { + Location location = player.getLocation(); + + Generator diamondGenerator; + + diamondGenerator = new Generator(location, GeneratorType.DIAMOND, false); + diamondGenerator.setActivated(true); + diamondGenerator.spawn(); +// arena.getDiamondGenerators().add(diamondGenerator); + + player.sendMessage(CC.translate("&aSuccessfully set the diamond generator for the arena called &a&l" + args[1])); + } else { + player.sendMessage(CC.translate("&cThis arena does not already 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/SetEmeraldGeneratorCommand.java b/src/main/java/rip/tilly/bedwars/commands/arena/SetEmeraldGeneratorCommand.java new file mode 100644 index 0000000..ed2ae79 --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/commands/arena/SetEmeraldGeneratorCommand.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.generators.Generator; +import rip.tilly.bedwars.generators.GeneratorType; +import rip.tilly.bedwars.utils.CC; + +import java.util.ArrayList; +import java.util.List; + +public class SetEmeraldGeneratorCommand extends BaseCommand { + + private BedWars main = BedWars.getInstance(); + + @Override + public void executeAs(CommandSender sender, Command cmd, String label, String[] args) { + Player player = (Player) sender; + + Arena arena = this.main.getArenaManager().getArena(args[1]); + + if (arena != null) { + Location location = player.getLocation(); + + Generator emeraldGenerator; + + emeraldGenerator = new Generator(location, GeneratorType.EMERALD, false); + emeraldGenerator.spawn(); +// arena.getEmeraldGenerators().add(emeraldGenerator); + + player.sendMessage(CC.translate("&aSuccessfully set the emerald generator for the arena called &a&l" + args[1])); + } else { + player.sendMessage(CC.translate("&cThis arena does not already 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/SetPlayerGeneratorCommand.java b/src/main/java/rip/tilly/bedwars/commands/arena/SetPlayerGeneratorCommand.java new file mode 100644 index 0000000..32bb98e --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/commands/arena/SetPlayerGeneratorCommand.java @@ -0,0 +1,57 @@ +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.generators.Generator; +import rip.tilly.bedwars.generators.GeneratorType; +import rip.tilly.bedwars.utils.CC; +import rip.tilly.bedwars.utils.CustomLocation; + +import java.util.ArrayList; +import java.util.List; + +public class SetPlayerGeneratorCommand extends BaseCommand { + + private BedWars main = BedWars.getInstance(); + + @Override + public void executeAs(CommandSender sender, Command cmd, String label, String[] args) { + Player player = (Player) sender; + + Arena arena = this.main.getArenaManager().getArena(args[1]); + + if (arena != null) { + Location location = player.getLocation(); + + Generator playerGenerator; + + playerGenerator = new Generator(location, GeneratorType.IRON, true); + +// arena.getPlayerGenerators().add(playerGenerator); + + playerGenerator = new Generator(location, GeneratorType.GOLD, true); + +// arena.getPlayerGenerators().add(playerGenerator); + + playerGenerator = new Generator(location, GeneratorType.EMERALD, true); + +// arena.getPlayerGenerators().add(playerGenerator); + + player.sendMessage(CC.translate("&aSuccessfully set the player's generator for the arena called &a&l" + args[1])); + } else { + player.sendMessage(CC.translate("&cThis arena does not already 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/arena/Arena.java b/src/main/java/rip/tilly/bedwars/game/arena/Arena.java index c45c390..aa0d59e 100644 --- a/src/main/java/rip/tilly/bedwars/game/arena/Arena.java +++ b/src/main/java/rip/tilly/bedwars/game/arena/Arena.java @@ -4,6 +4,7 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; +import rip.tilly.bedwars.generators.Generator; import rip.tilly.bedwars.utils.CustomLocation; import java.util.List; @@ -37,6 +38,10 @@ public class Arena { private int deadZone; private int buildMax; +// private List playerGenerators; +// private List diamondGenerators; +// private List emeraldGenerators; + private boolean enabled; public CopiedArena getAvailableArena() { diff --git a/src/main/java/rip/tilly/bedwars/generators/Generator.java b/src/main/java/rip/tilly/bedwars/generators/Generator.java new file mode 100644 index 0000000..768caf2 --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/generators/Generator.java @@ -0,0 +1,257 @@ +package rip.tilly.bedwars.generators; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.ArmorStand; +import org.bukkit.inventory.ItemStack; +import org.bukkit.scheduler.BukkitTask; +import org.bukkit.util.EulerAngle; +import rip.tilly.bedwars.BedWars; +import rip.tilly.bedwars.utils.CC; + +public class Generator { + + private BedWars main = BedWars.getInstance(); + + private Location location; + private GeneratorType generatorType; + private boolean isIslandGenerator; + private GeneratorTier generatorTier; + private ArmorStand indictatorArmorStand = null; + private ArmorStand generatorTypeArmorStand = null; + private ArmorStand generatorTierArmorStand = null; + private BukkitTask rotateIndicatorTask = null; + private int secondsSinceActivation; + private boolean activated; + + public Generator(Location location, GeneratorType generatorType, boolean isIslandGenerator) { + this.location = location; + this.generatorType = generatorType; + this.isIslandGenerator = isIslandGenerator; + this.secondsSinceActivation = this.getActivationTime(); + this.activated = false; + } + + public void spawn() { + Material material; + + if (this.generatorType == GeneratorType.DIAMOND && this.isIslandGenerator) { + return; + } + + if (!this.activated) { + if (this.generatorTypeArmorStand != null) { + this.generatorTypeArmorStand.setCustomNameVisible(false); + } + + if (this.generatorTierArmorStand != null) { + this.generatorTierArmorStand.setCustomNameVisible(false); + } + + return; + } + + this.secondsSinceActivation++; + + if (!this.isIslandGenerator) { + this.generatorTypeArmorStand.setCustomNameVisible(true); + this.generatorTypeArmorStand.setCustomName(CC.translate(this.getArmorStandName())); + this.generatorTierArmorStand.setCustomNameVisible(true); + this.generatorTierArmorStand.setCustomName(CC.translate("&fTier: &b" + this.generatorTier.getFormattedName())); + } + + if (this.secondsSinceActivation < this.getActivationTime()) { + return; + } + + this.secondsSinceActivation = 0; + + switch (this.generatorType) { + case IRON: + material = Material.IRON_INGOT; + + break; + case GOLD: + material = Material.GOLD_INGOT; + + break; + case DIAMOND: + material = Material.DIAMOND; + + break; + case EMERALD: + material = Material.EMERALD; + + break; + default: + throw new IllegalStateException("Unexcepted value: " + this.generatorType); + } + + this.location.getWorld().dropItemNaturally(this.location, new ItemStack(material, 1)); + } + + public void setActivated(boolean activated) { + if (this.activated == activated) { + return; + } + + this.activated = activated; + + if (this.isIslandGenerator) { + return; + } + + if (!activated) { + if (this.generatorTypeArmorStand != null) { + this.generatorTypeArmorStand.remove(); + } + + if (this.generatorTierArmorStand != null) { + this.generatorTierArmorStand.remove(); + } + + if (this.indictatorArmorStand != null) { + this.indictatorArmorStand.remove(); + } + + if (this.rotateIndicatorTask != null) { + this.rotateIndicatorTask.cancel(); + } + + return; + } + + Material generatorTypeMaterial = Material.STONE; + + if (this.generatorType == GeneratorType.DIAMOND) { + generatorTypeMaterial = Material.DIAMOND_BLOCK; + } else if (this.generatorType == GeneratorType.EMERALD) { + generatorTypeMaterial = Material.EMERALD_BLOCK; + } + + this.indictatorArmorStand = this.location.getWorld().spawn(this.location.clone().add(0.0D, 0.5D, 0.0D), ArmorStand.class); + this.indictatorArmorStand.setVisible(false); + this.indictatorArmorStand.setOp(true); + this.indictatorArmorStand.setGravity(false); + this.indictatorArmorStand.getEquipment().setHelmet(new ItemStack(generatorTypeMaterial)); + this.generatorTypeArmorStand = this.location.getWorld().spawn(this.location.clone().add(0.0D, 1.0D, 0.0D), ArmorStand.class); + this.generatorTypeArmorStand.setVisible(false); + this.generatorTypeArmorStand.setOp(true); + this.generatorTypeArmorStand.setCustomNameVisible(true); + this.generatorTypeArmorStand.setGravity(false); + this.generatorTypeArmorStand.setCustomName(CC.translate(this.getArmorStandName())); + this.generatorTierArmorStand = this.location.getWorld().spawn(this.location.clone().add(0.0D, 1.8D, 0.0D), ArmorStand.class); + this.generatorTierArmorStand.setVisible(false); + this.generatorTierArmorStand.setOp(true); + this.generatorTierArmorStand.setCustomNameVisible(true); + this.generatorTierArmorStand.setGravity(false); + this.generatorTierArmorStand.setCustomName(CC.translate(this.getArmorStandName())); + + if (this.main != null) { + this.rotateIndicatorTask = this.main.getServer().getScheduler().runTaskTimer(this.main, () -> { + EulerAngle eulerAngle = this.indictatorArmorStand.getHeadPose(); + + if (eulerAngle.getY() > 360D) { + eulerAngle = eulerAngle.setY(0D); + } + + this.indictatorArmorStand.setHeadPose(eulerAngle.setY(eulerAngle.getY() + 5D)); + }, 0L, 4L); + } + } + + public int getActivationTime() { + switch (this.generatorType) { + case IRON: + if (this.generatorTier == GeneratorTier.ONE) { + return 3; + } + + if (this.generatorTier == GeneratorTier.TWO) { + return 2; + } + + if (this.generatorTier == GeneratorTier.THREE) { + return 2; + } + + return 1; + case GOLD: + if (this.generatorTier == GeneratorTier.ONE) { + return 12; + } + + if (this.generatorTier == GeneratorTier.TWO) { + return 10; + } + + if (this.generatorTier == GeneratorTier.THREE) { + return 8; + } + + return 5; + case DIAMOND: + if (this.generatorTier == GeneratorTier.ONE) { + return 30; + } + + if (this.generatorTier == GeneratorTier.TWO) { + return 20; + } + + if (this.generatorTier == GeneratorTier.THREE) { + return 15; + } + + return 10; + case EMERALD: + if (this.isIslandGenerator) { + if (this.generatorTier == GeneratorTier.ONE) { + return 30; + } + + if (this.generatorTier == GeneratorTier.TWO) { + return 20; + } + } else { + if (this.generatorTier == GeneratorTier.ONE) { + return 40; + } + + if (this.generatorTier == GeneratorTier.TWO) { + return 20; + } + + return 15; + } + + break; + } + + return 20; + } + + public String getArmorStandName() { + int timeLeft = this.getActivationTime() - this.secondsSinceActivation; + + if (timeLeft == 0) { + timeLeft = this.getActivationTime(); + } + + String generatorTypeName = this.generatorType.name().toUpperCase().charAt(0) + this.generatorType.name().substring(1).toLowerCase(); + + return this.generatorType.getColorCode() + generatorTypeName + " &7⚫ &f" + timeLeft + " second" + (timeLeft == 1 ? "" : "s") + "..."; + } + + public Location getLocation() { + return this.location; + } + + public GeneratorType getGeneratorType() { + return this.generatorType; + } + + public void setGeneratorTier() { + this.generatorTier = generatorTier; + } +} diff --git a/src/main/java/rip/tilly/bedwars/generators/GeneratorTier.java b/src/main/java/rip/tilly/bedwars/generators/GeneratorTier.java new file mode 100644 index 0000000..beefc02 --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/generators/GeneratorTier.java @@ -0,0 +1,27 @@ +package rip.tilly.bedwars.generators; + +public enum GeneratorTier { + + ONE, + TWO, + THREE, + FOUR, + FIVE; + + public String getFormattedName() { + switch (this) { + case ONE: + return "I"; + case TWO: + return "II"; + case THREE: + return "III"; + case FOUR: + return "IV"; + case FIVE: + return "V"; + } + + return "I"; + } +} diff --git a/src/main/java/rip/tilly/bedwars/generators/GeneratorType.java b/src/main/java/rip/tilly/bedwars/generators/GeneratorType.java new file mode 100644 index 0000000..c8adf9d --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/generators/GeneratorType.java @@ -0,0 +1,24 @@ +package rip.tilly.bedwars.generators; + +public enum GeneratorType { + + IRON, + GOLD, + DIAMOND, + EMERALD; + + public String getColorCode() { + switch (this) { + case IRON: + return "&f"; + case GOLD: + return "&6"; + case DIAMOND: + return "&b"; + case EMERALD: + return "&a"; + } + + return "&f"; + } +} diff --git a/src/main/java/rip/tilly/bedwars/managers/arena/ArenaManager.java b/src/main/java/rip/tilly/bedwars/managers/arena/ArenaManager.java index 9480289..57b7d48 100644 --- a/src/main/java/rip/tilly/bedwars/managers/arena/ArenaManager.java +++ b/src/main/java/rip/tilly/bedwars/managers/arena/ArenaManager.java @@ -8,6 +8,7 @@ import org.bukkit.configuration.file.FileConfiguration; import rip.tilly.bedwars.BedWars; import rip.tilly.bedwars.game.arena.Arena; import rip.tilly.bedwars.game.arena.CopiedArena; +import rip.tilly.bedwars.generators.Generator; import rip.tilly.bedwars.utils.CustomLocation; import rip.tilly.bedwars.utils.config.file.Config;