This commit is contained in:
Luca 2021-11-24 20:29:53 +01:00
parent 980743ef62
commit e076e76c57
13 changed files with 223 additions and 434 deletions

View File

@ -313,16 +313,4 @@ public class Game {
this.addEntityToRemove(teamAUpgradesVillager);
this.addEntityToRemove(teamBUpgradesVillager);
}
public boolean checkTrapStatus(Player player) {
PlayerData playerData = this.plugin.getPlayerDataManager().getPlayerData(player.getUniqueId());
GameTeam gameTeam = this.getTeams().get(playerData.getTeamId());
if (player.getLocation().distance((gameTeam.getId() == 0 ? this.copiedArena.getA().toBukkitLocation() : this.copiedArena.getB().toBukkitLocation())) < 15) {
return true;
}
return false;
}
}

View File

@ -5,6 +5,7 @@ import lombok.Setter;
import org.bukkit.entity.Player;
import rip.tilly.bedwars.BedWars;
import rip.tilly.bedwars.playerdata.PlayerTeam;
import rip.tilly.bedwars.playerdata.currentgame.PlayerCurrentGameData;
import java.util.ArrayList;
import java.util.List;
@ -25,6 +26,8 @@ public class GameTeam {
private final int id;
private final PlayerTeam playerTeam;
private final PlayerCurrentGameData playerCurrentGameData;
private boolean hasBed = true;
public GameTeam(UUID leader, List<UUID> allPlayers, int id, PlayerTeam playerTeam) {
@ -34,6 +37,7 @@ public class GameTeam {
this.id = id;
this.playerTeam = playerTeam;
this.playerCurrentGameData = new PlayerCurrentGameData();
}
public void killPlayer(UUID uuid) {

View File

@ -11,7 +11,7 @@ import rip.tilly.bedwars.game.GameState;
import rip.tilly.bedwars.game.GameTeam;
import rip.tilly.bedwars.generators.Generator;
import rip.tilly.bedwars.playerdata.PlayerData;
import rip.tilly.bedwars.playerdata.currentgame.PlayerCurrentGameData;
import rip.tilly.bedwars.playerdata.currentgame.TeamUpgrades;
import rip.tilly.bedwars.utils.CC;
import rip.tilly.bedwars.utils.PlayerUtil;
@ -39,13 +39,13 @@ public class GameEndListener implements Listener {
PlayerData playerData = this.plugin.getPlayerDataManager().getPlayerData(player.getUniqueId());
PlayerCurrentGameData playerCurrentGameData = playerData.getCurrentGameData();
TeamUpgrades teamUpgrades = playerData.getPlayerTeam().getTeamUpgrades();
playerData.setLastDamager(null);
playerData.getCurrentGameData().setGameKills(0);
playerData.getCurrentGameData().setGameBedsDestroyed(0);
playerCurrentGameData.getUpgrades().clear();
teamUpgrades.getUpgrades().clear();
String winnerTitle = CC.translate("&aVICTORY!");
String losingTitle = CC.translate("&cDEFEAT!");

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, playerData.getPlayerTeam().getTeamUpgrades()));
player.getInventory().setArmorContents(this.plugin.getGameManager().getGameArmor(playerData));
for (ItemStack stack : this.plugin.getGameManager().getGameItems(playerData.getCurrentGameData(), playerData.getPlayerTeam().getTeamUpgrades())) {
player.getInventory().addItem(stack);
}

View File

@ -7,12 +7,12 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import rip.tilly.bedwars.BedWars;
import rip.tilly.bedwars.events.PlayerKillEvent;
import rip.tilly.bedwars.game.Game;
import rip.tilly.bedwars.game.GameState;
import rip.tilly.bedwars.events.PlayerKillEvent;
import rip.tilly.bedwars.game.GameTeam;
import rip.tilly.bedwars.playerdata.PlayerData;
import rip.tilly.bedwars.playerdata.PlayerState;
import rip.tilly.bedwars.playerdata.currentgame.PlayerCurrentGameData;
import rip.tilly.bedwars.upgrades.Upgrade;
import rip.tilly.bedwars.utils.CC;
@ -61,27 +61,16 @@ public class MovementListener implements Listener {
}
}
if (game.getGameState() == GameState.FIGHTING) {
game.getTeams().forEach(gameTeam -> {
gameTeam.playingPlayers().forEach(teamPlayer -> {
PlayerData teamPlayerData = this.plugin.getPlayerDataManager().getPlayerData(teamPlayer.getUniqueId());
PlayerCurrentGameData teamPlayerCurrentGameData = teamPlayerData.getCurrentGameData();
if (teamPlayerCurrentGameData.getLevelForUpgrade(Upgrade.TRAP) != 0) {
if (game.checkTrapStatus(player)) {
teamPlayerCurrentGameData.getUpgrades().remove(Upgrade.TRAP);
teamPlayer.sendMessage(CC.translate("&cYour trap has been activated"));
game.broadcastTitleToOneTeam("&cTRAP ACTIVATED", "&eYour trap has been activated", gameTeam);
}
}
});
});
}
GameTeam opposingTeam = game.getTeams().get(playerData.getTeamId() == 0 ? 1 : 0);
if (game.getGameState() != GameState.ENDING) {
if (opposingTeam.getPlayerTeam().getTeamUpgrades().getLevelForUpgrade(Upgrade.TRAP) != 0) {
if (player.getLocation().distance((playerData.getTeamId() == 0 ? game.getCopiedArena().getA().toBukkitLocation() : game.getCopiedArena().getB().toBukkitLocation())) < 15) {
opposingTeam.getPlayerTeam().getTeamUpgrades().getUpgrades().remove(Upgrade.TRAP);
opposingTeam.playingPlayers().forEach(enemyPlayer -> enemyPlayer.sendMessage(CC.translate("&cYour trap has been activated")));
game.broadcastTitleToOneTeam("&cTRAP ACTIVATED", "&eYour trap has been activated", opposingTeam);
}
}
if (player.getLocation().getY() <= game.getArena().getDeadZone()) {
Player killer = playerData.getLastDamager();
if (killer != null) {

View File

@ -222,7 +222,7 @@ public class WorldListener implements Listener {
event.setCancelled(true);
return;
}
game.getDroppedItems().add(itemStack);
game.addEntityToRemove(item);
}

View File

@ -10,17 +10,16 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import rip.tilly.bedwars.BedWars;
import rip.tilly.bedwars.game.*;
import rip.tilly.bedwars.game.arena.Arena;
import rip.tilly.bedwars.events.GameEndEvent;
import rip.tilly.bedwars.events.GameStartEvent;
import rip.tilly.bedwars.game.*;
import rip.tilly.bedwars.game.arena.Arena;
import rip.tilly.bedwars.managers.hotbar.impl.HotbarItem;
import rip.tilly.bedwars.playerdata.currentgame.PlayerCurrentGameData;
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.utils.ItemBuilder;
import rip.tilly.bedwars.utils.ItemUtil;
import rip.tilly.bedwars.utils.PlayerUtil;
import rip.tilly.bedwars.utils.TtlHashMap;
@ -217,9 +216,6 @@ public class GameManager {
List<ItemStack> allItems = new ArrayList<>();
ItemStack sword = new ItemBuilder(Material.WOOD_SWORD).addUnbreakable().build();
if (teamUpgrades.isSharpenedSwords()) {
sword = new ItemBuilder(Material.WOOD_SWORD).enchantment(Enchantment.DAMAGE_ALL, 1).addUnbreakable().build();
}
allItems.add(sword);
if (currentGameData.isShears()) {
@ -278,217 +274,20 @@ public class GameManager {
return allItems;
}
public ItemStack[] getGameArmor(PlayerData playerData, TeamUpgrades teamUpgrades) {
public ItemStack[] getGameArmor(PlayerData playerData) {
Color color = playerData.getPlayerTeam().getColor();
PlayerCurrentGameData currentGameData = playerData.getCurrentGameData();
ItemStack leatherBoots = new ItemBuilder(Material.LEATHER_BOOTS).color(color).addUnbreakable().build();
ItemStack leatherLeggings = new ItemBuilder(Material.LEATHER_LEGGINGS).color(color).addUnbreakable().build();
ItemStack leatherChestplate = new ItemBuilder(Material.LEATHER_CHESTPLATE).color(color).addUnbreakable().build();
ItemStack leatherHelmet = new ItemBuilder(Material.LEATHER_HELMET).color(color).addUnbreakable().build();
ItemStack chainBoots = new ItemBuilder(Material.CHAINMAIL_BOOTS).addUnbreakable().build();
ItemStack chainLeggings = new ItemBuilder(Material.CHAINMAIL_LEGGINGS).addUnbreakable().build();
ItemStack ironBoots = new ItemBuilder(Material.IRON_BOOTS).addUnbreakable().build();
ItemStack ironLeggings = new ItemBuilder(Material.IRON_LEGGINGS).addUnbreakable().build();
ItemStack diamondBoots = new ItemBuilder(Material.DIAMOND_BOOTS).addUnbreakable().build();
ItemStack diamondLeggings = new ItemBuilder(Material.DIAMOND_LEGGINGS).addUnbreakable().build();
switch (teamUpgrades.getArmorLevel()) {
case 0:
switch (currentGameData.getArmorType()) {
case LEATHER:
return new ItemStack[]{
leatherBoots,
leatherLeggings,
leatherChestplate,
leatherHelmet
};
case CHAIN:
return new ItemStack[]{
chainBoots,
chainLeggings,
leatherChestplate,
leatherHelmet
};
case IRON:
return new ItemStack[]{
ironBoots,
ironLeggings,
leatherChestplate,
leatherHelmet
};
case DIAMOND:
return new ItemStack[]{
diamondBoots,
diamondLeggings,
leatherChestplate,
leatherHelmet
};
}
break;
case 1:
switch (currentGameData.getArmorType()) {
case LEATHER:
return new ItemStack[]{
ItemUtil.reEnchantItem(leatherBoots, Enchantment.PROTECTION_ENVIRONMENTAL, 1, true),
ItemUtil.reEnchantItem(leatherLeggings, Enchantment.PROTECTION_ENVIRONMENTAL, 1, true),
ItemUtil.reEnchantItem(leatherChestplate, Enchantment.PROTECTION_ENVIRONMENTAL, 1, true),
ItemUtil.reEnchantItem(leatherHelmet, Enchantment.PROTECTION_ENVIRONMENTAL, 1, true),
};
case CHAIN:
return new ItemStack[]{
ItemUtil.reEnchantItem(chainBoots, Enchantment.PROTECTION_ENVIRONMENTAL, 1, true),
ItemUtil.reEnchantItem(chainLeggings, Enchantment.PROTECTION_ENVIRONMENTAL, 1, true),
ItemUtil.reEnchantItem(leatherChestplate, Enchantment.PROTECTION_ENVIRONMENTAL, 1, true),
ItemUtil.reEnchantItem(leatherHelmet, Enchantment.PROTECTION_ENVIRONMENTAL, 1, true),
};
case IRON:
return new ItemStack[]{
ItemUtil.reEnchantItem(ironBoots, Enchantment.PROTECTION_ENVIRONMENTAL, 1, true),
ItemUtil.reEnchantItem(ironLeggings, Enchantment.PROTECTION_ENVIRONMENTAL, 1, true),
ItemUtil.reEnchantItem(leatherChestplate, Enchantment.PROTECTION_ENVIRONMENTAL, 1, true),
ItemUtil.reEnchantItem(leatherHelmet, Enchantment.PROTECTION_ENVIRONMENTAL, 1, true),
};
case DIAMOND:
return new ItemStack[]{
ItemUtil.reEnchantItem(diamondBoots, Enchantment.PROTECTION_ENVIRONMENTAL, 1, true),
ItemUtil.reEnchantItem(diamondLeggings, Enchantment.PROTECTION_ENVIRONMENTAL, 1, true),
ItemUtil.reEnchantItem(leatherChestplate, Enchantment.PROTECTION_ENVIRONMENTAL, 1, true),
ItemUtil.reEnchantItem(leatherHelmet, Enchantment.PROTECTION_ENVIRONMENTAL, 1, true),
};
}
break;
case 2:
switch (currentGameData.getArmorType()) {
case LEATHER:
return new ItemStack[]{
ItemUtil.reEnchantItem(leatherBoots, Enchantment.PROTECTION_ENVIRONMENTAL, 2, true),
ItemUtil.reEnchantItem(leatherLeggings, Enchantment.PROTECTION_ENVIRONMENTAL, 2, true),
ItemUtil.reEnchantItem(leatherChestplate, Enchantment.PROTECTION_ENVIRONMENTAL, 2, true),
ItemUtil.reEnchantItem(leatherHelmet, Enchantment.PROTECTION_ENVIRONMENTAL, 2, true),
};
case CHAIN:
return new ItemStack[]{
ItemUtil.reEnchantItem(chainBoots, Enchantment.PROTECTION_ENVIRONMENTAL, 2, true),
ItemUtil.reEnchantItem(chainLeggings, Enchantment.PROTECTION_ENVIRONMENTAL, 2, true),
ItemUtil.reEnchantItem(leatherChestplate, Enchantment.PROTECTION_ENVIRONMENTAL, 2, true),
ItemUtil.reEnchantItem(leatherHelmet, Enchantment.PROTECTION_ENVIRONMENTAL, 2, true),
};
case IRON:
return new ItemStack[]{
ItemUtil.reEnchantItem(ironBoots, Enchantment.PROTECTION_ENVIRONMENTAL, 2, true),
ItemUtil.reEnchantItem(ironLeggings, Enchantment.PROTECTION_ENVIRONMENTAL, 2, true),
ItemUtil.reEnchantItem(leatherChestplate, Enchantment.PROTECTION_ENVIRONMENTAL, 2, true),
ItemUtil.reEnchantItem(leatherHelmet, Enchantment.PROTECTION_ENVIRONMENTAL, 2, true),
};
case DIAMOND:
return new ItemStack[]{
ItemUtil.reEnchantItem(diamondBoots, Enchantment.PROTECTION_ENVIRONMENTAL, 2, true),
ItemUtil.reEnchantItem(diamondLeggings, Enchantment.PROTECTION_ENVIRONMENTAL, 2, true),
ItemUtil.reEnchantItem(leatherChestplate, Enchantment.PROTECTION_ENVIRONMENTAL, 2, true),
ItemUtil.reEnchantItem(leatherHelmet, Enchantment.PROTECTION_ENVIRONMENTAL, 2, true),
};
}
break;
case 3:
switch (currentGameData.getArmorType()) {
case LEATHER:
return new ItemStack[]{
ItemUtil.reEnchantItem(leatherBoots, Enchantment.PROTECTION_ENVIRONMENTAL, 3, true),
ItemUtil.reEnchantItem(leatherLeggings, Enchantment.PROTECTION_ENVIRONMENTAL, 3, true),
ItemUtil.reEnchantItem(leatherChestplate, Enchantment.PROTECTION_ENVIRONMENTAL, 3, true),
ItemUtil.reEnchantItem(leatherHelmet, Enchantment.PROTECTION_ENVIRONMENTAL, 3, true),
};
case CHAIN:
return new ItemStack[]{
ItemUtil.reEnchantItem(chainBoots, Enchantment.PROTECTION_ENVIRONMENTAL, 3, true),
ItemUtil.reEnchantItem(chainLeggings, Enchantment.PROTECTION_ENVIRONMENTAL, 3, true),
ItemUtil.reEnchantItem(leatherChestplate, Enchantment.PROTECTION_ENVIRONMENTAL, 3, true),
ItemUtil.reEnchantItem(leatherHelmet, Enchantment.PROTECTION_ENVIRONMENTAL, 3, true),
};
case IRON:
return new ItemStack[]{
ItemUtil.reEnchantItem(ironBoots, Enchantment.PROTECTION_ENVIRONMENTAL, 3, true),
ItemUtil.reEnchantItem(ironLeggings, Enchantment.PROTECTION_ENVIRONMENTAL, 3, true),
ItemUtil.reEnchantItem(leatherChestplate, Enchantment.PROTECTION_ENVIRONMENTAL, 3, true),
ItemUtil.reEnchantItem(leatherHelmet, Enchantment.PROTECTION_ENVIRONMENTAL, 3, true),
};
case DIAMOND:
return new ItemStack[]{
ItemUtil.reEnchantItem(diamondBoots, Enchantment.PROTECTION_ENVIRONMENTAL, 3, true),
ItemUtil.reEnchantItem(diamondLeggings, Enchantment.PROTECTION_ENVIRONMENTAL, 3, true),
ItemUtil.reEnchantItem(leatherChestplate, Enchantment.PROTECTION_ENVIRONMENTAL, 3, true),
ItemUtil.reEnchantItem(leatherHelmet, Enchantment.PROTECTION_ENVIRONMENTAL, 3, true),
};
}
break;
case 4:
switch (currentGameData.getArmorType()) {
case LEATHER:
return new ItemStack[]{
ItemUtil.reEnchantItem(leatherBoots, Enchantment.PROTECTION_ENVIRONMENTAL, 4, true),
ItemUtil.reEnchantItem(leatherLeggings, Enchantment.PROTECTION_ENVIRONMENTAL, 4, true),
ItemUtil.reEnchantItem(leatherChestplate, Enchantment.PROTECTION_ENVIRONMENTAL, 4, true),
ItemUtil.reEnchantItem(leatherHelmet, Enchantment.PROTECTION_ENVIRONMENTAL, 4, true),
};
case CHAIN:
return new ItemStack[]{
ItemUtil.reEnchantItem(chainBoots, Enchantment.PROTECTION_ENVIRONMENTAL, 4, true),
ItemUtil.reEnchantItem(chainLeggings, Enchantment.PROTECTION_ENVIRONMENTAL, 4, true),
ItemUtil.reEnchantItem(leatherChestplate, Enchantment.PROTECTION_ENVIRONMENTAL, 4, true),
ItemUtil.reEnchantItem(leatherHelmet, Enchantment.PROTECTION_ENVIRONMENTAL, 4, true),
};
case IRON:
return new ItemStack[]{
ItemUtil.reEnchantItem(ironBoots, Enchantment.PROTECTION_ENVIRONMENTAL, 4, true),
ItemUtil.reEnchantItem(ironLeggings, Enchantment.PROTECTION_ENVIRONMENTAL, 4, true),
ItemUtil.reEnchantItem(leatherChestplate, Enchantment.PROTECTION_ENVIRONMENTAL, 4, true),
ItemUtil.reEnchantItem(leatherHelmet, Enchantment.PROTECTION_ENVIRONMENTAL, 4, true),
};
case DIAMOND:
return new ItemStack[]{
ItemUtil.reEnchantItem(diamondBoots, Enchantment.PROTECTION_ENVIRONMENTAL, 4, true),
ItemUtil.reEnchantItem(diamondLeggings, Enchantment.PROTECTION_ENVIRONMENTAL, 4, true),
ItemUtil.reEnchantItem(leatherChestplate, Enchantment.PROTECTION_ENVIRONMENTAL, 4, true),
ItemUtil.reEnchantItem(leatherHelmet, Enchantment.PROTECTION_ENVIRONMENTAL, 4, true),
};
}
break;
default:
switch (currentGameData.getArmorType()) {
case LEATHER:
return new ItemStack[]{
leatherBoots,
leatherLeggings,
leatherChestplate,
leatherHelmet
};
case CHAIN:
return new ItemStack[]{
chainBoots,
chainLeggings,
leatherChestplate,
leatherHelmet
};
case IRON:
return new ItemStack[]{
ironBoots,
ironLeggings,
leatherChestplate,
leatherHelmet
};
case DIAMOND:
return new ItemStack[]{
diamondBoots,
diamondLeggings,
leatherChestplate,
leatherHelmet
};
}
break;
}
return null;
return new ItemStack[] {
leatherBoots,
leatherLeggings,
leatherChestplate,
leatherHelmet
};
}
public void clearBlocks(Game game) {

View File

@ -30,7 +30,7 @@ public enum PlayerTeam {
private final ChatColor chatColor;
private final int colorData;
private final String smallName;
private TeamUpgrades teamUpgrades;
private final TeamUpgrades teamUpgrades;
PlayerTeam(String name, Color color, ChatColor chatColor, int colorData, String smallName) {
this.name = name;

View File

@ -33,157 +33,4 @@ public class PlayerCurrentGameData {
private int pickaxeLevel = 0;
private int axeLevel = 0;
private boolean shears = false;
private ArmorType armorType = ArmorType.LEATHER;
private Map<UUID, ArmorType> armor = new HashMap<UUID, ArmorType>();
private Map<Upgrade, Integer> upgrades = new HashMap<Upgrade, Integer>();
public int getLevelForUpgrade(Upgrade upgrade) {
return this.upgrades.getOrDefault(upgrade, 0);
}
public int getCostToUpgrade(Upgrade upgrade) {
return upgrade.getCostForLevel(this.upgrades.getOrDefault(upgrade, 0) + 1);
}
public void upgrade(Player player, Game game, GameTeam gameTeam, Upgrade upgrade) {
this.upgrades.put(upgrade, this.upgrades.getOrDefault(upgrade, 0) + 1);
int level = this.upgrades.get(upgrade);
gameTeam.playingPlayers().forEach(teamPlayer -> {
teamPlayer.sendMessage(CC.translate("&6" + player.getName() + " upgraded " + upgrade.getFormattedName() + " to &cTier " + upgrade.getNumberToRomanNumeral(level)));
// System.out.println("11111111111111111111111 - " + player.getName());
this.giveTeamArmor(player, this);
int upgradeLevel = 0;
switch (upgrade) {
case SHARPENED_SWORDS:
// System.out.println("2222222222222222");
for (ListIterator<ItemStack> listIterator = player.getInventory().iterator(); listIterator.hasNext();) {
ItemStack itemStack = listIterator.next();
// System.out.println("33333333333333333");
if (itemStack != null && itemStack.getType().name().toLowerCase().contains("sword")) {
// System.out.println("444444444444444444444");
itemStack.addEnchantment(Enchantment.DAMAGE_ALL, 1);
}
}
break;
case MANIAC_MINER:
upgradeLevel = this.getLevelForUpgrade(upgrade);
player.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, 1000000, upgradeLevel));
break;
case FASTER_FORGE:
upgradeLevel = this.getLevelForUpgrade(upgrade);
int upgradeLevelFinal = upgradeLevel;
game.getActivatedGenerators().forEach(generator -> {
switch (upgradeLevelFinal) {
case 1:
if (generator.getGeneratorType() != GeneratorType.EMERALD) {
generator.setGeneratorTier(GeneratorTier.TWO);
}
break;
case 2:
if (generator.getGeneratorType() != GeneratorType.EMERALD) {
generator.setGeneratorTier(GeneratorTier.THREE);
}
break;
case 3:
if (generator.getGeneratorType() != GeneratorType.EMERALD) {
generator.setGeneratorTier(GeneratorTier.THREE);
} else {
generator.setActivated(true);
generator.setGeneratorTier(GeneratorTier.ONE);
}
break;
case 4:
if (generator.getGeneratorType() != GeneratorType.EMERALD) {
generator.setGeneratorTier(GeneratorTier.FOUR);
} else {
generator.setGeneratorTier(GeneratorTier.TWO);
}
break;
}
});
break;
}
});
}
public ArmorType getArmorType(Player player) {
return this.armor.getOrDefault(player.getUniqueId(), ArmorType.LEATHER);
}
public void setArmorType(Player player, ArmorType armorType) {
this.armor.put(player.getUniqueId(), armorType);
this.giveTeamArmor(player, this);
}
public void giveTeamArmor(Player player, PlayerCurrentGameData playerCurrentGameData) {
Material leggingsMaterial;
Material bootsMaterial;
Map<Enchantment, Integer> protection = new HashMap<Enchantment, Integer>();
int level = playerCurrentGameData.getLevelForUpgrade(Upgrade.PROTECTION);
if (level != 0) {
protection.put(Enchantment.PROTECTION_ENVIRONMENTAL, level);
}
Game game = this.main.getGameManager().getGame(player.getUniqueId());
PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId());
GameTeam gameTeam = game.getTeams().get(playerData.getTeamId());
player.getInventory().setHelmet((new ItemBuilder(Material.LEATHER_HELMET)).color(gameTeam.getPlayerTeam().getColor()).addEnchantments(protection).addUnbreakable().build());
player.getInventory().setChestplate((new ItemBuilder(Material.LEATHER_CHESTPLATE)).color(gameTeam.getPlayerTeam().getColor()).addEnchantments(protection).addUnbreakable().build());
ArmorType armorType = this.getArmorType(player);
if (armorType == ArmorType.LEATHER) {
player.getInventory().setLeggings((new ItemBuilder(Material.LEATHER_LEGGINGS)).color(gameTeam.getPlayerTeam().getColor()).addEnchantments(protection).addUnbreakable().build());
player.getInventory().setBoots((new ItemBuilder(Material.LEATHER_BOOTS)).color(gameTeam.getPlayerTeam().getColor()).addEnchantments(protection).addUnbreakable().build());
return;
}
switch (armorType) {
case CHAIN:
leggingsMaterial = Material.CHAINMAIL_LEGGINGS;
bootsMaterial = Material.CHAINMAIL_BOOTS;
break;
case IRON:
leggingsMaterial = Material.IRON_LEGGINGS;
bootsMaterial = Material.IRON_BOOTS;
break;
case DIAMOND:
leggingsMaterial = Material.DIAMOND_LEGGINGS;
bootsMaterial = Material.DIAMOND_BOOTS;
break;
default:
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());
}
}

View File

@ -1,17 +1,179 @@
package rip.tilly.bedwars.playerdata.currentgame;
import lombok.Data;
import org.bukkit.Material;
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 rip.tilly.bedwars.BedWars;
import rip.tilly.bedwars.game.Game;
import rip.tilly.bedwars.game.GameTeam;
import rip.tilly.bedwars.generators.GeneratorTier;
import rip.tilly.bedwars.generators.GeneratorType;
import rip.tilly.bedwars.playerdata.PlayerData;
import rip.tilly.bedwars.upgrades.Upgrade;
import rip.tilly.bedwars.utils.CC;
import rip.tilly.bedwars.utils.ItemBuilder;
import java.util.List;
import java.util.*;
@Data
public class TeamUpgrades {
private boolean sharpenedSwords;
private int armorLevel = 0;
private int maniacMiner = 0;
private int forgeLevel = 0;
private boolean healPool;
private boolean dragonBuff;
private List<String> trapList;
private BedWars main = BedWars.getInstance();
private ArmorType armorType = ArmorType.LEATHER;
private Map<UUID, ArmorType> armor = new HashMap<UUID, ArmorType>();
private Map<Upgrade, Integer> upgrades = new HashMap<Upgrade, Integer>();
public int getLevelForUpgrade(Upgrade upgrade) {
return this.upgrades.getOrDefault(upgrade, 0);
}
public int getCostToUpgrade(Upgrade upgrade) {
return upgrade.getCostForLevel(this.upgrades.getOrDefault(upgrade, 0) + 1);
}
public void upgrade(Player player, Game game, GameTeam gameTeam, Upgrade upgrade) {
this.upgrades.put(upgrade, this.upgrades.getOrDefault(upgrade, 0) + 1);
int level = this.upgrades.get(upgrade);
gameTeam.playingPlayers().forEach(teamPlayer -> {
teamPlayer.sendMessage(CC.translate("&6" + player.getName() + " upgraded " + upgrade.getFormattedName() + " to &cTier " + upgrade.getNumberToRomanNumeral(level)));
// System.out.println("11111111111111111111111 - " + player.getName());
this.giveTeamArmor(player);
int upgradeLevel = 0;
switch (upgrade) {
case SHARPENED_SWORDS:
// System.out.println("2222222222222222");
for (ListIterator<ItemStack> listIterator = player.getInventory().iterator(); listIterator.hasNext();) {
ItemStack itemStack = listIterator.next();
// System.out.println("33333333333333333");
if (itemStack != null && itemStack.getType().name().toLowerCase().contains("sword")) {
// System.out.println("444444444444444444444");
itemStack.addEnchantment(Enchantment.DAMAGE_ALL, 1);
}
}
break;
case MANIAC_MINER:
upgradeLevel = this.getLevelForUpgrade(upgrade);
player.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, 1000000, upgradeLevel));
break;
case FASTER_FORGE:
upgradeLevel = this.getLevelForUpgrade(upgrade);
int upgradeLevelFinal = upgradeLevel;
game.getActivatedGenerators().forEach(generator -> {
switch (upgradeLevelFinal) {
case 1:
if (generator.getGeneratorType() != GeneratorType.EMERALD) {
generator.setGeneratorTier(GeneratorTier.TWO);
}
break;
case 2:
if (generator.getGeneratorType() != GeneratorType.EMERALD) {
generator.setGeneratorTier(GeneratorTier.THREE);
}
break;
case 3:
if (generator.getGeneratorType() != GeneratorType.EMERALD) {
generator.setGeneratorTier(GeneratorTier.THREE);
} else {
generator.setActivated(true);
generator.setGeneratorTier(GeneratorTier.ONE);
}
break;
case 4:
if (generator.getGeneratorType() != GeneratorType.EMERALD) {
generator.setGeneratorTier(GeneratorTier.FOUR);
} else {
generator.setGeneratorTier(GeneratorTier.TWO);
}
break;
}
});
break;
}
});
}
public ArmorType getArmorType(Player player) {
return this.armor.getOrDefault(player.getUniqueId(), ArmorType.LEATHER);
}
public void setArmorType(Player player, ArmorType armorType) {
this.armor.put(player.getUniqueId(), armorType);
this.giveTeamArmor(player);
}
public void giveTeamArmor(Player player) {
Material leggingsMaterial;
Material bootsMaterial;
Map<Enchantment, Integer> protection = new HashMap<Enchantment, Integer>();
int level = this.getLevelForUpgrade(Upgrade.PROTECTION);
if (level != 0) {
protection.put(Enchantment.PROTECTION_ENVIRONMENTAL, level);
}
Game game = this.main.getGameManager().getGame(player.getUniqueId());
PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId());
GameTeam gameTeam = game.getTeams().get(playerData.getTeamId());
player.getInventory().setHelmet((new ItemBuilder(Material.LEATHER_HELMET)).color(gameTeam.getPlayerTeam().getColor()).addEnchantments(protection).addUnbreakable().build());
player.getInventory().setChestplate((new ItemBuilder(Material.LEATHER_CHESTPLATE)).color(gameTeam.getPlayerTeam().getColor()).addEnchantments(protection).addUnbreakable().build());
ArmorType armorType = this.getArmorType(player);
if (armorType == ArmorType.LEATHER) {
player.getInventory().setLeggings((new ItemBuilder(Material.LEATHER_LEGGINGS)).color(gameTeam.getPlayerTeam().getColor()).addEnchantments(protection).addUnbreakable().build());
player.getInventory().setBoots((new ItemBuilder(Material.LEATHER_BOOTS)).color(gameTeam.getPlayerTeam().getColor()).addEnchantments(protection).addUnbreakable().build());
return;
}
switch (armorType) {
case CHAIN:
leggingsMaterial = Material.CHAINMAIL_LEGGINGS;
bootsMaterial = Material.CHAINMAIL_BOOTS;
break;
case IRON:
leggingsMaterial = Material.IRON_LEGGINGS;
bootsMaterial = Material.IRON_BOOTS;
break;
case DIAMOND:
leggingsMaterial = Material.DIAMOND_LEGGINGS;
bootsMaterial = Material.DIAMOND_BOOTS;
break;
default:
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());
}
}

View File

@ -5,7 +5,6 @@ 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;
@ -16,7 +15,7 @@ import rip.tilly.bedwars.game.Game;
import rip.tilly.bedwars.game.GameTeam;
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.CC;
import rip.tilly.bedwars.utils.ItemBuilder;
@ -60,17 +59,17 @@ public class RespawnRunnable extends BukkitRunnable {
PlayerData playerData = this.plugin.getPlayerDataManager().getPlayerData(this.player.getUniqueId());
PlayerCurrentGameData playerCurrentGameData = playerData.getCurrentGameData();
playerCurrentGameData.giveTeamArmor(this.player, playerCurrentGameData);
TeamUpgrades teamUpgrades = playerData.getPlayerTeam().getTeamUpgrades();
teamUpgrades.giveTeamArmor(this.player);
ItemBuilder itemBuilder = new ItemBuilder(Material.WOOD_SWORD).addUnbreakable();
if (playerCurrentGameData.getLevelForUpgrade(Upgrade.SHARPENED_SWORDS) == 1) {
if (teamUpgrades.getLevelForUpgrade(Upgrade.SHARPENED_SWORDS) == 1) {
itemBuilder.enchantment(Enchantment.DAMAGE_ALL, 1);
}
if (playerCurrentGameData.getLevelForUpgrade(Upgrade.MANIAC_MINER) != 0) {
this.player.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, 1000000, playerCurrentGameData.getLevelForUpgrade(Upgrade.MANIAC_MINER)));
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());

View File

@ -5,7 +5,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import rip.tilly.bedwars.game.Game;
import rip.tilly.bedwars.game.GameTeam;
import rip.tilly.bedwars.playerdata.currentgame.PlayerCurrentGameData;
import rip.tilly.bedwars.playerdata.currentgame.TeamUpgrades;
import rip.tilly.bedwars.utils.CC;
import rip.tilly.bedwars.utils.ItemBuilder;
@ -31,8 +31,8 @@ public class UpgradeItem {
this.upgrade = upgrade;
}
public ItemStack getItemStack(Player player, PlayerCurrentGameData playerCurrentGameData) {
int level = playerCurrentGameData.getLevelForUpgrade(this.upgrade);
public ItemStack getItemStack(Player player, TeamUpgrades teamUpgrades) {
int level = teamUpgrades.getLevelForUpgrade(this.upgrade);
ItemBuilder itemBuilder = new ItemBuilder(this.material, Math.min(level + 1, this.upgrade.getHighestLevel()));
itemBuilder.name(CC.translate("&e" + this.name + " " + this.upgrade.getNumberToRomanNumeral(Math.min(level + 1, this.upgrade.getHighestLevel()))));
@ -54,7 +54,7 @@ public class UpgradeItem {
lore.add(CC.translate(""));
if (playerCurrentGameData.getCostToUpgrade(this.upgrade) != -1) {
if (teamUpgrades.getCostToUpgrade(this.upgrade) != -1) {
if (this.canBuy(player, level + 1)) {
lore.add(CC.translate("&aClick to purchase"));
} else {
@ -69,7 +69,7 @@ public class UpgradeItem {
return itemBuilder.build();
}
public void buy(Player player, int level, Game game, GameTeam gameTeam, PlayerCurrentGameData playerCurrentGameData) {
public void buy(Player player, int level, Game game, GameTeam gameTeam, TeamUpgrades teamUpgrades) {
if (!this.canBuy(player, level)) {
return;
}
@ -97,7 +97,7 @@ public class UpgradeItem {
}
}
playerCurrentGameData.upgrade(player, game, gameTeam, this.upgrade);
teamUpgrades.upgrade(player, game, gameTeam, this.upgrade);
}
public boolean canBuy(Player player, int level) {

View File

@ -7,12 +7,13 @@ import rip.tilly.bedwars.BedWars;
import rip.tilly.bedwars.game.Game;
import rip.tilly.bedwars.game.GameTeam;
import rip.tilly.bedwars.playerdata.PlayerData;
import rip.tilly.bedwars.playerdata.currentgame.PlayerCurrentGameData;
import rip.tilly.bedwars.playerdata.currentgame.TeamUpgrades;
import rip.tilly.bedwars.upgrades.Upgrade;
import rip.tilly.bedwars.upgrades.UpgradeItem;
import rip.tilly.bedwars.utils.CC;
import rip.tilly.bedwars.utils.menusystem.Menu;
import rip.tilly.bedwars.utils.menusystem.PlayerMenuUtil;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
@ -51,7 +52,7 @@ public class UpgradesMenu extends Menu {
PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId());
PlayerCurrentGameData playerCurrentGameData = playerData.getCurrentGameData();
TeamUpgrades teamUpgrades = playerData.getPlayerTeam().getTeamUpgrades();
Game game = this.main.getGameManager().getGame(player.getUniqueId());
@ -63,22 +64,22 @@ public class UpgradesMenu extends Menu {
if (event.getView().getTitle().equalsIgnoreCase(CC.translate("&eUpgrades Menu"))) {
for (UpgradeItem upgradeItem : this.upgradeItems) {
if (upgradeItem.getItemStack(player, playerCurrentGameData).getItemMeta().getDisplayName().equalsIgnoreCase(event.getCurrentItem().getItemMeta().getDisplayName())) {
if (playerCurrentGameData.getCostToUpgrade(upgradeItem.getUpgrade()) == -1) {
if (upgradeItem.getItemStack(player, teamUpgrades).getItemMeta().getDisplayName().equalsIgnoreCase(event.getCurrentItem().getItemMeta().getDisplayName())) {
if (teamUpgrades.getCostToUpgrade(upgradeItem.getUpgrade()) == -1) {
player.sendMessage(CC.translate("&cYour team already has the highest upgrade for &c&l" + upgradeItem.getUpgrade().getFormattedName()));
return;
}
if (upgradeItem.canBuy(player, playerCurrentGameData.getLevelForUpgrade(upgradeItem.getUpgrade()) + 1)) {
upgradeItem.buy(player, playerCurrentGameData.getLevelForUpgrade(upgradeItem.getUpgrade()) + 1, game, gameTeam, playerCurrentGameData);
if (upgradeItem.canBuy(player, teamUpgrades.getLevelForUpgrade(upgradeItem.getUpgrade()) + 1)) {
upgradeItem.buy(player, teamUpgrades.getLevelForUpgrade(upgradeItem.getUpgrade()) + 1, game, gameTeam, teamUpgrades);
new UpgradesMenu(this.main.getPlayerMenuUtil(player)).open(player);
break;
}
player.sendMessage(CC.translate("&cYou do not have enough diamonds for &c&l" + upgradeItem.getUpgrade().getFormattedName() + " " + upgradeItem.getUpgrade().getNumberToRomanNumeral(playerCurrentGameData.getLevelForUpgrade(upgradeItem.getUpgrade()) + 1)));
player.sendMessage(CC.translate("&cYou do not have enough diamonds for &c&l" + upgradeItem.getUpgrade().getFormattedName() + " " + upgradeItem.getUpgrade().getNumberToRomanNumeral(teamUpgrades.getLevelForUpgrade(upgradeItem.getUpgrade()) + 1)));
break;
}
@ -90,7 +91,7 @@ public class UpgradesMenu extends Menu {
public void setMenuItems(Player player) {
PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId());
PlayerCurrentGameData playerCurrentGameData = playerData.getCurrentGameData();
TeamUpgrades teamUpgrades = playerData.getPlayerTeam().getTeamUpgrades();
for (int i = 0; i < this.inventory.getSize(); i++) {
this.inventory.setItem(i, this.FILLER_GLASS);
@ -99,7 +100,7 @@ public class UpgradesMenu extends Menu {
AtomicInteger atomicInteger = new AtomicInteger(10);
this.upgradeItems.forEach(itemStack -> {
this.inventory.setItem(atomicInteger.get(), itemStack.getItemStack(player, playerCurrentGameData));
this.inventory.setItem(atomicInteger.get(), itemStack.getItemStack(player, teamUpgrades));
atomicInteger.addAndGet(1);
});