Finished main tournament calendar UI.

Added registration for tournaments.
This commit is contained in:
Jonathan Williams 2016-04-14 12:21:24 -05:00
parent 85f4ff1299
commit 3a26225ce2
3 changed files with 99 additions and 15 deletions

View File

@ -10,7 +10,9 @@ import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniDbClientPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.F;
import mineplex.core.donation.DonationManager;
import mineplex.core.recharge.Recharge;
import mineplex.core.tournament.data.ClientTournamentData;
import mineplex.core.tournament.data.Tournament;
import mineplex.core.tournament.data.TournamentInviteStatus;
@ -91,4 +93,37 @@ public class TournamentManager extends MiniDbClientPlugin<ClientTournamentData>
{
return _tournaments;
}
public void registerForTournament(Player player, Tournament tournament, Runnable runnable)
{
if (!Recharge.Instance.use(player, "Tournament Registration", 1000, true, false))
return;
runAsync(new Runnable()
{
@Override
public void run()
{
boolean success = _repository.registerForTournament(getClientManager().getAccountId(player), tournament.TournamentId);
runSync(new Runnable()
{
@Override
public void run()
{
if (success)
{
player.sendMessage(F.main(getName(), "You have successfully registered for " + tournament.Name + " tournament!"));
}
else
{
player.sendMessage(F.main(getName(), "There was an error registering you for " + tournament.Name + " tournament. Please try again later."));
}
runnable.run();
}
});
}
});
}
}

View File

@ -14,7 +14,7 @@ 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 REGISTER_FOR_TOURNAMENT = "INSERT INTO tournamentTeams(accountId, tournamentId) 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;";
@ -26,17 +26,17 @@ public class TournamentRepository extends MinecraftRepository
public boolean registerForTournament(int accountId, int tournamentId)
{
return executeUpdate(REGISTER_FOR_TOURNAMENT, null, new ColumnInt("accountId", accountId), new ColumnInt("tournamentId", tournamentId)) > 0;
return executeUpdate(REGISTER_FOR_TOURNAMENT, 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;
return executeUpdate(UNREGISTER_FOR_TOURNAMENT, 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;
return executeUpdate(UNREGISTER_TEAM_FOR_TOURNAMENT, new ColumnInt("accountId", accountId), new ColumnInt("tournamentId", tournamentId)) > 0;
}
public HashSet<Tournament> getTournaments()

View File

@ -1,23 +1,31 @@
package mineplex.core.tournament.ui.page;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.NautHashMap;
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.data.Tournament;
import mineplex.core.tournament.ui.TournamentShop;
import net.md_5.bungee.api.ChatColor;
public class TournamentsMenu extends ShopPageBase<TournamentManager, TournamentShop>
{
private static Calendar _calendar = Calendar.getInstance();
private static SimpleDateFormat _tournamentStart = new SimpleDateFormat("h:mma z");
private static SimpleDateFormat _tournamentCountdown = new SimpleDateFormat("h:mm:ss");
public TournamentsMenu(TournamentManager plugin, TournamentShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player)
{
super(plugin, shop, clientManager, donationManager, "Tournament Calender", player, 45);
@ -28,6 +36,15 @@ public class TournamentsMenu extends ShopPageBase<TournamentManager, TournamentS
@Override
protected void buildPage()
{
NautHashMap<Integer, Tournament> tournamentDateMap = new NautHashMap<>();
for (Tournament tournament : getPlugin().getTournaments())
{
_calendar.setTime(new Date(tournament.Date));
tournamentDateMap.put(_calendar.get(Calendar.DAY_OF_MONTH), tournament);
}
int currentDayOfMonth = _calendar.get(Calendar.DAY_OF_MONTH);
int maxDaysThisMonth = _calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
@ -40,19 +57,51 @@ public class TournamentsMenu extends ShopPageBase<TournamentManager, TournamentS
if ((slot + 1) % 9 == 0)
slot += 2;
if (i == currentDayOfMonth)
addItem(slot, new ItemBuilder(Material.STAINED_GLASS_PANE, i, (byte)5).setTitle("TODAY.").build());
if (tournamentDateMap.containsKey(i))
{
final Tournament tournament = tournamentDateMap.get(i);
boolean registered = getPlugin().Get(getPlayer()).Tournaments.containsKey(tournament.TournamentId);
addButton(slot, new ItemBuilder(Material.PAPER, i).setTitle(ChatColor.RESET + "" + ChatColor.BOLD + ChatColor.GOLD + tournament.Name).setLore
(
ChatColor.GRAY + tournament.GameType, " ",
ChatColor.WHITE + "Take part in a super competitive",
ChatColor.WHITE + "tournament between all kinds of",
ChatColor.WHITE + "people in the Mineplex community!",
registered ? ChatColor.GREEN + "" + ChatColor.BOLD + "You are registered for this tournament!" : " ",
ChatColor.GRAY + "Time: " + ChatColor.YELLOW + _tournamentStart.format(new Date(tournament.Date)),
ChatColor.GRAY + "Countdown: " + ChatColor.LIGHT_PURPLE + _tournamentCountdown.format(new Date(tournament.Date - System.currentTimeMillis()))
).build(), !registered ? new IButton()
{
@Override
public void onClick(Player player, ClickType clickType)
{
getPlugin().registerForTournament(player, tournament, new Runnable()
{
@Override
public void run()
{
buildPage();
}
});
}
} : null);
}
else
addItem(slot, new ItemBuilder(Material.STAINED_GLASS_PANE, i, (byte)14).setTitle("No Tournaments Scheduled.").build());
{
/*
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(ChatColor.RESET + "" + ChatColor.BOLD + ChatColor.RED + "No Events").setLore
(
ChatColor.GRAY + "Sorry, there are no events",
ChatColor.GRAY + "on this particular date."
).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());
}
}
}