Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor refactoring & new twist #5

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -278,5 +278,11 @@
<version>1.0.8-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import me.gaagjescraft.network.team.manhunt.managers.world.WorldManager;
import me.gaagjescraft.network.team.manhunt.menus.*;
import me.gaagjescraft.network.team.manhunt.menus.handlers.RunnerTrackerMenuHandler;
import me.gaagjescraft.network.team.manhunt.menus.twist.ManhuntTwistVoteMenu;
import me.gaagjescraft.network.team.manhunt.utils.*;
import me.gaagjescraft.network.team.manhunt.utils.platform.OriginalPlatformUtils;
import me.gaagjescraft.network.team.manhunt.utils.platform.PlatformUtils;
Expand Down
71 changes: 49 additions & 22 deletions src/main/java/me/gaagjescraft/network/team/manhunt/games/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.chat.ComponentSerializer;
import org.bukkit.*;
import org.bukkit.advancement.Advancement;
import org.bukkit.entity.Player;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.security.SecureRandom;
import java.util.*;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;


public class Game {
Expand All @@ -34,7 +37,7 @@ public class Game {
private final String worldIdentifier;
private final List<GamePlayer> players;
private final List<UUID> spectators;
private GameSchematic schematic;
private final GameSchematic schematic;
private final GameScheduler scheduler;
private final RunnerTrackerMenu runnerTrackerMenu;
private boolean twistsAllowed;
Expand Down Expand Up @@ -102,7 +105,9 @@ public Game(Manhunt plugin, String id, boolean twistsAllowed, UUID host, int max
}

public static Game getGame(UUID worldId) {
for (Game g : games) if (g.getWorldIdentifier().equals(worldId.toString()) || (g.getHostUUID() != null && g.getHostUUID().equals(worldId))) return g;
for (Game g : games)
if (g.getWorldIdentifier().equals(worldId.toString()) || (g.getHostUUID() != null && g.getHostUUID().equals(worldId)))
return g;
return null;
}

Expand Down Expand Up @@ -190,6 +195,10 @@ public void setDragonDefeated(boolean dragonDefeated) {
}

public void start() {
this.maxPlayers = players.size() - ((int) players.stream()
.filter(gamePlayer -> gamePlayer.getPlayerType() == PlayerType.RUNNER)
.count());

this.status = GameStatus.STARTING;
this.timer = 0;
}
Expand Down Expand Up @@ -241,6 +250,7 @@ public boolean addPlayer(Player player) {
gamePlayer.setOnline(true);
if (spectators.contains(player.getUniqueId())) {
gamePlayer.setSpectating(true);
gamePlayer.prepareForSpectate();
// Verify players not invisible to spec
player.spigot().getHiddenPlayers().forEach(p -> {
if (!getPlayer(p).isSpectating()) {
Expand Down Expand Up @@ -293,6 +303,15 @@ public boolean addPlayer(Player player) {
this.getRunnerTeleporterMenu().update();
sendUpdate();
if (plugin.getTagUtils() != null) plugin.getTagUtils().updateTag(player);

// Revoke all advancements
var iterator = Bukkit.getServer().advancementIterator();
while (iterator.hasNext()) {
var progress = player.getAdvancementProgress(iterator.next());
for (String awardedCriterion : progress.getAwardedCriteria()) {
progress.revokeCriteria(awardedCriterion);
}
}
return true;
}

Expand Down Expand Up @@ -466,15 +485,16 @@ public void win() {
else if (s.contains("%third_killer%") && thirdKillerName == null) continue;

if (s.isEmpty() || s.trim().isEmpty()) player.sendMessage("");
else plugin.getUtil().sendCenteredMessage(player, Util.c(s.replaceAll("%winner%", winningTeam.name())
.replaceAll("%player%", player.getName())
.replaceAll("%first_killer%", firstKillerName == null ? "N/A" : firstKillerName)
.replaceAll("%second_killer%", secondKillerName == null ? "N/A" : secondKillerName)
.replaceAll("%third_killer%", thirdKillerName == null ? "N/A" : thirdKillerName)
.replaceAll("%first_killer_number%", firstKillerNumber + "")
.replaceAll("%second_killer_number%", secondKillerNumber + "")
.replaceAll("%third_killer_number%", thirdKillerNumber + "")
.replaceAll("%kills%", gp.getKills() + "")));
else
plugin.getUtil().sendCenteredMessage(player, Util.c(s.replaceAll("%winner%", winningTeam.name())
.replaceAll("%player%", player.getName())
.replaceAll("%first_killer%", firstKillerName == null ? "N/A" : firstKillerName)
.replaceAll("%second_killer%", secondKillerName == null ? "N/A" : secondKillerName)
.replaceAll("%third_killer%", thirdKillerName == null ? "N/A" : thirdKillerName)
.replaceAll("%first_killer_number%", firstKillerNumber + "")
.replaceAll("%second_killer_number%", secondKillerNumber + "")
.replaceAll("%third_killer_number%", thirdKillerNumber + "")
.replaceAll("%kills%", gp.getKills() + "")));
}

if (gp.getPlayerType() == winningTeam) {
Expand Down Expand Up @@ -544,6 +564,15 @@ public void delete() {
for (GamePlayer gp : players) {
Player p = Bukkit.getPlayer(gp.getUuid());
if (p != null) {
// Revoke all advancements
var iterator = Bukkit.getServer().advancementIterator();
while (iterator.hasNext()) {
var progress = p.getAdvancementProgress(iterator.next());
for (String awardedCriterion : progress.getAwardedCriteria()) {
progress.revokeCriteria(awardedCriterion);
}
}

if (!plugin.getCfg().bungeeMode) p.teleport(loc);
else {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
Expand All @@ -555,9 +584,13 @@ public void delete() {
p.setFlying(false);
p.setAllowFlight(false);

p.spigot().getHiddenPlayers().forEach(p1 -> p.showPlayer(plugin, p1));
p.spigot().getHiddenPlayers().stream()
.filter(Objects::nonNull)
.forEach(hidden -> p.showPlayer(plugin, hidden));

if (plugin.getTagUtils() != null) plugin.getTagUtils().updateTag(p);
if (plugin.getTagUtils() != null) {
plugin.getTagUtils().updateTag(p);
}
}
}
if (plugin.getCfg().bungeeMode) plugin.getBungeeMessenger().createGameEndedMessage(this);
Expand Down Expand Up @@ -586,9 +619,7 @@ public void delete() {
}

public void create() {
int random = ThreadLocalRandom.current().nextInt(plugin.getCfg().seeds.size());
long seed = plugin.getCfg().seeds.get(random);
this.seed = seed;
this.seed = ThreadLocalRandom.current().nextLong();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This removes the seed pre-selection system

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you are looking at one particular commit. It was later reverted.


World w = plugin.getWorldManager().create(seed, getWorldIdentifier(), World.Environment.NORMAL);

Expand Down Expand Up @@ -740,11 +771,11 @@ public World getWorld() {
return Bukkit.getWorld(getWorldIdentifier());
}

public World getNether(){
public World getNether() {
return Bukkit.getWorld(getWorldIdentifier() + "_nether");
}

public World getEnd(){
public World getEnd() {
return Bukkit.getWorld(getWorldIdentifier() + "_the_end");
}

Expand Down Expand Up @@ -864,10 +895,6 @@ public String getWorldIdentifier() {
return worldIdentifier;
}

public long getSeed() {
return seed;
}

public Manhunt getPlugin() {
return plugin;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ public void prepareForSpectate() {
assert player != null;
player.setInvisible(true);
reset(player, false);
player.setGameMode(GameMode.SURVIVAL);
player.setGameMode(GameMode.SPECTATOR);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This removes clickable items in hotbar as a spectator

player.setAllowFlight(true);
player.setFlying(true);
player.getInventory().setItem(4, plugin.getItemizer().MANHUNT_RUNNER_TRACKER);
Expand Down Expand Up @@ -621,10 +621,11 @@ public void updateScoreboard() {
line = line.replaceAll("%color%", getColor());
line = line.replaceAll("%winner%", game.getWinningTeam() == null ? "null" : game.getWinningTeam().name());
line = line.replaceAll("%lives%", getMaxLives() < 1 ? "unlimited" : Math.max(getMaxLives() - getDeaths(), 0) + "");
line = line.replaceAll("%hunters%", hunters + "");
line = line.replaceAll("%runners%", runners + "");
line = line.replaceAll("%alivehunters%", aliveHunters + "");
line = line.replaceAll("%aliverunners%", aliveRunners + "");
line = line.replaceAll("%hunters%", String.valueOf(hunters));
line = line.replaceAll("%runners%", String.valueOf(runners));
line = line.replaceAll("%alivehunters%", String.valueOf(aliveHunters));
line = line.replaceAll("%aliverunners%", String.valueOf(aliveRunners));
line = line.replaceAll("%spectators%", String.valueOf(game.getSpectators().size()));
line = line.replaceAll("%twist%", game.getSelectedTwist() == null ? "none" : game.getSelectedTwist().name());
line = line.replaceAll("%kills%", getKills() + "");
line = line.replaceAll("%maxplayers%", game.getMaxPlayers() + "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import me.gaagjescraft.network.team.manhunt.Manhunt;
import me.gaagjescraft.network.team.manhunt.utils.Util;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -32,9 +33,14 @@ public void start() {
@Override
public void run() {
for (GamePlayer gp : game.getOnlinePlayers(null)) {
if ((Bukkit.getPlayer(gp.getUuid()) != null)) {
Player player = Bukkit.getPlayer(gp.getUuid());
if (player != null) {
gp.updateScoreboard();
gp.getCompassTracker().updateCompass();

if (gp.isSpectating()) {
player.setGameMode(GameMode.SPECTATOR);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary at best, or at worst, admins can't change gamemode

}
}
}

Expand All @@ -43,7 +49,6 @@ public void run() {
if (w != null) w.setTime(6000);
}

// todo add automatic start for minimum amount of players.
if (game.getStatus() == GameStatus.STARTING) {
if (plugin.getCfg().debug) Bukkit.getLogger().severe("Starting the game now. (1)");
doStartingCountdown();
Expand Down Expand Up @@ -189,7 +194,12 @@ private void doHuntersReleaseCountdown() {

// announce time at 60s, 30s, 10s, <5s
int headstart = game.getHeadStart().getSeconds();
if ((headstart >= 120 && timer == headstart - 120) || (headstart >= 90 && timer == headstart - 90) || (headstart >= 60 && timer == headstart - 60) || (headstart >= 30 && timer == headstart - 30) || (headstart >= 10 && timer == headstart - 10) || (timer >= headstart - 5 && timer < headstart)) {
if ((headstart >= 120 && timer == headstart - 120)
|| (headstart >= 90 && timer == headstart - 90)
|| (headstart >= 60 && timer == headstart - 60)
|| (headstart >= 30 && timer == headstart - 30)
|| (headstart >= 10 && timer == headstart - 10)
|| (timer >= headstart - 5 && timer < headstart)) {
String time = plugin.getUtil().secondsToTimeString(headstart - timer, "string");
for (GamePlayer gp : online) {
Player p = Bukkit.getPlayer(gp.getUuid());
Expand Down Expand Up @@ -310,6 +320,29 @@ public void doEvent() {
game.setEventActive(false);
game.determineNextEventTime();
}, 400);
} else if (game.getSelectedTwist() == TwistVote.GET_HIGH) {
game.setEventActive(true);
for (GamePlayer onlinePlayer : game.getOnlinePlayers(null)) {
Player player = Bukkit.getPlayer(onlinePlayer.getUuid());
if (player == null) {
continue;
}

Location playerLocation = player.getLocation();
player.teleport(new Location(
game.getWorld(),
playerLocation.getX(),
game.getWorld().getHighestBlockYAt(playerLocation) + 1.5,
playerLocation.getZ()));

plugin.getUtil().sendTitle(player, Util.c(plugin.getCfg().twistGetHighTitle), 20, 50, 20);
player.sendMessage(Util.c(plugin.getCfg().twistGetHighMessage));
Bukkit.getScheduler().runTaskLater(plugin, () -> {
game.setEventActive(false);
game.determineNextEventTime();
}, 200);

}
} else if (game.getSelectedTwist() == TwistVote.BLINDNESS) {
game.setEventActive(true);
for (GamePlayer gp : game.getOnlinePlayers(null)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ public void setHeadstart(HeadstartType headstart, boolean announce) {
if (getGame() != null) {
getGame().setHeadStart(headstart);
if (announce) {
getGame().sendMessage(null, Util.c(plugin.getCfg().headstartChangeMessage.replaceAll("%time%", plugin.getUtil().secondsToTimeString(headstart.getSeconds(), "string")).replaceAll("%player%", host.getName())));
getGame().sendMessage(null, Util.c(
plugin.getCfg().headstartChangeMessage
.replaceAll("%time%", plugin.getUtil().secondsToTimeString(headstart.getSeconds(), "string"))
.replaceAll("%player%", host.getName())));
}
}
}
Expand All @@ -70,8 +73,13 @@ public void setAllowTwists(boolean allowTwists, boolean announce) {
for (GamePlayer gp : this.game.getPlayers()) {
gp.prepareForGame(GameStatus.WAITING);
}

if (announce) {
getGame().sendMessage(null, Util.c(this.allowTwists ? plugin.getCfg().toggleTwistsEnabledMessage : plugin.getCfg().toggleTwistsDisabledMessage).replaceAll("%player%", host.getName()));
getGame().sendMessage(null, Util.c(
this.allowTwists
? plugin.getCfg().toggleTwistsEnabledMessage
: plugin.getCfg().toggleTwistsDisabledMessage)
.replaceAll("%player%", host.getName()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public enum TwistVote {
BLINDNESS("random blindness"),
ACID_RAIN("acid rain"),
RANDOM_YEET("random yeets"),
GET_HIGH("get high"),
HARDCORE("hardcore");

private String displayName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import me.gaagjescraft.network.team.manhunt.Manhunt;
import org.bukkit.*;

import java.security.SecureRandom;

import static com.onarandombox.MultiverseCore.enums.AllowedPortalType.ALL;

public class MultiverseManager implements WorldManager {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

public class ManhuntGamesMenu implements Listener {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void openMenu(Player player) {
gui.setItem(i, plugin.getItemizer().FILL_ITEM);
}

gui.setItem(53, plugin.getItemizer().createItem(plugin.getCfg().mainMenuStoreMaterial, 1, Util.c(plugin.getCfg().mainMenuStoreDisplayname), plugin.getCfg().mainMenuStoreLore));
gui.setItem(53, plugin.getItemizer().FILL_ITEM);
Copy link
Collaborator

@TechnicallyCoded TechnicallyCoded Jul 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removes the main store menu item??

gui.setItem(49, plugin.getItemizer().CLOSE_ITEM);

player.openInventory(gui);
Expand Down
Loading