This commit is contained in:
Luca 2021-11-23 19:06:20 +01:00
parent 9209b3e5cc
commit c63f42afd9
7 changed files with 93 additions and 26 deletions

View File

@ -0,0 +1,46 @@
package rip.tilly.bedwars.customvillager;
import net.minecraft.server.v1_8_R3.DamageSource;
import net.minecraft.server.v1_8_R3.EntityVillager;
import net.minecraft.server.v1_8_R3.NBTTagCompound;
import net.minecraft.server.v1_8_R3.World;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftVillager;
import org.bukkit.event.entity.CreatureSpawnEvent;
import rip.tilly.bedwars.utils.CC;
public class CustomVillager extends EntityVillager {
public CustomVillager(World world, String name) {
super(world);
this.setCustomName(CC.translate(name));
this.setCustomNameVisible(true);
this.noMove();
this.setInvisible(false);
((CraftVillager) this.getBukkitEntity()).getHandle().setInvisible(false);
this.world.addEntity(this, CreatureSpawnEvent.SpawnReason.CUSTOM);
}
public void noMove() {
NBTTagCompound tag = this.getNBTTag();
if(tag == null) {
tag = new NBTTagCompound();
}
this.c(tag);
tag.setInt("NoAI", 1);
this.f(tag);
}
@Override
public void makeSound(String s, float f, float f1) {
return;
}
@Override
public boolean damageEntity(DamageSource source, float f) {
return false;
}
}

View File

