This commit is contained in:
Luca 2021-11-23 19:17:19 +01:00
parent a0a1e79138
commit e92e1ea23f
3 changed files with 22 additions and 24 deletions

View File

@ -11,6 +11,7 @@ import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Villager;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.github.paperspigot.Title; import org.github.paperspigot.Title;
import rip.tilly.bedwars.BedWars; import rip.tilly.bedwars.BedWars;
@ -39,8 +40,6 @@ public class Game {
private final Set<Integer> runnables = new HashSet<>(); private final Set<Integer> runnables = new HashSet<>();
private final Set<ItemStack> droppedItems = new ConcurrentSet<>(); private final Set<ItemStack> droppedItems = new ConcurrentSet<>();
private final Set<CustomVillager> villagers = new ConcurrentSet<>();
private final List<GameTeam> teams; private final List<GameTeam> teams;
private final Arena arena; private final Arena arena;
private final GameType gameType; private final GameType gameType;
@ -284,28 +283,26 @@ public class Game {
return seconds / 60D; return seconds / 60D;
} }
public void spawnVillagers(CopiedArena copiedArena) { public void spawnVillagers() {
Location teamAshopLoc = copiedArena.getTeamAshop().toBukkitLocation(); Villager teamAShopVillager = this.copiedArena.getTeamAshop().toBukkitLocation().getWorld().spawn(this.copiedArena.getTeamAshop().toBukkitLocation(), Villager.class);
WorldServer worldServer = ((CraftWorld) teamAshopLoc.getWorld()).getHandle(); teamAShopVillager.setCustomName(CC.translate("&aItem Shop"));
teamAShopVillager.setCustomNameVisible(true);
CustomVillager teamAshop = new CustomVillager(worldServer, "&aItem Shop"); Villager teamBShopVillager = this.copiedArena.getTeamBshop().toBukkitLocation().getWorld().spawn(this.copiedArena.getTeamBshop().toBukkitLocation(), Villager.class);
teamAshop.setLocation(teamAshopLoc.getBlockX(), teamAshopLoc.getBlockY(), teamAshopLoc.getBlockZ(), teamAshopLoc.getYaw(), teamAshopLoc.getPitch()); teamBShopVillager.setCustomName(CC.translate("&aItem Shop"));
teamBShopVillager.setCustomNameVisible(true);
Location teamBshopLoc = copiedArena.getTeamBshop().toBukkitLocation(); Villager teamAUpgradesVillager = this.copiedArena.getTeamAupgrades().toBukkitLocation().getWorld().spawn(this.copiedArena.getTeamAupgrades().toBukkitLocation(), Villager.class);
CustomVillager teamBshop = new CustomVillager(worldServer, "&aItem Shop"); teamAUpgradesVillager.setCustomName(CC.translate("&aUpgrades Shop"));
teamBshop.setLocation(teamBshopLoc.getBlockX(), teamBshopLoc.getBlockY(), teamBshopLoc.getBlockZ(), teamBshopLoc.getYaw(), teamBshopLoc.getPitch()); teamAUpgradesVillager.setCustomNameVisible(true);
Location teamAupgradeLoc = copiedArena.getTeamAupgrades().toBukkitLocation(); Villager teamBUpgradesVillager = this.copiedArena.getTeamBupgrades().toBukkitLocation().getWorld().spawn(this.copiedArena.getTeamBupgrades().toBukkitLocation(), Villager.class);
CustomVillager teamAupgrade = new CustomVillager(worldServer, "&aUpgrades Shop"); teamBUpgradesVillager.setCustomName(CC.translate("&aUpgrades Shop"));
teamAupgrade.setLocation(teamAupgradeLoc.getBlockX(), teamAupgradeLoc.getBlockY(), teamAupgradeLoc.getBlockZ(), teamAupgradeLoc.getYaw(), teamAupgradeLoc.getPitch()); teamBUpgradesVillager.setCustomNameVisible(true);
Location teamBupgradeLoc = copiedArena.getTeamAupgrades().toBukkitLocation(); this.addEntityToRemove(teamAShopVillager);
CustomVillager teamBupgrade = new CustomVillager(worldServer, "&aUpgrades Shop"); this.addEntityToRemove(teamBShopVillager);
teamBupgrade.setLocation(teamBupgradeLoc.getBlockX(), teamBupgradeLoc.getBlockY(), teamBupgradeLoc.getBlockZ(), teamBupgradeLoc.getYaw(), teamBupgradeLoc.getPitch()); this.addEntityToRemove(teamAUpgradesVillager);
this.addEntityToRemove(teamBUpgradesVillager);
this.villagers.add(teamAshop);
this.villagers.add(teamBshop);
this.villagers.add(teamAupgrade);
this.villagers.add(teamBupgrade);
} }
} }

View File

@ -1,5 +1,6 @@
package rip.tilly.bedwars.listeners.game; package rip.tilly.bedwars.listeners.game;
import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.github.paperspigot.Title; import org.github.paperspigot.Title;
@ -57,8 +58,8 @@ public class GameEndListener implements Listener {
playerData.setGamesPlayed(playerData.getGamesPlayed() + 1); playerData.setGamesPlayed(playerData.getGamesPlayed() + 1);
})); }));
for (CustomVillager villager : game.getVillagers()) { for (Entity entity : game.getEntitiesToRemove()) {
villager.die(); entity.remove();
} }
} }
} }

View File

@ -65,7 +65,7 @@ public class GameStartListener implements Listener {
game.getActivatedGenerators().add(emeGen); game.getActivatedGenerators().add(emeGen);
} }
game.spawnVillagers(game.getCopiedArena()); game.spawnVillagers();
Set<Player> gamePlayers = new HashSet<>(); Set<Player> gamePlayers = new HashSet<>();
game.getTeams().forEach(team -> team.playingPlayers().forEach(player -> { game.getTeams().forEach(team -> team.playingPlayers().forEach(player -> {