From e92e1ea23faaf4987c38fa1d21e63dd118a3f591 Mon Sep 17 00:00:00 2001 From: Luca Date: Tue, 23 Nov 2021 19:17:19 +0100 Subject: [PATCH] e --- .../java/rip/tilly/bedwars/game/Game.java | 39 +++++++++---------- .../listeners/game/GameEndListener.java | 5 ++- .../listeners/game/GameStartListener.java | 2 +- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/main/java/rip/tilly/bedwars/game/Game.java b/src/main/java/rip/tilly/bedwars/game/Game.java index 9492921..cb58f4a 100644 --- a/src/main/java/rip/tilly/bedwars/game/Game.java +++ b/src/main/java/rip/tilly/bedwars/game/Game.java @@ -11,6 +11,7 @@ import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; +import org.bukkit.entity.Villager; import org.bukkit.inventory.ItemStack; import org.github.paperspigot.Title; import rip.tilly.bedwars.BedWars; @@ -39,8 +40,6 @@ public class Game { private final Set runnables = new HashSet<>(); private final Set droppedItems = new ConcurrentSet<>(); - private final Set villagers = new ConcurrentSet<>(); - private final List teams; private final Arena arena; private final GameType gameType; @@ -284,28 +283,26 @@ public class Game { return seconds / 60D; } - public void spawnVillagers(CopiedArena copiedArena) { - Location teamAshopLoc = copiedArena.getTeamAshop().toBukkitLocation(); - WorldServer worldServer = ((CraftWorld) teamAshopLoc.getWorld()).getHandle(); + public void spawnVillagers() { + Villager teamAShopVillager = this.copiedArena.getTeamAshop().toBukkitLocation().getWorld().spawn(this.copiedArena.getTeamAshop().toBukkitLocation(), Villager.class); + teamAShopVillager.setCustomName(CC.translate("&aItem Shop")); + teamAShopVillager.setCustomNameVisible(true); - CustomVillager teamAshop = new CustomVillager(worldServer, "&aItem Shop"); - teamAshop.setLocation(teamAshopLoc.getBlockX(), teamAshopLoc.getBlockY(), teamAshopLoc.getBlockZ(), teamAshopLoc.getYaw(), teamAshopLoc.getPitch()); + Villager teamBShopVillager = this.copiedArena.getTeamBshop().toBukkitLocation().getWorld().spawn(this.copiedArena.getTeamBshop().toBukkitLocation(), Villager.class); + teamBShopVillager.setCustomName(CC.translate("&aItem Shop")); + teamBShopVillager.setCustomNameVisible(true); - Location teamBshopLoc = copiedArena.getTeamBshop().toBukkitLocation(); - CustomVillager teamBshop = new CustomVillager(worldServer, "&aItem Shop"); - teamBshop.setLocation(teamBshopLoc.getBlockX(), teamBshopLoc.getBlockY(), teamBshopLoc.getBlockZ(), teamBshopLoc.getYaw(), teamBshopLoc.getPitch()); + Villager teamAUpgradesVillager = this.copiedArena.getTeamAupgrades().toBukkitLocation().getWorld().spawn(this.copiedArena.getTeamAupgrades().toBukkitLocation(), Villager.class); + teamAUpgradesVillager.setCustomName(CC.translate("&aUpgrades Shop")); + teamAUpgradesVillager.setCustomNameVisible(true); - Location teamAupgradeLoc = copiedArena.getTeamAupgrades().toBukkitLocation(); - CustomVillager teamAupgrade = new CustomVillager(worldServer, "&aUpgrades Shop"); - teamAupgrade.setLocation(teamAupgradeLoc.getBlockX(), teamAupgradeLoc.getBlockY(), teamAupgradeLoc.getBlockZ(), teamAupgradeLoc.getYaw(), teamAupgradeLoc.getPitch()); + Villager teamBUpgradesVillager = this.copiedArena.getTeamBupgrades().toBukkitLocation().getWorld().spawn(this.copiedArena.getTeamBupgrades().toBukkitLocation(), Villager.class); + teamBUpgradesVillager.setCustomName(CC.translate("&aUpgrades Shop")); + teamBUpgradesVillager.setCustomNameVisible(true); - Location teamBupgradeLoc = copiedArena.getTeamAupgrades().toBukkitLocation(); - CustomVillager teamBupgrade = new CustomVillager(worldServer, "&aUpgrades Shop"); - teamBupgrade.setLocation(teamBupgradeLoc.getBlockX(), teamBupgradeLoc.getBlockY(), teamBupgradeLoc.getBlockZ(), teamBupgradeLoc.getYaw(), teamBupgradeLoc.getPitch()); - - this.villagers.add(teamAshop); - this.villagers.add(teamBshop); - this.villagers.add(teamAupgrade); - this.villagers.add(teamBupgrade); + this.addEntityToRemove(teamAShopVillager); + this.addEntityToRemove(teamBShopVillager); + this.addEntityToRemove(teamAUpgradesVillager); + this.addEntityToRemove(teamBUpgradesVillager); } } diff --git a/src/main/java/rip/tilly/bedwars/listeners/game/GameEndListener.java b/src/main/java/rip/tilly/bedwars/listeners/game/GameEndListener.java index 687055e..8882488 100644 --- a/src/main/java/rip/tilly/bedwars/listeners/game/GameEndListener.java +++ b/src/main/java/rip/tilly/bedwars/listeners/game/GameEndListener.java @@ -1,5 +1,6 @@ package rip.tilly.bedwars.listeners.game; +import org.bukkit.entity.Entity; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.github.paperspigot.Title; @@ -57,8 +58,8 @@ public class GameEndListener implements Listener { playerData.setGamesPlayed(playerData.getGamesPlayed() + 1); })); - for (CustomVillager villager : game.getVillagers()) { - villager.die(); + for (Entity entity : game.getEntitiesToRemove()) { + entity.remove(); } } } diff --git a/src/main/java/rip/tilly/bedwars/listeners/game/GameStartListener.java b/src/main/java/rip/tilly/bedwars/listeners/game/GameStartListener.java index cea8b95..205cf6a 100644 --- a/src/main/java/rip/tilly/bedwars/listeners/game/GameStartListener.java +++ b/src/main/java/rip/tilly/bedwars/listeners/game/GameStartListener.java @@ -65,7 +65,7 @@ public class GameStartListener implements Listener { game.getActivatedGenerators().add(emeGen); } - game.spawnVillagers(game.getCopiedArena()); + game.spawnVillagers(); Set gamePlayers = new HashSet<>(); game.getTeams().forEach(team -> team.playingPlayers().forEach(player -> {