@ -3,17 +3,18 @@ package rip.tilly.bedwars.game;
import io.netty.util.internal.ConcurrentSet; import io.netty.util.internal.ConcurrentSet;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.bukkit.Bukkit; import net.minecraft.server.v1_8_R3.WorldServer;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.block.Block; import org.bukkit.block.Block;
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;
import rip.tilly.bedwars.customvillager.CustomVillager;
import rip.tilly.bedwars.game.arena.Arena; import rip.tilly.bedwars.game.arena.Arena;
import rip.tilly.bedwars.game.arena.CopiedArena; import rip.tilly.bedwars.game.arena.CopiedArena;
import rip.tilly.bedwars.generators.Generator; import rip.tilly.bedwars.generators.Generator;
@ -22,8 +23,8 @@ import rip.tilly.bedwars.generators.GeneratorType;
import rip.tilly.bedwars.utils.CC; import rip.tilly.bedwars.utils.CC;
import rip.tilly.bedwars.utils.CustomLocation; import rip.tilly.bedwars.utils.CustomLocation;
import rip.tilly.bedwars.utils.TimeUtils; import rip.tilly.bedwars.utils.TimeUtils;
import java.util.*; import java.util.*;
import java.util.List;
import java.util.stream.Stream; import java.util.stream.Stream;
@Getter @Getter
@ -38,6 +39,8 @@ 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;
@ -223,33 +226,33 @@ public class Game {
return false; return false;
} }
public void tick(int amount) { public void tick(int amount, Game game) {
if (this.secondsToMinutes(amount) == 5D) { if (this.secondsToMinutes(amount) == 5D) {
Bukkit.broadcastMessage(CC.translate("&bDiamond &egenerators have been upgraded to &bTier II")); game.broadcast("&bDiamond &egenerators have been upgraded to &bTier II&e.");
this.diamondGeneratorTier = GeneratorTier.TWO; this.diamondGeneratorTier = GeneratorTier.TWO;
} }
if (this.secondsToMinutes(amount) == 8D) { if (this.secondsToMinutes(amount) == 8D) {
Bukkit.broadcastMessage(CC.translate("&aEmerald &egenerators have been upgraded to &bTier II")); game.broadcast("&aEmerald &egenerators have been upgraded to &bTier II&e.");
this.emeraldGeneratorTier = GeneratorTier.TWO; this.emeraldGeneratorTier = GeneratorTier.TWO;
} }
if (this.secondsToMinutes(amount) == 10D) { if (this.secondsToMinutes(amount) == 10D) {
Bukkit.broadcastMessage(CC.translate("&bDiamond &egenerators have been upgraded to &bTier II")); game.broadcast("&bDiamond &egenerators have been upgraded to &bTier III&e.");
this.diamondGeneratorTier = GeneratorTier.THREE; this.diamondGeneratorTier = GeneratorTier.THREE;
} }
if (this.secondsToMinutes(amount) == 12D) { if (this.secondsToMinutes(amount) == 12D) {
Bukkit.broadcastMessage(CC.translate("&aEmerald &egenerators have been upgraded to &bTier II")); game.broadcast("&aEmerald &egenerators have been upgraded to &bTier III&e.");
this.emeraldGeneratorTier = GeneratorTier.THREE; this.emeraldGeneratorTier = GeneratorTier.THREE;
} }
if (this.secondsToMinutes(amount) == 15D) { if (this.secondsToMinutes(amount) == 15D) {
Bukkit.broadcastMessage(CC.translate("&bDiamond &egenerators have been upgraded to &bTier II")); game.broadcast("&bDiamond &egenerators have been upgraded to &bTier IV&e.");
this.diamondGeneratorTier = GeneratorTier.FOUR; this.diamondGeneratorTier = GeneratorTier.FOUR;
} }
@ -281,21 +284,28 @@ public class Game {
return seconds / 60D; return seconds / 60D;
} }
public void spawnVillagers() { public void spawnVillagers(CopiedArena copiedArena) {
Villager teamAShopVillager = this.arena.getTeamAshop().toBukkitLocation().getWorld().spawn(this.arena.getTeamAshop().toBukkitLocation(), Villager.class); Location teamAshopLoc = copiedArena.getTeamAshop().toBukkitLocation();
teamAShopVillager.setCustomName(CC.translate("&aItem Shop")); WorldServer worldServer = ((CraftWorld) teamAshopLoc.getWorld()).getHandle();
teamAShopVillager.setCustomNameVisible(true);
Villager teamBShopVillager = this.arena.getTeamBshop().toBukkitLocation().getWorld().spawn(this.arena.getTeamBshop().toBukkitLocation(), Villager.class); CustomVillager teamAshop = new CustomVillager(worldServer, "&aItem Shop");
teamBShopVillager.setCustomName(CC.translate("&aItem Shop")); teamAshop.setLocation(teamAshopLoc.getBlockX(), teamAshopLoc.getBlockY(), teamAshopLoc.getBlockZ(), teamAshopLoc.getYaw(), teamAshopLoc.getPitch());
teamBShopVillager.setCustomNameVisible(true);
Villager teamAUpgradesVillager = this.arena.getTeamAupgrades().toBukkitLocation().getWorld().spawn(this.arena.getTeamAupgrades().toBukkitLocation(), Villager.class); Location teamBshopLoc = copiedArena.getTeamBshop().toBukkitLocation();
teamAUpgradesVillager.setCustomName(CC.translate("&aUpgrades Shop")); CustomVillager teamBshop = new CustomVillager(worldServer, "&aItem Shop");
teamAUpgradesVillager.setCustomNameVisible(true); teamBshop.setLocation(teamBshopLoc.getBlockX(), teamBshopLoc.getBlockY(), teamBshopLoc.getBlockZ(), teamBshopLoc.getYaw(), teamBshopLoc.getPitch());
Villager teamBUpgradesVillager = this.arena.getTeamBupgrades().toBukkitLocation().getWorld().spawn(this.arena.getTeamBupgrades().toBukkitLocation(), Villager.class); Location teamAupgradeLoc = copiedArena.getTeamAupgrades().toBukkitLocation();
teamBUpgradesVillager.setCustomName(CC.translate("&aUpgrades Shop")); CustomVillager teamAupgrade = new CustomVillager(worldServer, "&aUpgrades Shop");
teamBUpgradesVillager.setCustomNameVisible(true); teamAupgrade.setLocation(teamAupgradeLoc.getBlockX(), teamAupgradeLoc.getBlockY(), teamAupgradeLoc.getBlockZ(), teamAupgradeLoc.getYaw(), teamAupgradeLoc.getPitch());
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);
} }
} }

