Starting on Tournaments.
This commit is contained in:
parent
105f62e563
commit
85f4ff1299
@ -0,0 +1,20 @@
|
||||
package mineplex.core.tournament;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.command.CommandBase;
|
||||
import mineplex.core.common.Rank;
|
||||
|
||||
public class DebugShopCommand extends CommandBase<TournamentManager>
|
||||
{
|
||||
public DebugShopCommand(TournamentManager plugin)
|
||||
{
|
||||
super(plugin, Rank.ALL, "ots");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Execute(Player caller, String[] args)
|
||||
{
|
||||
Plugin.openShop(caller);
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
package mineplex.core.tournament;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.MiniDbClientPlugin;
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.tournament.data.ClientTournamentData;
|
||||
import mineplex.core.tournament.data.Tournament;
|
||||
import mineplex.core.tournament.data.TournamentInviteStatus;
|
||||
import mineplex.core.tournament.data.TournamentParticipant;
|
||||
import mineplex.core.tournament.data.TournamentTeam;
|
||||
import mineplex.core.tournament.ui.TournamentShop;
|
||||
|
||||
public class TournamentManager extends MiniDbClientPlugin<ClientTournamentData>
|
||||
{
|
||||
private TournamentRepository _repository;
|
||||
private TournamentShop _shop;
|
||||
private HashSet<Tournament> _tournaments = new HashSet<>();
|
||||
|
||||
public TournamentManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager)
|
||||
{
|
||||
super("Tournament Manager", plugin, clientManager);
|
||||
|
||||
_repository = new TournamentRepository(plugin);
|
||||
_shop = new TournamentShop(this, clientManager, donationManager);
|
||||
addCommand(new DebugShopCommand(this));
|
||||
_tournaments = _repository.getTournaments();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getQuery(int accountId, String uuid, String name)
|
||||
{
|
||||
return "SELECT TT.id, TT.tournamentId, accounts.id, accounts.uuid, accounts.name, TTI.status FROM tournamentTeams AS TT INNER JOIN accounts ON accounts.id = TT.accountId LEFT JOIN tournamentTeamInvites AS TTI ON TTI.teamId = TT.id WHERE TT.accountId = " + accountId + ";";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processLoginResultSet(String playerName, int accountId, ResultSet resultSet) throws SQLException
|
||||
{
|
||||
ClientTournamentData clientData = Get(playerName);
|
||||
|
||||
while (resultSet.next())
|
||||
{
|
||||
int teamId = resultSet.getInt(1);
|
||||
int tournamentId = resultSet.getInt(2);
|
||||
int id = resultSet.getInt(3);
|
||||
String uuid = resultSet.getString(4);
|
||||
String name = resultSet.getString(5);
|
||||
String status = resultSet.getString(6);
|
||||
|
||||
if (!clientData.Tournaments.containsKey(tournamentId))
|
||||
{
|
||||
clientData.Tournaments.put(tournamentId, new Tournament());
|
||||
}
|
||||
|
||||
Tournament tournament = clientData.Tournaments.get(tournamentId);
|
||||
|
||||
if (!tournament.Teams.containsKey(teamId))
|
||||
{
|
||||
tournament.Teams.put(teamId, new TournamentTeam());
|
||||
}
|
||||
|
||||
TournamentTeam team = tournament.Teams.get(teamId);
|
||||
TournamentParticipant participant = new TournamentParticipant();
|
||||
participant.Name = name;
|
||||
participant.Uuid = UUID.fromString(uuid);
|
||||
participant.Status = Enum.valueOf(TournamentInviteStatus.class, status);
|
||||
|
||||
team.Members.put(id, participant);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ClientTournamentData AddPlayer(String player)
|
||||
{
|
||||
return new ClientTournamentData();
|
||||
}
|
||||
|
||||
public void openShop(Player player)
|
||||
{
|
||||
_shop.attemptShopOpen(player);
|
||||
}
|
||||
|
||||
public HashSet<Tournament> getTournaments()
|
||||
{
|
||||
return _tournaments;
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package mineplex.core.tournament;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.database.MinecraftRepository;
|
||||
import mineplex.core.tournament.data.Tournament;
|
||||
import mineplex.serverdata.database.DBPool;
|
||||
import mineplex.serverdata.database.ResultSetCallable;
|
||||
import mineplex.serverdata.database.column.ColumnInt;
|
||||
|
||||
public class TournamentRepository extends MinecraftRepository
|
||||
{
|
||||
private static String REGISTER_FOR_TOURNAMENT = "INSERT INTO tournamentTeams(tournamentId, accountId) VALUES (?, ?);";
|
||||
private static String UNREGISTER_FOR_TOURNAMENT = "DELETE FROM TTI FROM tournamentTeamInvites AS TTI INNER JOIN tournamentTeams AS TT ON TT.id = TTI.teamId WHERE TTI.accountId = ? AND TT.tournamentId = ?;";
|
||||
private static String UNREGISTER_TEAM_FOR_TOURNAMENT = "DELETE FROM tournamentTeams WHERE accountId = ? AND tournamentId = ?;";
|
||||
private static String RETRIEVE_ALL_TOURNAMENTS = "SELECT * FROM tournaments;";
|
||||
|
||||
public TournamentRepository(JavaPlugin plugin)
|
||||
{
|
||||
super(plugin, DBPool.getAccount());
|
||||
}
|
||||
|
||||
public boolean registerForTournament(int accountId, int tournamentId)
|
||||
{
|
||||
return executeUpdate(REGISTER_FOR_TOURNAMENT, null, new ColumnInt("accountId", accountId), new ColumnInt("tournamentId", tournamentId)) > 0;
|
||||
}
|
||||
|
||||
public boolean unregisterFromTeam(int accountId, int tournamentId)
|
||||
{
|
||||
return executeUpdate(UNREGISTER_FOR_TOURNAMENT, null, new ColumnInt("accountId", accountId), new ColumnInt("tournamentId", tournamentId)) > 0;
|
||||
}
|
||||
|
||||
public boolean unregisterTeamFromTournament(int accountId, int tournamentId)
|
||||
{
|
||||
return executeUpdate(UNREGISTER_TEAM_FOR_TOURNAMENT, null, new ColumnInt("accountId", accountId), new ColumnInt("tournamentId", tournamentId)) > 0;
|
||||
}
|
||||
|
||||
public HashSet<Tournament> getTournaments()
|
||||
{
|
||||
HashSet<Tournament> tournaments = new HashSet<>();
|
||||
|
||||
executeQuery(RETRIEVE_ALL_TOURNAMENTS, new ResultSetCallable()
|
||||
{
|
||||
@Override
|
||||
public void processResultSet(ResultSet resultSet) throws SQLException
|
||||
{
|
||||
while (resultSet.next())
|
||||
{
|
||||
Tournament tournament = new Tournament();
|
||||
tournament.TournamentId = resultSet.getInt(1);
|
||||
tournament.Name = resultSet.getString(2);
|
||||
tournament.Date = resultSet.getTimestamp(3).getTime();
|
||||
tournament.GameType = resultSet.getString(4);
|
||||
|
||||
tournaments.add(tournament);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return tournaments;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initialize() { }
|
||||
|
||||
@Override
|
||||
protected void update() { }
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package mineplex.core.tournament.data;
|
||||
|
||||
import mineplex.core.common.util.NautHashMap;
|
||||
|
||||
public class ClientTournamentData
|
||||
{
|
||||
public NautHashMap<Integer, Tournament> Tournaments = new NautHashMap<>();
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package mineplex.core.tournament.data;
|
||||
|
||||
import mineplex.core.common.util.NautHashMap;
|
||||
|
||||
public class Tournament
|
||||
{
|
||||
public int TournamentId = -1;
|
||||
public String Name;
|
||||
public String GameType;
|
||||
public long Date = 0;
|
||||
public NautHashMap<Integer, TournamentTeam> Teams = new NautHashMap<>();
|
||||
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package mineplex.core.tournament.data;
|
||||
|
||||
public enum TournamentInviteStatus
|
||||
{
|
||||
INVITED,
|
||||
ACCEPTED,
|
||||
DENIED
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package mineplex.core.tournament.data;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class TournamentParticipant
|
||||
{
|
||||
public UUID Uuid = null;
|
||||
public String Name;
|
||||
public TournamentInviteStatus Status;
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package mineplex.core.tournament.data;
|
||||
|
||||
import mineplex.core.common.util.NautHashMap;
|
||||
|
||||
public class TournamentTeam
|
||||
{
|
||||
public NautHashMap<Integer, TournamentParticipant> Members = new NautHashMap<>();
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package mineplex.core.tournament.ui;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.common.CurrencyType;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.shop.ShopBase;
|
||||
import mineplex.core.shop.page.ShopPageBase;
|
||||
import mineplex.core.tournament.TournamentManager;
|
||||
import mineplex.core.tournament.ui.page.MainMenu;
|
||||
|
||||
public class TournamentShop extends ShopBase<TournamentManager>
|
||||
{
|
||||
public TournamentShop(TournamentManager plugin, CoreClientManager clientManager, DonationManager donationManager)
|
||||
{
|
||||
super(plugin, clientManager, donationManager, "Tournaments", CurrencyType.Gems);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ShopPageBase<TournamentManager, ? extends ShopBase<TournamentManager>> buildPagesFor(Player player)
|
||||
{
|
||||
return new MainMenu(getPlugin(), this, getClientManager(), getDonationManager(), player);
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package mineplex.core.tournament.ui.page;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
import mineplex.core.shop.item.IButton;
|
||||
import mineplex.core.shop.page.ShopPageBase;
|
||||
import mineplex.core.tournament.TournamentManager;
|
||||
import mineplex.core.tournament.ui.TournamentShop;
|
||||
|
||||
public class MainMenu extends ShopPageBase<TournamentManager, TournamentShop>
|
||||
{
|
||||
private static IButton _friendsButton = null;
|
||||
private static IButton _tournamentsButton = null;
|
||||
|
||||
public MainMenu(TournamentManager plugin, TournamentShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player)
|
||||
{
|
||||
super(plugin, shop, clientManager, donationManager, "Tournament Menu", player, 9);
|
||||
|
||||
if (_friendsButton == null)
|
||||
{
|
||||
_friendsButton = new IButton()
|
||||
{
|
||||
@Override
|
||||
public void onClick(Player player, ClickType clickType)
|
||||
{
|
||||
shop.openPageForPlayer(player, new SoloTournamentMenu(plugin, shop, clientManager, donationManager, player));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (_tournamentsButton == null)
|
||||
{
|
||||
_tournamentsButton = new IButton()
|
||||
{
|
||||
@Override
|
||||
public void onClick(Player player, ClickType clickType)
|
||||
{
|
||||
shop.openPageForPlayer(player, new TournamentsMenu(plugin, shop, clientManager, donationManager, player));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
buildPage();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildPage()
|
||||
{
|
||||
addButton(0, new ItemBuilder(Material.SKULL_ITEM, 1, (short) 3).setTitle("Friends").build(), _friendsButton);
|
||||
addButton(1, new ItemBuilder(Material.CHEST, 1).setTitle("Tournaments").build(), _tournamentsButton);
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package mineplex.core.tournament.ui.page;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.shop.ShopBase;
|
||||
import mineplex.core.shop.page.ShopPageBase;
|
||||
import mineplex.core.tournament.TournamentManager;
|
||||
import mineplex.core.tournament.ui.TournamentShop;
|
||||
|
||||
public class SoloTournamentMenu extends ShopPageBase<TournamentManager, TournamentShop>
|
||||
{
|
||||
public SoloTournamentMenu(TournamentManager plugin, TournamentShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player)
|
||||
{
|
||||
super(plugin, shop, clientManager, donationManager, "Solo Tournaments", player);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildPage()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package mineplex.core.tournament.ui.page;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
import mineplex.core.shop.page.ShopPageBase;
|
||||
import mineplex.core.tournament.TournamentManager;
|
||||
import mineplex.core.tournament.data.Tournament;
|
||||
import mineplex.core.tournament.ui.TournamentShop;
|
||||
|
||||
public class TournamentsMenu extends ShopPageBase<TournamentManager, TournamentShop>
|
||||
{
|
||||
private static Calendar _calendar = Calendar.getInstance();
|
||||
|
||||
public TournamentsMenu(TournamentManager plugin, TournamentShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player)
|
||||
{
|
||||
super(plugin, shop, clientManager, donationManager, "Tournament Calender", player, 45);
|
||||
|
||||
buildPage();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildPage()
|
||||
{
|
||||
int currentDayOfMonth = _calendar.get(Calendar.DAY_OF_MONTH);
|
||||
int maxDaysThisMonth = _calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
|
||||
|
||||
_calendar.set(Calendar.DAY_OF_MONTH, 1);
|
||||
int startDayOfMonth = _calendar.get(Calendar.DAY_OF_WEEK);
|
||||
int slot = startDayOfMonth;
|
||||
|
||||
for (int i=1; i <= maxDaysThisMonth; i++)
|
||||
{
|
||||
if ((slot + 1) % 9 == 0)
|
||||
slot += 2;
|
||||
|
||||
if (i == currentDayOfMonth)
|
||||
addItem(slot, new ItemBuilder(Material.STAINED_GLASS_PANE, i, (byte)5).setTitle("TODAY.").build());
|
||||
else
|
||||
addItem(slot, new ItemBuilder(Material.STAINED_GLASS_PANE, i, (byte)14).setTitle("No Tournaments Scheduled.").build());
|
||||
|
||||
slot++;
|
||||
}
|
||||
|
||||
for (Tournament tournament : getPlugin().getTournaments())
|
||||
{
|
||||
_calendar.setTime(new Date(tournament.Date));
|
||||
|
||||
addItem(slot, new ItemBuilder(Material.STAINED_GLASS_PANE, i, (byte)14).setTitle("No Tournaments Scheduled.").build());
|
||||
}
|
||||
}
|
||||
}
|
@ -50,6 +50,7 @@ import mineplex.core.status.ServerStatusManager;
|
||||
import mineplex.core.task.TaskManager;
|
||||
import mineplex.core.teleport.Teleport;
|
||||
import mineplex.core.titangiveaway.TitanGiveawayManager;
|
||||
import mineplex.core.tournament.TournamentManager;
|
||||
import mineplex.core.updater.FileUpdater;
|
||||
import mineplex.core.updater.Updater;
|
||||
import mineplex.core.velocity.VelocityFix;
|
||||
@ -113,7 +114,8 @@ public class Hub extends JavaPlugin implements IRelation
|
||||
InventoryManager inventoryManager = new InventoryManager(this, clientManager);
|
||||
PetManager petManager = new PetManager(this, clientManager, donationManager, inventoryManager, disguiseManager, creature, blockRestore, webServerAddress);
|
||||
PollManager pollManager = new PollManager(this, clientManager, donationManager);
|
||||
|
||||
new TournamentManager(this, clientManager, donationManager);
|
||||
|
||||
//Main Modules
|
||||
ServerStatusManager serverStatusManager = new ServerStatusManager(this, clientManager, new LagMeter(this, clientManager));
|
||||
new TitanGiveawayManager(this, clientManager, serverStatusManager);
|
||||
|
Loading…
Reference in New Issue
Block a user