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 lombok.Getter;
import lombok.Setter;
import org.bukkit.Bukkit;
import net.minecraft.server.v1_8_R3.WorldServer;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
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;
import rip.tilly.bedwars.customvillager.CustomVillager;
import rip.tilly.bedwars.game.arena.Arena;
import rip.tilly.bedwars.game.arena.CopiedArena;
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.CustomLocation;
import rip.tilly.bedwars.utils.TimeUtils;
import java.util.*;
import java.util.List;
import java.util.stream.Stream;
@Getter
@ -38,6 +39,8 @@ public class Game {
private final Set<Integer> runnables = new HashSet<>();
private final Set<ItemStack> droppedItems = new ConcurrentSet<>();
private final Set<CustomVillager> villagers = new ConcurrentSet<>();
private final List<GameTeam> teams;
private final Arena arena;
private final GameType gameType;
@ -223,33 +226,33 @@ public class Game {
return false;
}
public void tick(int amount) {
public void tick(int amount, Game game) {
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;
}
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;
}
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;
}
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;
}
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;
}
@ -281,21 +284,28 @@ public class Game {
return seconds / 60D;
}
public void spawnVillagers() {
Villager teamAShopVillager = this.arena.getTeamAshop().toBukkitLocation().getWorld().spawn(this.arena.getTeamAshop().toBukkitLocation(), Villager.class);
teamAShopVillager.setCustomName(CC.translate("&aItem Shop"));
teamAShopVillager.setCustomNameVisible(true);
public void spawnVillagers(CopiedArena copiedArena) {
Location teamAshopLoc = copiedArena.getTeamAshop().toBukkitLocation();
WorldServer worldServer = ((CraftWorld) teamAshopLoc.getWorld()).getHandle();
Villager teamBShopVillager = this.arena.getTeamBshop().toBukkitLocation().getWorld().spawn(this.arena.getTeamBshop().toBukkitLocation(), Villager.class);
teamBShopVillager.setCustomName(CC.translate("&aItem Shop"));
teamBShopVillager.setCustomNameVisible(true);
CustomVillager teamAshop = new CustomVillager(worldServer, "&aItem Shop");
teamAshop.setLocation(teamAshopLoc.getBlockX(), teamAshopLoc.getBlockY(), teamAshopLoc.getBlockZ(), teamAshopLoc.getYaw(), teamAshopLoc.getPitch());
Villager teamAUpgradesVillager = this.arena.getTeamAupgrades().toBukkitLocation().getWorld().spawn(this.arena.getTeamAupgrades().toBukkitLocation(), Villager.class);
teamAUpgradesVillager.setCustomName(CC.translate("&aUpgrades Shop"));
teamAUpgradesVillager.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 teamBUpgradesVillager = this.arena.getTeamBupgrades().toBukkitLocation().getWorld().spawn(this.arena.getTeamBupgrades().toBukkitLocation(), Villager.class);
teamBUpgradesVillager.setCustomName(CC.translate("&aUpgrades Shop"));
teamBUpgradesVillager.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());
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
public void onCreatureSpawn(CreatureSpawnEvent event) {
if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.CUSTOM) {
return;
}
if (event.getEntity().getType() != EntityType.ARMOR_STAND && event.getEntity().getType() != EntityType.VILLAGER) {
event.setCancelled(true);
}

View File

@ -4,6 +4,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.github.paperspigot.Title;
import rip.tilly.bedwars.BedWars;
import rip.tilly.bedwars.customvillager.CustomVillager;
import rip.tilly.bedwars.events.GameEndEvent;
import rip.tilly.bedwars.game.Game;
import rip.tilly.bedwars.game.GameState;
@ -55,5 +56,9 @@ public class GameEndListener implements Listener {
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.spawnVillagers();
game.spawnVillagers(game.getCopiedArena());
Set<Player> gamePlayers = new HashSet<>();
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(" ");
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(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("&dtilly.rip");
lines.add(CC.scoreboardBar);

View File

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