do not touch the generators

This commit is contained in:
Trixkz 2021-11-22 16:50:49 -05:00
parent da2fe2dbc1
commit 09927d2a76
10 changed files with 483 additions and 9 deletions

View File

@ -41,14 +41,5 @@
<orderEntry type="library" scope="PROVIDED" name="Maven: com.boydti:fawe-api:latest" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: me.clip:placeholderapi:2.10.9" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.jetbrains:annotations:19.0.0" level="project" />
<orderEntry type="module-library">
<library name="Maven: club.frozed.tablist:FrozedTablist:4.0-SNAPSHOT">
<CLASSES>
<root url="jar://$MODULE_DIR$/libs/FrozedTablist-4.0-SNAPSHOT.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>

View File

@ -43,6 +43,9 @@ public class ArenaCommand implements CommandExecutor {
player.sendMessage(CC.translate("&7⚫ &9/arena setTeamBMax <arena> &7- &eSet team B max"));
player.sendMessage(CC.translate("&7⚫ &9/arena setDeadZone <arena> <amount> &7- &eSet the dead zone"));
player.sendMessage(CC.translate("&7⚫ &9/arena setBuildMax <arena> <amount> &7- &eSet the build max"));
player.sendMessage(CC.translate("&7⚫ &9/arena setPlayerGenerator <arena> <&7- &eSet the player's generator"));
player.sendMessage(CC.translate("&7⚫ &9/arena setDiamondGenerator <arena> <&7- &eSet the diamond generator"));
player.sendMessage(CC.translate("&7⚫ &9/arena setEmeraldGenerator <arena> <&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)"));

View File

@ -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<String> getTabCompletions(CommandSender sender, Command cmd, String label, String[] args) {
List<String> tabCompletions = new ArrayList<String>();
return tabCompletions;
}
}

View File

@ -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<String> getTabCompletions(CommandSender sender, Command cmd, String label, String[] args) {
List<String> tabCompletions = new ArrayList<String>();
return tabCompletions;
}
}

View File

@ -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<String> getTabCompletions(CommandSender sender, Command cmd, String label, String[] args) {
List<String> tabCompletions = new ArrayList<String>();
return tabCompletions;
}
}

View File

@ -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<Generator> playerGenerators;
// private List<Generator> diamondGenerators;
// private List<Generator> emeraldGenerators;
private boolean enabled;
public CopiedArena getAvailableArena() {

View File

@ -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;
}
}

View File

@ -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";
}
}

View File

@ -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";
}
}

View File

@ -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;