Initial commit
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>ProjectCranked</artifactId>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
<version>1.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>Tournaments</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<artifactId>Utils</artifactId>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>Teams</artifactId>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
<artifactId>Enchants</artifactId>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
<artifactId>StarItems</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
<artifactId>AdminWeapons</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
<artifactId>Masks</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
<artifactId>Lootboxes</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
<artifactId>Armor</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
<artifactId>StorageUtilsShaded</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/../StorageUtils/target/StorageUtils-1.0-shaded.jar</systemPath>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,44 @@
|
||||
package net.crankedpvp.tournaments;
|
||||
|
||||
import net.crankedpvp.crankedutils.utils.InventoryUtils;
|
||||
import net.crankedpvp.tournaments.managers.TournamentManager;
|
||||
import net.crankedpvp.tournaments.struct.TournamentMatch;
|
||||
import net.crankedpvp.tournaments.struct.TournamentPlayer;
|
||||
import net.crankedpvp.tournaments.struct.TournamentTeam;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class TournamentsAPI {
|
||||
|
||||
private static TournamentManager tournamentManager = TournamentsPlugin.getInstance().getTournamentManager();
|
||||
|
||||
public static void clearInventory(Player player) {
|
||||
InventoryUtils.clearInventory(player);
|
||||
}
|
||||
|
||||
public static TournamentTeam getTournamentTeamFromPlayer(Player player) {
|
||||
for(TournamentTeam tournamentTeam : tournamentManager.getTournamentParticipants()) {
|
||||
for(TournamentPlayer tournamentPlayer : tournamentTeam.getAllPlayers()) {
|
||||
if(tournamentPlayer.getPlayerUUID().equals(player.getUniqueId())) return tournamentTeam;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static boolean isPlayerInTournament(Player player) {
|
||||
for(TournamentTeam tournamentTeam : tournamentManager.getTournamentParticipants()) {
|
||||
if(tournamentTeam.getAllPlayersAsPlayers().contains(player)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static TournamentMatch findTournamentMatchFromPlayer(TournamentPlayer tournamentPlayer) {
|
||||
for(TournamentMatch tournamentMatch : tournamentManager.getTournamentMatchList()) {
|
||||
if(tournamentMatch.getTeamOne().containsPlayer(tournamentPlayer)) return tournamentMatch;
|
||||
if(tournamentMatch.getTeamTwo().containsPlayer(tournamentPlayer)) return tournamentMatch;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package net.crankedpvp.tournaments;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.mattstudios.mf.base.CommandManager;
|
||||
import net.crankedpvp.tournaments.commands.TournamentCommand;
|
||||
import net.crankedpvp.tournaments.listeners.DeathListener;
|
||||
import net.crankedpvp.tournaments.managers.ArenaManager;
|
||||
import net.crankedpvp.tournaments.managers.PlayerManager;
|
||||
import net.crankedpvp.tournaments.managers.TournamentManager;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class TournamentsPlugin extends JavaPlugin {
|
||||
|
||||
@Getter
|
||||
private static TournamentsPlugin instance;
|
||||
|
||||
@Getter
|
||||
private TournamentManager tournamentManager;
|
||||
|
||||
private CommandManager commandManager;
|
||||
|
||||
@Getter
|
||||
private PlayerManager playerManager;
|
||||
@Getter
|
||||
private ArenaManager arenaManager;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
|
||||
this.playerManager = new PlayerManager(this);
|
||||
this.arenaManager = new ArenaManager(this);
|
||||
this.playerManager.loadAll();
|
||||
this.arenaManager.loadAll();
|
||||
this.tournamentManager = new TournamentManager(this);
|
||||
this.commandManager = new CommandManager(this);
|
||||
this.commandManager.register(new TournamentCommand(this));
|
||||
this.registerListeners(this.getServer().getPluginManager());
|
||||
}
|
||||
|
||||
private void registerListeners(PluginManager pluginManager) {
|
||||
pluginManager.registerEvents(new DeathListener(this), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
this.playerManager.saveAll();
|
||||
this.arenaManager.saveAll();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
package net.crankedpvp.tournaments.commands;
|
||||
|
||||
import me.mattstudios.mf.annotations.*;
|
||||
import me.mattstudios.mf.base.CommandBase;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.crankedutils.utils.InventoryUtils;
|
||||
import net.crankedpvp.crankedutils.utils.SoundUtils;
|
||||
import net.crankedpvp.teams.TeamsAPI;
|
||||
import net.crankedpvp.tournaments.TournamentsAPI;
|
||||
import net.crankedpvp.tournaments.TournamentsPlugin;
|
||||
import net.crankedpvp.tournaments.constants.TournamentStatus;
|
||||
import net.crankedpvp.tournaments.struct.TournamentArena;
|
||||
import net.crankedpvp.tournaments.struct.TournamentPlayer;
|
||||
import net.crankedpvp.tournaments.struct.TournamentTeam;
|
||||
import net.crankedpvp.tournaments.tasks.TournamentStartTask;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Command("tournament")
|
||||
@Alias({"tm"})
|
||||
public class TournamentCommand extends CommandBase {
|
||||
|
||||
private TournamentStartTask tournamentStartTask;
|
||||
|
||||
private TournamentsPlugin plugin;
|
||||
public TournamentCommand(TournamentsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Default
|
||||
public void defaultCommand(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@SubCommand("start")
|
||||
@Permission("tournament.*")
|
||||
public void startTournamentCommand(CommandSender commandSender, @Optional Integer teamSize) {
|
||||
if(teamSize == null) teamSize = 1;
|
||||
|
||||
if(plugin.getTournamentManager().isActive()) {
|
||||
commandSender.sendMessage(CC.translate("&cThere is already an active tournament event"));
|
||||
SoundUtils.tryPlayErrorSound(commandSender);
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getTournamentManager().setTeamSize(teamSize);
|
||||
SoundUtils.playSoundIfPlayer(commandSender, Sound.ORB_PICKUP);
|
||||
plugin.getTournamentManager().setStatus(TournamentStatus.JOINABLE);
|
||||
this.tournamentStartTask = new TournamentStartTask(this.plugin);
|
||||
this.tournamentStartTask.runTaskTimer(this.plugin, 0L, 20L);
|
||||
commandSender.sendMessage(CC.translate("&aYou have successfully started a " + plugin.getTournamentManager().getTournamentTeamSizeFixedString() + " tournament"));
|
||||
}
|
||||
|
||||
@SubCommand("forceend")
|
||||
@Permission("tournament.*")
|
||||
public void endTournamentCommand(CommandSender commandSender) {
|
||||
if(!plugin.getTournamentManager().isActive()) {
|
||||
commandSender.sendMessage(CC.translate("&cThere is not an active tournament event"));
|
||||
SoundUtils.tryPlayErrorSound(commandSender);
|
||||
return;
|
||||
}
|
||||
plugin.getTournamentManager().end();
|
||||
this.tournamentStartTask.cancel();
|
||||
commandSender.sendMessage(CC.translate("&aYou have successfully ended a tournament"));
|
||||
SoundUtils.playSoundIfPlayer(commandSender, Sound.BAT_TAKEOFF);
|
||||
Bukkit.broadcastMessage(CC.translate("&cThe ongoing tournament event has been forcefully ended"));
|
||||
}
|
||||
|
||||
@SubCommand("join")
|
||||
public void joinTournamentCommand(Player player) {
|
||||
|
||||
if(TournamentsAPI.isPlayerInTournament(player)) {
|
||||
player.sendMessage(CC.translate("&cYou are already in this tournament!"));
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_LAND, 2.0F, 2.0F);
|
||||
return;
|
||||
}
|
||||
if(!plugin.getTournamentManager().isJoinable()) {
|
||||
player.sendMessage(CC.translate("&cNo tournament is running or the tournament is no longer joinable"));
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_LAND, 2.0F, 2.0F);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if(!InventoryUtils.isEmptyInventory(player)) {
|
||||
player.sendMessage(CC.translate("&cYou must have an empty inventory to join the tournament"));
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_LAND, 2.0F, 2.0F);
|
||||
return;
|
||||
}
|
||||
|
||||
if(plugin.getTournamentManager().getTeamSize() == 1) {
|
||||
if(TeamsAPI.hasTeam(player) && TeamsAPI.getTeamSize(player) > 1) {
|
||||
player.sendMessage(CC.translate("&cYou cannot have people in your team when joining a 1v1 tournament"));
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_LAND, 2.0F, 2.0F);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(plugin.getTournamentManager().getTeamSize() > 1) {
|
||||
if(!runTeamChecks(player)) return;
|
||||
}
|
||||
|
||||
|
||||
if(!TeamsAPI.hasTeam(player)) {
|
||||
TeamsAPI.createTeam(player);
|
||||
}
|
||||
|
||||
TournamentTeam tournamentTeam = new TournamentTeam(TeamsAPI.getTeamFromPlayer(player));
|
||||
if(plugin.getTournamentManager().getTournamentParticipants().contains(tournamentTeam)) {
|
||||
player.sendMessage(CC.translate("&cYou are already in the tournament"));
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_LAND, 2.0F, 2.0F);
|
||||
return;
|
||||
}
|
||||
this.finish(tournamentTeam);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void finish(TournamentTeam tournamentTeam) {
|
||||
|
||||
plugin.getTournamentManager().getTournamentParticipants().add(tournamentTeam);
|
||||
tournamentTeam.playSound(Sound.ORB_PICKUP);
|
||||
tournamentTeam.sendMessage("&aYou have successfully joined the tournament");
|
||||
tournamentTeam.teleport(this.plugin.getTournamentManager().getWaitingRoomLocation());
|
||||
}
|
||||
|
||||
private boolean runTeamChecks(Player player) {
|
||||
|
||||
if(!TeamsAPI.hasTeam(player)) {
|
||||
player.sendMessage(CC.translate("&cYou must have a team to join the tournament"));
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_LAND, 2.0F, 2.0F);
|
||||
return false;
|
||||
}
|
||||
|
||||
TournamentTeam tournamentTeam = new TournamentTeam(TeamsAPI.getTeamFromPlayer(player));
|
||||
|
||||
if(plugin.getTournamentManager().getTournamentParticipants().contains(tournamentTeam)) {
|
||||
player.sendMessage(CC.translate("&cYou are already in the tournament"));
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_LAND, 2.0F, 2.0F);
|
||||
return false;
|
||||
}
|
||||
|
||||
int maxPlayersInTeam = plugin.getTournamentManager().getTeamSize();
|
||||
if(tournamentTeam.getTeamSize() != maxPlayersInTeam) {
|
||||
player.sendMessage(CC.translate("&cYour team must only consist of " + maxPlayersInTeam + " players to join this tournament"));
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_LAND, 2.0F, 2.0F);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if(tournamentTeam.getLeader().getPlayer() != player) {
|
||||
player.sendMessage(CC.translate("&cYou must be the team leader to enter the tournament"));
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_LAND, 2.0F, 2.0F);
|
||||
return false;
|
||||
}
|
||||
|
||||
for(TournamentPlayer tournamentPlayer : tournamentTeam.getAllPlayers()) {
|
||||
if(!InventoryUtils.isEmptyInventory(tournamentPlayer.getPlayer())) {
|
||||
tournamentTeam.sendMessage("&c" + tournamentPlayer.getPlayer().getName() + " does not have an empty inventory");
|
||||
tournamentTeam.playSound(Sound.ANVIL_LAND);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
this.finish(tournamentTeam);
|
||||
return true;
|
||||
}
|
||||
|
||||
@SubCommand("setspawn")
|
||||
@Permission("cranked.admin")
|
||||
public void setSpawnCommand(final Player player, String tournamentArena, String team) {
|
||||
if(this.plugin.getArenaManager().containsKey(tournamentArena)) {
|
||||
TournamentArena tournamentArenaObject = this.plugin.getArenaManager().getFromCache(tournamentArena);
|
||||
if(team.equals("true")) tournamentArenaObject.setSpawnPointOne(player.getLocation());
|
||||
if(team.equals("false")) tournamentArenaObject.setSpawnPointTwo(player.getLocation());
|
||||
player.sendMessage("setup");
|
||||
return;
|
||||
}
|
||||
this.plugin.getArenaManager().addToCache(new TournamentArena(tournamentArena, player.getLocation(), player.getLocation(), false));
|
||||
|
||||
player.sendMessage("setup");
|
||||
player.playSound(player.getLocation(), Sound.SUCCESSFUL_HIT, 2.0F, 2.0F);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package net.crankedpvp.tournaments.constants;
|
||||
|
||||
public enum TournamentStatus {
|
||||
ACTIVE, JOINABLE, INACTIVE
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package net.crankedpvp.tournaments.inventory;
|
||||
|
||||
public class TournamentInventory {
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package net.crankedpvp.tournaments.listeners;
|
||||
|
||||
import net.crankedpvp.tournaments.TournamentsPlugin;
|
||||
import net.crankedpvp.tournaments.TournamentsAPI;
|
||||
import net.crankedpvp.tournaments.managers.TournamentManager;
|
||||
import net.crankedpvp.tournaments.struct.TournamentPlayer;
|
||||
import net.crankedpvp.tournaments.struct.TournamentTeam;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
|
||||
public class DeathListener implements Listener {
|
||||
|
||||
private TournamentsPlugin plugin;
|
||||
private TournamentManager tournamentManager;
|
||||
public DeathListener(TournamentsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.tournamentManager = plugin.getTournamentManager();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void deathHandler(PlayerDeathEvent event) {
|
||||
if(event.getEntity() == null) return;
|
||||
if(event.getEntity().getKiller() == null) return;
|
||||
|
||||
Player victim = event.getEntity();
|
||||
Player attacker = event.getEntity().getKiller();
|
||||
|
||||
System.out.println("here");
|
||||
|
||||
if(!TournamentsAPI.isPlayerInTournament(victim)) return;
|
||||
System.out.println("here 1");
|
||||
if(!TournamentsAPI.isPlayerInTournament(attacker)) return;
|
||||
System.out.println("here 2");
|
||||
|
||||
TournamentTeam victimTeam = TournamentsAPI.getTournamentTeamFromPlayer(victim);
|
||||
TournamentTeam attackerTeam = TournamentsAPI.getTournamentTeamFromPlayer(attacker);
|
||||
|
||||
System.out.println("here 3");
|
||||
|
||||
TournamentPlayer victimTournamentPlayer = victimTeam.getTournamentPlayer(victim);
|
||||
TournamentPlayer attackerTournamentPlayer = attackerTeam.getTournamentPlayer(attacker);
|
||||
|
||||
System.out.println("here 4");
|
||||
|
||||
victimTournamentPlayer.kill();
|
||||
|
||||
System.out.println("here 5");
|
||||
if(!victimTeam.hasPlayerAlive()) {
|
||||
System.out.println("here 6");
|
||||
victimTeam.lose();
|
||||
attackerTeam.win();
|
||||
this.tournamentManager.putNextPlayersInArena();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package net.crankedpvp.tournaments.managers;
|
||||
|
||||
import net.crankedpvp.storageutils.StorageUtils;
|
||||
import net.crankedpvp.storageutils.struct.NewSaveLoadManager;
|
||||
import net.crankedpvp.tournaments.struct.TournamentArena;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class ArenaManager extends NewSaveLoadManager<String, TournamentArena> {
|
||||
public ArenaManager(JavaPlugin plugin) {
|
||||
super(plugin, StorageUtils.getInstance().getGson(), "arenas", TournamentArena.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize(String string) {
|
||||
return string;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String deserialize(String string) {
|
||||
return string;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package net.crankedpvp.tournaments.managers;
|
||||
|
||||
import net.crankedpvp.storageutils.StorageUtils;
|
||||
import net.crankedpvp.storageutils.struct.NewSaveLoadManager;
|
||||
import net.crankedpvp.tournaments.struct.TournamentPlayer;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerManager extends NewSaveLoadManager<UUID, TournamentPlayer> {
|
||||
public PlayerManager(JavaPlugin plugin) {
|
||||
super(plugin, StorageUtils.getInstance().getGson(), "data/", TournamentPlayer.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize(UUID uuid) {
|
||||
return uuid.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID deserialize(String s) {
|
||||
return UUID.fromString(s);
|
||||
}
|
||||
|
||||
public TournamentPlayer getTournamentPlayer(UUID uuid) {
|
||||
if (!containsKey(uuid)) {
|
||||
TournamentPlayer tournamentPlayer = new TournamentPlayer(uuid);
|
||||
addToCache(tournamentPlayer);
|
||||
}
|
||||
return getFromCache(uuid);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package net.crankedpvp.tournaments.managers;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.crankedpvp.crankedutils.utils.Queue;
|
||||
import net.crankedpvp.tournaments.TournamentsPlugin;
|
||||
import net.crankedpvp.tournaments.TournamentsAPI;
|
||||
import net.crankedpvp.tournaments.constants.TournamentStatus;
|
||||
import net.crankedpvp.tournaments.struct.TournamentArena;
|
||||
import net.crankedpvp.tournaments.struct.TournamentMatch;
|
||||
import net.crankedpvp.tournaments.struct.TournamentPlayer;
|
||||
import net.crankedpvp.tournaments.struct.TournamentTeam;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TournamentManager {
|
||||
|
||||
private TournamentsPlugin plugin;
|
||||
public TournamentManager(TournamentsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.tournamentParticipants = new ArrayList<>();
|
||||
this.teamQueue = new Queue<>();
|
||||
}
|
||||
|
||||
@Getter @Setter
|
||||
private TournamentStatus status;
|
||||
|
||||
@Getter @Setter
|
||||
private int teamSize;
|
||||
|
||||
@Getter
|
||||
private Queue<TournamentTeam> teamQueue;
|
||||
|
||||
@Getter
|
||||
private List<TournamentTeam> tournamentParticipants;
|
||||
|
||||
@Getter
|
||||
private final List<TournamentMatch> tournamentMatchList = new ArrayList<>();
|
||||
|
||||
public boolean isActive() {
|
||||
return this.status == TournamentStatus.ACTIVE;
|
||||
}
|
||||
|
||||
public boolean isJoinable() {
|
||||
return this.status == TournamentStatus.JOINABLE;
|
||||
}
|
||||
|
||||
public boolean isInactive() {
|
||||
return this.status == TournamentStatus.INACTIVE;
|
||||
}
|
||||
|
||||
public void putNextPlayersInArena() {
|
||||
if(this.teamQueue.size() == 1) {
|
||||
this.selectWinner(this.teamQueue.dequeue());
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("here");
|
||||
|
||||
if(this.teamQueue.size() < 2) return;
|
||||
System.out.println("here2");
|
||||
for(TournamentArena tournamentArena : this.plugin.getArenaManager().getCacheValues()) {
|
||||
System.out.println("arena name: " + tournamentArena.getArenaName());
|
||||
if(tournamentArena.isActive()) continue;
|
||||
this.setupTournamentMatch(tournamentArena);
|
||||
}
|
||||
}
|
||||
|
||||
private void setupTournamentMatch(TournamentArena tournamentArena) {
|
||||
tournamentArena.setActive(true);
|
||||
TournamentMatch tournamentMatch = new TournamentMatch(this.teamQueue.dequeue(), this.teamQueue.dequeue(), tournamentArena);
|
||||
tournamentMatch.start();
|
||||
this.tournamentMatchList.add(tournamentMatch);
|
||||
}
|
||||
|
||||
private void selectWinner(TournamentTeam winningTeam) {
|
||||
Bukkit.broadcastMessage(winningTeam.getLeader().getPlayer().getName() + " wins");
|
||||
winningTeam.teleport(Bukkit.getWorld("world").getSpawnLocation());
|
||||
winningTeam.clearInventory();
|
||||
}
|
||||
|
||||
public String getTournamentTeamSizeFixedString() {
|
||||
return this.teamSize + "v" + this.teamSize;
|
||||
}
|
||||
|
||||
public void end() {
|
||||
this.teleportAllPlayersToSpawn();
|
||||
this.teamQueue.clear();
|
||||
this.setStatus(TournamentStatus.INACTIVE);
|
||||
this.tournamentMatchList.clear();
|
||||
for(TournamentArena tournamentArena : this.plugin.getArenaManager().getCacheValues()) {
|
||||
tournamentArena.setActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void teleportAllPlayersToSpawn() {
|
||||
while(this.teamQueue.hasItems()) {
|
||||
TournamentTeam tournamentTeam = this.teamQueue.dequeue();
|
||||
for(TournamentPlayer tournamentPlayer : tournamentTeam.getAllPlayers()) {
|
||||
tournamentPlayer.getPlayer().teleport(Bukkit.getWorld("world").getSpawnLocation(), PlayerTeleportEvent.TeleportCause.UNKNOWN);
|
||||
TournamentsAPI.clearInventory(tournamentPlayer.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setupQueue() {
|
||||
for(TournamentTeam tournamentTeam : this.getTournamentParticipants()) {
|
||||
this.teamQueue.enqueue(tournamentTeam);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Location getWaitingRoomLocation() {
|
||||
return new Location(Bukkit.getWorld("world"), 50, 50, 50);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package net.crankedpvp.tournaments.struct;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.crankedpvp.storageutils.struct.NewKeyToSave;
|
||||
import org.bukkit.Location;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
@Setter
|
||||
public class TournamentArena implements NewKeyToSave<String> {
|
||||
|
||||
private String arenaName;
|
||||
private Location spawnPointOne;
|
||||
private Location spawnPointTwo;
|
||||
private transient boolean active;
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return this.arenaName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setKey(String name) {
|
||||
this.arenaName = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package net.crankedpvp.tournaments.struct;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
|
||||
@Getter @AllArgsConstructor
|
||||
public class TournamentMatch {
|
||||
|
||||
private TournamentTeam teamOne;
|
||||
private TournamentTeam teamTwo;
|
||||
private TournamentArena arena;
|
||||
|
||||
public void start() {
|
||||
|
||||
for(TournamentPlayer tournamentPlayer : this.teamOne.getAllPlayers()) {
|
||||
tournamentPlayer.getPlayer().teleport(this.arena.getSpawnPointOne(), PlayerTeleportEvent.TeleportCause.UNKNOWN);
|
||||
tournamentPlayer.sendMessage("good luck");
|
||||
}
|
||||
|
||||
for(TournamentPlayer tournamentPlayer : this.teamTwo.getAllPlayers()) {
|
||||
tournamentPlayer.getPlayer().teleport(this.arena.getSpawnPointTwo(), PlayerTeleportEvent.TeleportCause.UNKNOWN);
|
||||
tournamentPlayer.sendMessage("good luck");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package net.crankedpvp.tournaments.struct;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.storageutils.struct.NewKeyToSave;
|
||||
import net.crankedpvp.tournaments.TournamentsPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
public class TournamentPlayer implements NewKeyToSave<UUID> {
|
||||
|
||||
private UUID playerUUID;
|
||||
|
||||
@Setter
|
||||
private boolean inTournament;
|
||||
|
||||
@Setter
|
||||
private boolean alive;
|
||||
|
||||
public TournamentPlayer(UUID uuid) {
|
||||
this.playerUUID = uuid;
|
||||
this.alive = false;
|
||||
this.inTournament = false;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return Bukkit.getPlayer(this.playerUUID);
|
||||
}
|
||||
|
||||
public void sendMessage(String message) {
|
||||
this.getPlayer().sendMessage(CC.translate(message));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public UUID getKey() {
|
||||
return this.playerUUID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setKey(UUID uuid) {
|
||||
this.playerUUID = uuid;
|
||||
}
|
||||
|
||||
public void kill() {
|
||||
this.setAlive(false);
|
||||
this.getPlayer().teleport(TournamentsPlugin.getInstance().getTournamentManager().getWaitingRoomLocation());
|
||||
this.sendMessage("&cYou have been eliminated from the tournament");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package net.crankedpvp.tournaments.struct;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.teams.struct.Team;
|
||||
import net.crankedpvp.tournaments.TournamentsPlugin;
|
||||
import net.crankedpvp.tournaments.TournamentsAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Getter
|
||||
public class TournamentTeam {
|
||||
|
||||
private final TournamentPlayer leader;
|
||||
private final List<TournamentPlayer> members;
|
||||
|
||||
public TournamentTeam(TournamentPlayer leader, List<TournamentPlayer> members) {
|
||||
this.leader = leader;
|
||||
this.members = members;
|
||||
}
|
||||
|
||||
public TournamentTeam(Team team) {
|
||||
this.leader = new TournamentPlayer(team.getLeader().getUniqueId());
|
||||
List<TournamentPlayer> members = new ArrayList<>();
|
||||
for(Player member : team.getMembers()) {
|
||||
members.add(new TournamentPlayer(member.getUniqueId()));
|
||||
}
|
||||
this.members = members;
|
||||
}
|
||||
|
||||
public int getTeamSize() {
|
||||
return this.getAllPlayers().size();
|
||||
}
|
||||
|
||||
public List<TournamentPlayer> getAllPlayers() {
|
||||
List<TournamentPlayer> tempPlayers = new ArrayList<>();
|
||||
tempPlayers.add(this.leader);
|
||||
tempPlayers.addAll(this.members);
|
||||
return tempPlayers;
|
||||
}
|
||||
|
||||
public List<Player> getAllPlayersAsPlayers() {
|
||||
return this.getAllPlayers().stream().map(TournamentPlayer::getPlayer).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void sendMessage(String message) {
|
||||
this.getAllPlayers().forEach(player -> player.sendMessage(CC.translate(message)));
|
||||
}
|
||||
|
||||
public void playSound(Sound sound) {
|
||||
this.getAllPlayers().forEach(tournamentPlayer -> tournamentPlayer.getPlayer().playSound(tournamentPlayer.getPlayer().getLocation(), sound, 2.0f, 2.0f));
|
||||
}
|
||||
|
||||
public void teleport(Location location) {
|
||||
this.getAllPlayers().forEach(tournamentPlayer -> tournamentPlayer.getPlayer().teleport(location, PlayerTeleportEvent.TeleportCause.UNKNOWN));
|
||||
}
|
||||
|
||||
public void clearInventory() {
|
||||
this.getAllPlayers().forEach(tournamentPlayer -> TournamentsAPI.clearInventory(tournamentPlayer.getPlayer()));
|
||||
}
|
||||
|
||||
public boolean hasPlayerAlive() {
|
||||
for(TournamentPlayer allPlayer : this.getAllPlayers()) {
|
||||
if(!allPlayer.isAlive()) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public TournamentPlayer getTournamentPlayer(Player player) {
|
||||
for(TournamentPlayer tournamentPlayer : this.getAllPlayers()) {
|
||||
if(tournamentPlayer.getPlayerUUID().equals(player.getUniqueId())) return tournamentPlayer;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean containsPlayer(TournamentPlayer tournamentPlayer) {
|
||||
return this.getAllPlayers().contains(tournamentPlayer);
|
||||
}
|
||||
|
||||
public void win() {
|
||||
TournamentsPlugin.getInstance().getTournamentManager().getTeamQueue().enqueue(this);
|
||||
this.teleport(TournamentsPlugin.getInstance().getTournamentManager().getWaitingRoomLocation());
|
||||
this.clearInventory();
|
||||
}
|
||||
|
||||
public void lose() {
|
||||
TournamentsPlugin.getInstance().getTournamentManager().getTournamentParticipants().remove(this);
|
||||
this.teleport(Bukkit.getWorld("world").getSpawnLocation());
|
||||
this.clearInventory();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package net.crankedpvp.tournaments.tasks;
|
||||
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.crankedutils.utils.Clickable;
|
||||
import net.crankedpvp.tournaments.TournamentsPlugin;
|
||||
import net.crankedpvp.tournaments.constants.TournamentStatus;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class TournamentStartTask extends BukkitRunnable {
|
||||
|
||||
private final TournamentsPlugin plugin;
|
||||
private int seconds;
|
||||
|
||||
public TournamentStartTask(TournamentsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
if(plugin.getTournamentManager().isInactive()) {
|
||||
return;
|
||||
}
|
||||
this.seconds = 31;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
this.seconds--;
|
||||
if(this.seconds == 0) {
|
||||
|
||||
if(plugin.getTournamentManager().getTournamentParticipants().size() == 0) {
|
||||
plugin.getTournamentManager().end();
|
||||
Bukkit.broadcastMessage(CC.translate("&cThe ongoing tournament event has been forcefully ended"));
|
||||
return;
|
||||
}
|
||||
plugin.getTournamentManager().setupQueue();
|
||||
plugin.getTournamentManager().setStatus(TournamentStatus.ACTIVE);
|
||||
|
||||
Bukkit.broadcastMessage("");
|
||||
Bukkit.broadcastMessage(CC.translate("&c&lCranked Tournaments &f(" + plugin.getTournamentManager().getTournamentTeamSizeFixedString() + " Tournament)"));
|
||||
Bukkit.broadcastMessage(CC.translate("&7&oThe tournament event is now starting..."));
|
||||
Bukkit.broadcastMessage(CC.translate("&7&oMay the best player win :D"));
|
||||
Bukkit.broadcastMessage("");
|
||||
Bukkit.broadcastMessage(CC.translate("&cTournament entry has now &c&nCLOSED"));
|
||||
Bukkit.broadcastMessage("");
|
||||
|
||||
this.plugin.getTournamentManager().putNextPlayersInArena();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(this.seconds == 60 || this.seconds == 30 || this.seconds == 15 || this.seconds == 10 || (this.seconds <= 5 && this.seconds > 0)) {
|
||||
|
||||
for(Player player : Bukkit.getOnlinePlayers()) {
|
||||
sendJSONMessage(player);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String getFormattedTime(int seconds) {
|
||||
int minutes = seconds/60;
|
||||
seconds %= 60;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
if(minutes > 0) {
|
||||
builder.append(minutes).append("m, ");
|
||||
}
|
||||
if(seconds > 0 || seconds == 0) {
|
||||
builder.append(seconds).append("s, ");
|
||||
}
|
||||
return builder.substring(0, builder.toString().lastIndexOf(","));
|
||||
}
|
||||
|
||||
private void sendJSONMessage(Player player) {
|
||||
player.sendMessage("");
|
||||
player.sendMessage(CC.translate("&c&lCranked Tournaments &f(" + plugin.getTournamentManager().getTournamentTeamSizeFixedString() + " Tournament)"));
|
||||
player.sendMessage(CC.translate("&7&oTournaments are special events where players"));
|
||||
player.sendMessage(CC.translate("&7&ofight eachother until only one player remains"));
|
||||
player.sendMessage("");
|
||||
Clickable clickable = new Clickable("&7Click &nhere&r &7to join the tournament", "&7&oClick to join tournament", "/tournament join");
|
||||
clickable.sendToPlayer(player);
|
||||
player.sendMessage("");
|
||||
player.sendMessage(CC.translate("&cTournament entry will close in &f" + getFormattedTime(this.seconds)));
|
||||
player.sendMessage("");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
Spawn: world,-150.0,80.0,-100.0
|
||||
Tournament:
|
||||
WaitingRoom:
|
||||
Location: world,-100.0,80.0,-100.0
|
||||
Arenas:
|
||||
Pingu Snowdome:
|
||||
PlayerOneSpawnPoint: world,-270.0,80.0,-122.0
|
||||
PlayerTwoSpawnPoint: world,-365.0,80.0,-122.0
|
||||
@@ -0,0 +1,7 @@
|
||||
name: CrankedTournaments
|
||||
main: net.crankedpvp.tournaments.TournamentsPlugin
|
||||
version: ${git.total.commit.count}.0
|
||||
description: "§fCommit ID: §a${git.commit.id.abbrev}"
|
||||
website: https://crankedpvp.net/
|
||||
depend: [ WorldGuard, CrankedUtils, Teams ]
|
||||
softdepend: [ Essentials, Factions, Vault, ProtocolLib ]
|
||||
Reference in New Issue
Block a user