Skip to content

Commit 90ce012

Browse files
v2.3
1 parent 38d2cc8 commit 90ce012

10 files changed

Lines changed: 415 additions & 245 deletions

File tree

src/main/java/com/vortex/blackjack/BlackjackPlugin.java

Lines changed: 56 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.vortex.blackjack.table.BlackjackTable;
1010
import com.vortex.blackjack.table.TableManager;
1111
import com.vortex.blackjack.util.AsyncUtils;
12+
import com.vortex.blackjack.util.GenericUtils;
1213
import com.vortex.blackjack.util.VersionChecker;
1314
import org.bukkit.command.Command;
1415
import org.bukkit.command.CommandSender;
@@ -291,6 +292,47 @@ private void createDefaultMessagesFile(File messagesFile) {
291292
messagesConfig.set("player-left-during-turn", "&c%player% %reason% during their turn.");
292293
messagesConfig.set("player-left-table", "&c%player% %reason%.");
293294

295+
// Game action prompts
296+
messagesConfig.set("game-action-prompt", "&7Your turn: ");
297+
messagesConfig.set("game-action-separator", "&7 | ");
298+
messagesConfig.set("post-game-prompt", "&7Choose: ");
299+
300+
// Betting category labels
301+
messagesConfig.set("betting-category-small", "&7Small: ");
302+
messagesConfig.set("betting-category-medium", "&7Medium: ");
303+
messagesConfig.set("betting-category-large", "&7Large: ");
304+
305+
// Button configuration
306+
messagesConfig.set("buttons.hit.text", "&a&l[HIT]");
307+
messagesConfig.set("buttons.hit.command", "/hit");
308+
messagesConfig.set("buttons.hit.hover", "&eClick to take another card");
309+
310+
messagesConfig.set("buttons.stand.text", "&c&l[STAND]");
311+
messagesConfig.set("buttons.stand.command", "/stand");
312+
messagesConfig.set("buttons.stand.hover", "&eClick to end your turn");
313+
314+
messagesConfig.set("buttons.double-down.text", "&6&l[DOUBLE DOWN]");
315+
messagesConfig.set("buttons.double-down.command", "/doubledown");
316+
messagesConfig.set("buttons.double-down.hover", "&eClick to double your bet and take one card");
317+
318+
messagesConfig.set("buttons.play-again.text", "&a&l[Play Again]");
319+
messagesConfig.set("buttons.play-again.command", "/start");
320+
messagesConfig.set("buttons.play-again.hover", "&eClick to start a new game");
321+
322+
messagesConfig.set("buttons.leave-table.text", "&c&l[Leave Table]");
323+
messagesConfig.set("buttons.leave-table.command", "/leave");
324+
messagesConfig.set("buttons.leave-table.hover", "&eClick to leave the table");
325+
326+
messagesConfig.set("buttons.custom-bet.text", "&b&l[CUSTOM BET]");
327+
messagesConfig.set("buttons.custom-bet.command", "/bet ");
328+
messagesConfig.set("buttons.custom-bet.hover", "&eClick to enter custom amount");
329+
330+
// Button color configurations
331+
messagesConfig.set("buttons.small-bet-color", "&a"); // Green for small bets
332+
messagesConfig.set("buttons.medium-bet-color", "&e"); // Yellow for medium bets
333+
messagesConfig.set("buttons.large-bet-color", "&c"); // Red for large bets
334+
messagesConfig.set("buttons.huge-bet-color", "&d"); // Pink for huge bets
335+
294336
messagesConfig.save(messagesFile);
295337

296338
} catch (IOException e) {
@@ -495,33 +537,18 @@ private boolean handleStart(Player player) {
495537
}
496538

497539
private boolean handleHit(Player player) {
498-
BlackjackTable table = tableManager.getPlayerTable(player);
499-
if (table != null) {
500-
table.hit(player);
501-
} else {
502-
player.sendMessage(configManager.getMessage("not-at-table"));
503-
}
504-
return true;
540+
return GenericUtils.handleTableAction(player, tableManager, configManager, "hit",
541+
table -> table.hit(player));
505542
}
506543

507544
private boolean handleStand(Player player) {
508-
BlackjackTable table = tableManager.getPlayerTable(player);
509-
if (table != null) {
510-
table.stand(player);
511-
} else {
512-
player.sendMessage(configManager.getMessage("not-at-table"));
513-
}
514-
return true;
545+
return GenericUtils.handleTableAction(player, tableManager, configManager, "stand",
546+
table -> table.stand(player));
515547
}
516548

517549
private boolean handleDoubleDown(Player player) {
518-
BlackjackTable table = tableManager.getPlayerTable(player);
519-
if (table != null) {
520-
table.doubleDown(player);
521-
} else {
522-
player.sendMessage(configManager.getMessage("not-at-table"));
523-
}
524-
return true;
550+
return GenericUtils.handleTableAction(player, tableManager, configManager, "doubledown",
551+
table -> table.doubleDown(player));
525552
}
526553

527554
private boolean handleBet(Player player, String[] args) {
@@ -535,13 +562,11 @@ private boolean handleBet(Player player, String[] args) {
535562
return true;
536563
}
537564

538-
try {
539-
int amount = Integer.parseInt(args[1]);
540-
return processBet(player, amount);
541-
} catch (NumberFormatException e) {
542-
player.sendMessage(configManager.getMessage("invalid-amount"));
565+
Integer amount = GenericUtils.parseIntegerArgument(args[1], player, configManager, "invalid-amount");
566+
if (amount == null) {
543567
return true;
544568
}
569+
return processBet(player, amount);
545570
}
546571

547572
private boolean handleStats(Player player, String[] args) {
@@ -590,17 +615,7 @@ private boolean handleStats(Player player, String[] args) {
590615

591616
// Load stats for the target player
592617
FileConfiguration statsConfig = YamlConfiguration.loadConfiguration(statsFile);
593-
PlayerStats stats = new PlayerStats();
594-
String path = "players." + targetUUID + ".";
595-
596-
stats.setHandsWon(statsConfig.getInt(path + "handsWon", 0));
597-
stats.setHandsLost(statsConfig.getInt(path + "handsLost", 0));
598-
stats.setHandsPushed(statsConfig.getInt(path + "handsPushed", 0));
599-
stats.setCurrentStreak(statsConfig.getInt(path + "currentStreak", 0));
600-
stats.setBestStreak(statsConfig.getInt(path + "bestStreak", 0));
601-
stats.setTotalWinnings(statsConfig.getDouble(path + "totalWinnings", 0.0));
602-
stats.setBlackjacks(statsConfig.getInt(path + "blackjacks", 0));
603-
stats.setBusts(statsConfig.getInt(path + "busts", 0));
618+
PlayerStats stats = GenericUtils.loadPlayerStats(statsConfig, targetUUID);
604619

605620
if (stats.getTotalHands() == 0) {
606621
if (targetUUID.equals(player.getUniqueId())) {
@@ -611,21 +626,9 @@ private boolean handleStats(Player player, String[] args) {
611626
return true;
612627
}
613628

614-
String headerMessage = targetUUID.equals(player.getUniqueId()) ?
615-
configManager.getMessage("stats-header") :
616-
configManager.formatMessage("stats-other-player-header", "player", targetName);
617-
618-
// Use the new formatted messages from config
619-
player.sendMessage(headerMessage);
620-
player.sendMessage(configManager.formatMessage("stats-hands-won", "value", stats.getHandsWon()));
621-
player.sendMessage(configManager.formatMessage("stats-hands-lost", "value", stats.getHandsLost()));
622-
player.sendMessage(configManager.formatMessage("stats-hands-pushed", "value", stats.getHandsPushed()));
623-
player.sendMessage(configManager.formatMessage("stats-blackjacks", "value", stats.getBlackjacks()));
624-
player.sendMessage(configManager.formatMessage("stats-busts", "value", stats.getBusts()));
625-
player.sendMessage(configManager.formatMessage("stats-win-rate", "value", String.format("%.1f", stats.getWinRate())));
626-
player.sendMessage(configManager.formatMessage("stats-current-streak", "value", stats.getCurrentStreak()));
627-
player.sendMessage(configManager.formatMessage("stats-best-streak", "value", stats.getBestStreak()));
628-
player.sendMessage(configManager.formatMessage("stats-total-winnings", "value", String.format("%.2f", stats.getTotalWinnings())));
629+
// Use generic stats display method
630+
GenericUtils.sendStatsToPlayer(player, stats, configManager, targetName,
631+
targetUUID.equals(player.getUniqueId()));
629632

630633
return true;
631634
}
@@ -743,17 +746,7 @@ private void savePlayerStats() {
743746
FileConfiguration statsConfig = YamlConfiguration.loadConfiguration(statsFile);
744747

745748
for (Map.Entry<UUID, PlayerStats> entry : playerStats.entrySet()) {
746-
String path = "players." + entry.getKey() + ".";
747-
PlayerStats stats = entry.getValue();
748-
749-
statsConfig.set(path + "handsWon", stats.getHandsWon());
750-
statsConfig.set(path + "handsLost", stats.getHandsLost());
751-
statsConfig.set(path + "handsPushed", stats.getHandsPushed());
752-
statsConfig.set(path + "currentStreak", stats.getCurrentStreak());
753-
statsConfig.set(path + "bestStreak", stats.getBestStreak());
754-
statsConfig.set(path + "totalWinnings", stats.getTotalWinnings());
755-
statsConfig.set(path + "blackjacks", stats.getBlackjacks());
756-
statsConfig.set(path + "busts", stats.getBusts());
749+
GenericUtils.savePlayerStats(statsConfig, entry.getKey(), entry.getValue());
757750
}
758751

759752
try {

src/main/java/com/vortex/blackjack/commands/BetCommand.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.vortex.blackjack.commands;
22

33
import com.vortex.blackjack.BlackjackPlugin;
4+
import com.vortex.blackjack.util.ChatUtils;
45
import org.bukkit.command.Command;
56
import org.bukkit.command.CommandSender;
67
import org.bukkit.entity.Player;
@@ -12,9 +13,11 @@
1213
*/
1314
public class BetCommand extends BlackjackCommand {
1415
private final BlackjackPlugin plugin;
16+
private final ChatUtils chatUtils;
1517

1618
public BetCommand(BlackjackPlugin plugin) {
1719
this.plugin = plugin;
20+
this.chatUtils = new ChatUtils(plugin.getConfigManager());
1821
}
1922

2023
@Override
@@ -61,6 +64,6 @@ private void showChatBettingOptions(Player player) {
6164
player.sendMessage(plugin.getConfigManager().getMessage("quick-bet-description"));
6265

6366
// Use configurable chat betting options
64-
com.vortex.blackjack.util.ChatUtils.sendBettingOptions(player, plugin.getConfigManager());
67+
chatUtils.sendBettingOptions(player);
6568
}
6669
}

src/main/java/com/vortex/blackjack/config/ConfigManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ private void loadAndValidateConfig() {
8383
public boolean areParticlesEnabled() { return particlesEnabled; }
8484
public boolean shouldHitSoft17() { return hitSoft17; }
8585

86+
// Auto-leave settings
87+
public int getAutoLeaveTimeoutSeconds() {
88+
return Math.max(10, config.getInt("game.auto-leave-timeout-seconds", 30));
89+
}
90+
8691
// Quick bet settings
8792
public java.util.List<Integer> getSmallBets() {
8893
return config.getIntegerList("betting.quick-bets.small");

src/main/java/com/vortex/blackjack/game/BlackjackEngine.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class BlackjackEngine {
1313
* @param hand List of cards in the hand
1414
* @return The best possible value (handling Aces optimally)
1515
*/
16-
public static int calculateHandValue(List<Card> hand) {
16+
public int calculateHandValue(List<Card> hand) {
1717
int value = 0;
1818
int aces = 0;
1919

@@ -39,21 +39,21 @@ public static int calculateHandValue(List<Card> hand) {
3939
/**
4040
* Check if a hand is a blackjack (21 with exactly 2 cards)
4141
*/
42-
public static boolean isBlackjack(List<Card> hand) {
42+
public boolean isBlackjack(List<Card> hand) {
4343
return hand.size() == 2 && calculateHandValue(hand) == 21;
4444
}
4545

4646
/**
4747
* Check if a hand is busted (over 21)
4848
*/
49-
public static boolean isBusted(List<Card> hand) {
49+
public boolean isBusted(List<Card> hand) {
5050
return calculateHandValue(hand) > 21;
5151
}
5252

5353
/**
5454
* Check if dealer should hit (less than 17, or soft 17 depending on rules)
5555
*/
56-
public static boolean dealerShouldHit(List<Card> hand, boolean hitSoft17) {
56+
public boolean dealerShouldHit(List<Card> hand, boolean hitSoft17) {
5757
int value = calculateHandValue(hand);
5858

5959
if (value < 17) {
@@ -71,7 +71,7 @@ public static boolean dealerShouldHit(List<Card> hand, boolean hitSoft17) {
7171
/**
7272
* Check if hand is a soft 17 (Ace + 6, or Ace + 5 + Ace, etc.)
7373
*/
74-
private static boolean isSoft17(List<Card> hand) {
74+
private boolean isSoft17(List<Card> hand) {
7575
if (calculateHandValue(hand) != 17) {
7676
return false;
7777
}
@@ -95,7 +95,7 @@ private static boolean isSoft17(List<Card> hand) {
9595
/**
9696
* Determine game outcome for a player vs dealer
9797
*/
98-
public static GameResult determineResult(List<Card> playerHand, List<Card> dealerHand) {
98+
public GameResult determineResult(List<Card> playerHand, List<Card> dealerHand) {
9999
int playerValue = calculateHandValue(playerHand);
100100
int dealerValue = calculateHandValue(dealerHand);
101101

src/main/java/com/vortex/blackjack/integration/BlackjackPlaceholderExpansion.java

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.vortex.blackjack.integration;
22

33
import com.vortex.blackjack.BlackjackPlugin;
4+
import com.vortex.blackjack.model.PlayerStats;
45
import com.vortex.blackjack.table.BlackjackTable;
6+
import com.vortex.blackjack.util.GenericUtils;
57
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
68
import org.bukkit.configuration.file.FileConfiguration;
79
import org.bukkit.configuration.file.YamlConfiguration;
@@ -108,34 +110,23 @@ private String handleStatsPlaceholder(Player player, String param) {
108110
return param.equals("has_played") ? "false" : "0";
109111
}
110112

111-
// Load all stats from file
112-
int handsWon = statsConfig.getInt(path + "handsWon", 0);
113-
int handsLost = statsConfig.getInt(path + "handsLost", 0);
114-
int handsPushed = statsConfig.getInt(path + "handsPushed", 0);
115-
int currentStreak = statsConfig.getInt(path + "currentStreak", 0);
116-
int bestStreak = statsConfig.getInt(path + "bestStreak", 0);
117-
double totalWinnings = statsConfig.getDouble(path + "totalWinnings", 0.0);
118-
int blackjacks = statsConfig.getInt(path + "blackjacks", 0);
119-
int busts = statsConfig.getInt(path + "busts", 0);
120-
121-
// Calculate derived values
122-
int totalHands = handsWon + handsLost + handsPushed;
123-
double winRate = totalHands > 0 ? (double) handsWon / totalHands * 100 : 0.0;
113+
// Use generic method to load player stats
114+
PlayerStats stats = GenericUtils.loadPlayerStats(statsConfig, player.getUniqueId());
124115

125116
return switch (param) {
126-
case "hands_won" -> String.valueOf(handsWon);
127-
case "hands_lost" -> String.valueOf(handsLost);
128-
case "hands_pushed" -> String.valueOf(handsPushed);
129-
case "total_hands" -> String.valueOf(totalHands);
130-
case "blackjacks" -> String.valueOf(blackjacks);
131-
case "busts" -> String.valueOf(busts);
132-
case "current_streak" -> String.valueOf(currentStreak);
133-
case "best_streak" -> String.valueOf(bestStreak);
134-
case "win_rate" -> percentFormat.format(winRate);
135-
case "win_rate_raw" -> decimalFormat.format(winRate / 100);
136-
case "total_winnings" -> decimalFormat.format(totalWinnings);
137-
case "total_winnings_formatted" -> formatMoney(totalWinnings);
138-
case "has_played" -> totalHands > 0 ? "true" : "false";
117+
case "hands_won" -> String.valueOf(stats.getHandsWon());
118+
case "hands_lost" -> String.valueOf(stats.getHandsLost());
119+
case "hands_pushed" -> String.valueOf(stats.getHandsPushed());
120+
case "total_hands" -> String.valueOf(stats.getTotalHands());
121+
case "blackjacks" -> String.valueOf(stats.getBlackjacks());
122+
case "busts" -> String.valueOf(stats.getBusts());
123+
case "current_streak" -> String.valueOf(stats.getCurrentStreak());
124+
case "best_streak" -> String.valueOf(stats.getBestStreak());
125+
case "win_rate" -> percentFormat.format(stats.getWinRate());
126+
case "win_rate_raw" -> decimalFormat.format(stats.getWinRate() / 100);
127+
case "total_winnings" -> decimalFormat.format(stats.getTotalWinnings());
128+
case "total_winnings_formatted" -> formatMoney(stats.getTotalWinnings());
129+
case "has_played" -> stats.getTotalHands() > 0 ? "true" : "false";
139130
default -> "0";
140131
};
141132
}

0 commit comments

Comments
 (0)