View File

@ -74,6 +74,10 @@ public class RandomListeners implements Listener {
@EventHandler @EventHandler
public void onCreatureSpawn(CreatureSpawnEvent event) { public void onCreatureSpawn(CreatureSpawnEvent event) {
if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.CUSTOM) {
return;
}
if (event.getEntity().getType() != EntityType.ARMOR_STAND && event.getEntity().getType() != EntityType.VILLAGER) { if (event.getEntity().getType() != EntityType.ARMOR_STAND && event.getEntity().getType() != EntityType.VILLAGER) {
event.setCancelled(true); event.setCancelled(true);
} }

View File

@ -4,6 +4,7 @@ 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;
import rip.tilly.bedwars.BedWars; import rip.tilly.bedwars.BedWars;
import rip.tilly.bedwars.customvillager.CustomVillager;
import rip.tilly.bedwars.events.GameEndEvent; import rip.tilly.bedwars.events.GameEndEvent;
import rip.tilly.bedwars.game.Game; import rip.tilly.bedwars.game.Game;
import rip.tilly.bedwars.game.GameState; import rip.tilly.bedwars.game.GameState;
@ -55,5 +56,9 @@ public class GameEndListener implements Listener {
playerData.setGamesPlayed(playerData.getGamesPlayed() + 1); playerData.setGamesPlayed(playerData.getGamesPlayed() + 1);
})); }));
for (CustomVillager villager : game.getVillagers()) {
villager.die();
}
} }
} }

View File

@ -65,7 +65,7 @@ public class GameStartListener implements Listener {
game.getActivatedGenerators().add(emeGen); game.getActivatedGenerators().add(emeGen);
} }
game.spawnVillagers(); game.spawnVillagers(game.getCopiedArena());
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 -> {

View File

@ -266,9 +266,11 @@ public class ScoreboardProvider implements BoardAdapter {
lines.add("&7[" + opposingTeam.getPlayerTeam().getChatColor() + opposingTeam.getPlayerTeam().getSmallName() + "&7] &c&l✗"); lines.add("&7[" + opposingTeam.getPlayerTeam().getChatColor() + opposingTeam.getPlayerTeam().getSmallName() + "&7] &c&l✗");
} }
lines.add(" "); lines.add(" ");
lines.add(yourTeam.getPlayerTeam().getChatColor() + yourTeam.playingPlayers().collect(Collectors.toList()).get(0).getName()); Player teamAplayer = yourTeam.playingPlayers().collect(Collectors.toList()).get(0);
lines.add(yourTeam.getPlayerTeam().getChatColor() + (teamAplayer != null ? teamAplayer.getName() : "None"));
lines.add("&7VS"); lines.add("&7VS");
lines.add(opposingTeam.getPlayerTeam().getChatColor() + opposingTeam.playingPlayers().collect(Collectors.toList()).get(0).getName()); Player teamBplayer = opposingTeam.playingPlayers().collect(Collectors.toList()).get(0);
lines.add(opposingTeam.getPlayerTeam().getChatColor() + (teamBplayer != null ? teamBplayer.getName() : "None"));
lines.add(" "); lines.add(" ");
lines.add("&dtilly.rip"); lines.add("&dtilly.rip");
lines.add(CC.scoreboardBar); lines.add(CC.scoreboardBar);

View File

@ -35,7 +35,7 @@ public class GameRunnable extends BukkitRunnable {
case FIGHTING: case FIGHTING:
this.amount++; this.amount++;
this.game.incrementDuration(); this.game.incrementDuration();
this.game.tick(this.amount); this.game.tick(this.amount, this.game);
break; break;
case ENDING: case ENDING: