This commit is contained in:
Luca 2021-11-26 20:03:54 +01:00
parent b14b37540b
commit 03b61cc2ad
12 changed files with 335 additions and 25 deletions

View File

@ -300,11 +300,11 @@ public class Game {
int minutesLeft = difference % 3600 / 60;
int secondsLeft = difference % 60;
return entry.getValue() + "&7: &d" + String.format("%02d:%02d", minutesLeft, secondsLeft);
return entry.getValue() + ": &d" + String.format("%02d:%02d", minutesLeft, secondsLeft);
}
}
return null;
return "&cNone";
}
public double secondsToMinutes(int seconds) {

View File

@ -157,7 +157,7 @@ public class Generator {
this.generatorTierArmorStand.setCustomName(CC.translate(this.getArmorStandName()));
if (this.main != null) {
this.rotateIndicatorTask = this.main.getServer().getScheduler().runTaskTimer(this.main, () -> {
this.rotateIndicatorTask = this.main.getServer().getScheduler().runTaskTimerAsynchronously(this.main, () -> {
EulerAngle eulerAngle = this.indictatorArmorStand.getHeadPose();
if (eulerAngle.getY() > 360D) {

View File

@ -86,7 +86,7 @@ public class GameStartListener implements Listener {
player.teleport(team.getId() == 1 ? locationA.toBukkitLocation() : locationB.toBukkitLocation());
player.getInventory().setArmorContents(this.plugin.getGameManager().getGameArmor(playerData));
player.getInventory().setArmorContents(this.plugin.getGameManager().getGameStartArmor(playerData));
for (ItemStack stack : this.plugin.getGameManager().getGameItems(playerData.getCurrentGameData(), playerData.getPlayerTeam().getTeamUpgrades())) {
player.getInventory().addItem(stack);
}

View File

@ -19,6 +19,7 @@ import rip.tilly.bedwars.playerdata.PlayerData;
import rip.tilly.bedwars.playerdata.PlayerState;
import rip.tilly.bedwars.playerdata.currentgame.PlayerCurrentGameData;
import rip.tilly.bedwars.playerdata.currentgame.TeamUpgrades;
import rip.tilly.bedwars.upgrades.Upgrade;
import rip.tilly.bedwars.utils.ItemBuilder;
import rip.tilly.bedwars.utils.PlayerUtil;
import rip.tilly.bedwars.utils.TtlHashMap;
@ -215,8 +216,11 @@ public class GameManager {
public List<ItemStack> getGameItems(PlayerCurrentGameData currentGameData, TeamUpgrades teamUpgrades) {
List<ItemStack> allItems = new ArrayList<>();
ItemStack sword = new ItemBuilder(Material.WOOD_SWORD).addUnbreakable().build();
allItems.add(sword);
ItemBuilder sword = new ItemBuilder(Material.WOOD_SWORD).addUnbreakable();
if (teamUpgrades.getLevelForUpgrade(Upgrade.SHARPENED_SWORDS) == 1) {
sword.enchantment(Enchantment.DAMAGE_ALL, 1);
}
allItems.add(sword.build());
if (currentGameData.isShears()) {
ItemStack shears = new ItemBuilder(Material.SHEARS).addUnbreakable().build();
@ -239,7 +243,6 @@ public class GameManager {
axe = new ItemBuilder(Material.DIAMOND_AXE).enchantment(Enchantment.DIG_SPEED, 3).addUnbreakable().build();
break;
default:
axe = null;
break;
}
}
@ -263,7 +266,6 @@ public class GameManager {
pickaxe = new ItemBuilder(Material.DIAMOND_PICKAXE).enchantment(Enchantment.DIG_SPEED, 3).addUnbreakable().build();
break;
default:
pickaxe = null;
break;
}
}
@ -274,7 +276,7 @@ public class GameManager {
return allItems;
}
public ItemStack[] getGameArmor(PlayerData playerData) {
public ItemStack[] getGameStartArmor(PlayerData playerData) {
Color color = playerData.getPlayerTeam().getColor();
ItemStack leatherBoots = new ItemBuilder(Material.LEATHER_BOOTS).color(color).addUnbreakable().build();

View File

@ -4,6 +4,7 @@ import lombok.AllArgsConstructor;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import rip.tilly.bedwars.menus.shop.armor.ArmorMenu;
import rip.tilly.bedwars.menus.shop.blocks.BlocksMenu;
import rip.tilly.bedwars.utils.ItemBuilder;
import rip.tilly.bedwars.utils.menu.Button;
@ -40,6 +41,7 @@ public class ShopTypeButton extends Button {
new BlocksMenu().openMenu(player);
break;
case ARMOR:
new ArmorMenu().openMenu(player);
break;
case TOOLS:
break;

View File

@ -0,0 +1,135 @@
package rip.tilly.bedwars.menus.shop.armor;
import lombok.AllArgsConstructor;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import rip.tilly.bedwars.BedWars;
import rip.tilly.bedwars.playerdata.PlayerData;
import rip.tilly.bedwars.playerdata.currentgame.ArmorType;
import rip.tilly.bedwars.playerdata.currentgame.TeamUpgrades;
import rip.tilly.bedwars.utils.CC;
import rip.tilly.bedwars.utils.ItemBuilder;
import rip.tilly.bedwars.utils.PlayerUtil;
import rip.tilly.bedwars.utils.menu.Button;
import java.util.ArrayList;
import java.util.List;
@AllArgsConstructor
public class ArmorButton extends Button {
private final String name;
private final Material material;
private final Material costType;
private final String costTypeName;
private final ChatColor costTypeColor;
private final int cost;
private final ArmorType armorType;
@Override
public ItemStack getButtonItem(Player player) {
List<String> loreList = new ArrayList<>();
PlayerData playerData = BedWars.getInstance().getPlayerDataManager().getPlayerData(player.getUniqueId());
TeamUpgrades teamUpgrades = playerData.getPlayerTeam().getTeamUpgrades();
loreList.add(" ");
loreList.add("&7&oYou will keep this armor");
loreList.add("&7&oupon death.");
loreList.add(" ");
if (teamUpgrades.getArmorType(player) == armorType) {
loreList.add("&cYou already own this!");
} else if (teamUpgrades.getArmorType(player) == ArmorType.DIAMOND) {
loreList.add("&cYou have the highest tier of armor!");
} else if (teamUpgrades.getArmorType(player) == ArmorType.IRON && armorType == ArmorType.CHAIN) {
loreList.add("&cYou already have a higher tier of armor!");
} else {
loreList.add("&9Cost: " + costTypeColor + cost + " " + costTypeName);
}
int costItems = 0;
for (ItemStack contents : player.getInventory().getContents()) {
if (contents != null) {
if (contents.getType() == costType) {
costItems += contents.getAmount();
}
}
}
loreList.add(" ");
loreList.add(costItems >= cost ? "&aClick to purchase!" : "&cYou don't have enough " + costTypeName + "!");
return new ItemBuilder(material)
.name((costItems >= cost ? "&a" : "&c") + name)
.lore(loreList)
.hideFlags()
.build();
}
@Override
public void clicked(Player player, int slot, ClickType clickType, int hotbarButton) {
if (clickType.isShiftClick()) {
return;
}
PlayerData playerData = BedWars.getInstance().getPlayerDataManager().getPlayerData(player.getUniqueId());
TeamUpgrades teamUpgrades = playerData.getPlayerTeam().getTeamUpgrades();
if (teamUpgrades.getArmorType(player) == armorType) {
player.sendMessage(CC.translate("&cYou already own this armor!"));
playFail(player);
return;
}
if (teamUpgrades.getArmorType(player) == ArmorType.DIAMOND) {
player.sendMessage(CC.translate("&cYou have the highest tier of armor!"));
playFail(player);
return;
}
if (teamUpgrades.getArmorType(player) == ArmorType.IRON && armorType == ArmorType.CHAIN) {
player.sendMessage(CC.translate("&cYou already have a higher tier of armor!"));
playFail(player);
return;
}
int costItems = 0;
for (ItemStack contents : player.getInventory().getContents()) {
if (contents != null) {
if (contents.getType() == costType) {
costItems += contents.getAmount();
}
}
}
if (costItems < cost) {
player.sendMessage(CC.translate("&cYou don't have enough " + costTypeName + "!"));
playFail(player);
return;
}
int finalCost = cost;
for (ItemStack i : player.getInventory().getContents()) {
if (i == null) {
continue;
}
if (i.getType() == costType) {
if (i.getAmount() < finalCost) {
finalCost -= i.getAmount();
PlayerUtil.minusAmount(player, i, i.getAmount());
player.updateInventory();
} else {
PlayerUtil.minusAmount(player, i, finalCost);
player.updateInventory();
break;
}
}
}
teamUpgrades.setArmorType(player, armorType);
playNeutral(player);
}
}

View File

@ -0,0 +1,52 @@
package rip.tilly.bedwars.menus.shop.armor;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import rip.tilly.bedwars.menus.shop.ShopType;
import rip.tilly.bedwars.menus.shop.ShopTypeButton;
import rip.tilly.bedwars.playerdata.currentgame.ArmorType;
import rip.tilly.bedwars.utils.CC;
import rip.tilly.bedwars.utils.ItemBuilder;
import rip.tilly.bedwars.utils.menu.Button;
import rip.tilly.bedwars.utils.menu.Menu;
import java.util.HashMap;
import java.util.Map;
public class ArmorMenu extends Menu {
@Override
public boolean isUpdateAfterClick() {
return true;
}
@Override
public String getTitle(Player player) {
return CC.translate("&eClick armor to purchase...");
}
@Override
public Map<Integer, Button> getButtons(Player player) {
Map<Integer, Button> buttons = new HashMap<>();
for (ShopType types : ShopType.values()) {
buttons.put(types.getSlot(), new ShopTypeButton(types));
}
buttons.put(ShopType.ARMOR.getSlot() + 9, Button.placeholder(Material.STAINED_GLASS_PANE, (byte) 5, " "));
buttons.put(19, new ArmorButton("Permanent Chain Armor", Material.CHAINMAIL_BOOTS, Material.IRON_INGOT, "Iron", ChatColor.WHITE, 40, ArmorType.CHAIN));
buttons.put(20, new ArmorButton("Permanent Iron Armor", Material.IRON_BOOTS, Material.GOLD_INGOT, "Gold", ChatColor.GOLD, 12, ArmorType.IRON));
buttons.put(21, new ArmorButton("Permanent Diamond Armor", Material.DIAMOND_BOOTS, Material.EMERALD, "Emeralds", ChatColor.DARK_GREEN, 6, ArmorType.DIAMOND));
fillEmptySlots(buttons, new ItemBuilder(Material.STAINED_GLASS_PANE).durability(7).name(" ").build());
return buttons;
}
@Override
public int getSize() {
return 6 * 9;
}
}

View File

@ -0,0 +1,103 @@
package rip.tilly.bedwars.menus.shop.tools;
import lombok.AllArgsConstructor;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import rip.tilly.bedwars.playerdata.currentgame.PlayerCurrentGameData;
import rip.tilly.bedwars.utils.CC;
import rip.tilly.bedwars.utils.ItemBuilder;
import rip.tilly.bedwars.utils.PlayerUtil;
import rip.tilly.bedwars.utils.menu.Button;
import java.util.ArrayList;
import java.util.List;
@AllArgsConstructor
public class ShearsButton extends Button {
private final String name;
private final Material material;
private final Material costType;
private final String costTypeName;
private final ChatColor costTypeColor;
private final int cost;
private final PlayerCurrentGameData currentGameData;
@Override
public ItemStack getButtonItem(Player player) {
List<String> loreList = new ArrayList<>();
loreList.add(" ");
if (currentGameData.isShears()) {
loreList.add("&cYou already have shears!");
} else {
loreList.add("&9Cost: " + costTypeColor + cost + " " + costTypeName);
}
int costItems = 0;
for (ItemStack contents : player.getInventory().getContents()) {
if (contents != null) {
if (contents.getType() == costType) {
costItems += contents.getAmount();
}
}
}
loreList.add(" ");
loreList.add(costItems >= cost ? "&aClick to purchase!" : "&cYou don't have enough " + costTypeName + "!");
return new ItemBuilder(material)
.name((costItems >= cost ? "&a" : "&c") + name)
.lore(loreList)
.hideFlags()
.build();
}
@Override
public void clicked(Player player, int slot, ClickType clickType, int hotbarButton) {
if (clickType.isShiftClick()) {
return;
}
int costItems = 0;
for (ItemStack contents : player.getInventory().getContents()) {
if (contents != null) {
if (contents.getType() == costType) {
costItems += contents.getAmount();
}
}
}
if (costItems < cost) {
player.sendMessage(CC.translate("&cYou don't have enough " + costTypeName + "!"));
playFail(player);
return;
}
int finalCost = cost;
for (ItemStack i : player.getInventory().getContents()) {
if (i == null) {
continue;
}
if (i.getType() == costType) {
if (i.getAmount() < finalCost) {
finalCost -= i.getAmount();
PlayerUtil.minusAmount(player, i, i.getAmount());
player.updateInventory();
} else {
PlayerUtil.minusAmount(player, i, finalCost);
player.updateInventory();
break;
}
}
}
player.getInventory().addItem(new ItemBuilder(material)
.addUnbreakable()
.hideFlags()
.build());
}
}

View File

@ -0,0 +1,6 @@
package rip.tilly.bedwars.menus.shop.tools;
import rip.tilly.bedwars.utils.menu.Menu;
public class ToolsMenu extends Menu {
}

View File

@ -171,7 +171,7 @@ public class TeamUpgrades {
return;
}
player.getInventory().setLeggings((new ItemBuilder(leggingsMaterial)).color(gameTeam.getPlayerTeam().getColor()).addEnchantments(protection).addUnbreakable().build());
player.getInventory().setBoots((new ItemBuilder(bootsMaterial)).color(gameTeam.getPlayerTeam().getColor()).addEnchantments(protection).addUnbreakable().build());
player.getInventory().setLeggings((new ItemBuilder(leggingsMaterial)).addEnchantments(protection).addUnbreakable().build());
player.getInventory().setBoots((new ItemBuilder(bootsMaterial)).addEnchantments(protection).addUnbreakable().build());
}
}

View File

@ -1,10 +1,9 @@
package rip.tilly.bedwars.runnables;
import lombok.AllArgsConstructor;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable;
@ -18,7 +17,6 @@ import rip.tilly.bedwars.playerdata.PlayerState;
import rip.tilly.bedwars.playerdata.currentgame.TeamUpgrades;
import rip.tilly.bedwars.upgrades.Upgrade;
import rip.tilly.bedwars.utils.CC;
import rip.tilly.bedwars.utils.ItemBuilder;
@AllArgsConstructor
public class RespawnRunnable extends BukkitRunnable {
@ -52,28 +50,19 @@ public class RespawnRunnable extends BukkitRunnable {
this.player.sendMessage(CC.translate("&aYou have respawned!"));
this.player.playSound(this.player.getLocation(), Sound.ORB_PICKUP, 10F, 1F);
// this.player.getInventory().setArmorContents(this.plugin.getGameManager().getGameArmor(this.playerData, this.playerData.getPlayerTeam().getTeamUpgrades()));
// for (ItemStack stack : this.plugin.getGameManager().getGameItems(this.playerData.getCurrentGameData(), this.playerData.getPlayerTeam().getTeamUpgrades())) {
// this.player.getInventory().addItem(stack);
// }
PlayerData playerData = this.plugin.getPlayerDataManager().getPlayerData(this.player.getUniqueId());
TeamUpgrades teamUpgrades = playerData.getPlayerTeam().getTeamUpgrades();
teamUpgrades.giveTeamArmor(this.player);
ItemBuilder itemBuilder = new ItemBuilder(Material.WOOD_SWORD).addUnbreakable();
if (teamUpgrades.getLevelForUpgrade(Upgrade.SHARPENED_SWORDS) == 1) {
itemBuilder.enchantment(Enchantment.DAMAGE_ALL, 1);
for (ItemStack stack : this.plugin.getGameManager().getGameItems(this.playerData.getCurrentGameData(), teamUpgrades)) {
this.player.getInventory().addItem(stack);
}
if (teamUpgrades.getLevelForUpgrade(Upgrade.MANIAC_MINER) != 0) {
this.player.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, 1000000, teamUpgrades.getLevelForUpgrade(Upgrade.MANIAC_MINER)));
}
player.getInventory().addItem(itemBuilder.build());
this.game.getTeams().forEach(team -> team.playingPlayers().filter(player1 -> !this.player.equals(player1))
.forEach(matchplayer -> matchplayer.sendMessage(CC.translate(this.gameTeam.getPlayerTeam().getChatColor() + this.player.getName() + " &ehas respawned!"))));

View File

@ -0,0 +1,21 @@
package rip.tilly.bedwars.upgrades;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import rip.tilly.bedwars.utils.ItemBuilder;
@Getter
@RequiredArgsConstructor
public enum AxeTier {
NONE(0, Material.AIR, null, 0),
WOOD(10, Material.IRON_INGOT, new ItemBuilder(Material.WOOD_AXE).enchantment(Enchantment.DIG_SPEED, 1).name(), 1)
private final int cost;
private final Material costType;
private final ItemStack item;
private final int level;
}