Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import dev.jorel.commandapi.CommandPermission;
import org.simpmc.simppay.SPPlugin;
import org.simpmc.simppay.menu.card.CardListView;
import org.simpmc.simppay.util.FloodgateUtil;

public class NaptheCommand {

Expand All @@ -12,12 +13,12 @@ public NaptheCommand() {
.withPermission(CommandPermission.NONE)
.executesPlayer((player, args) -> {
// start a new napthe session
boolean isFloodgateUUID = player.getUniqueId().getMostSignificantBits() == 0;
boolean floodgateEnabled = SPPlugin.getInstance().isFloodgateEnabled();
if (floodgateEnabled && isFloodgateUUID) {
// Use FloodgateUtil for accurate Bedrock player detection
if (SPPlugin.getInstance().isFloodgateEnabled() && FloodgateUtil.isBedrockPlayer(player)) {
try {
Class<?> naptheFormClass = Class.forName("org.simpmc.simppay.forms.NaptheForm");
Object form = naptheFormClass.getMethod("getNapTheForm", org.bukkit.entity.Player.class).invoke(null, player);
Object form = naptheFormClass.getMethod("getNapTheForm", org.bukkit.entity.Player.class)
.invoke(null, player);

Class<?> floodgateUtilClass = Class.forName("org.simpmc.simppay.util.FloodgateUtil");
floodgateUtilClass.getMethod("sendForm", java.util.UUID.class, Object.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
import org.bukkit.entity.Player;
import org.simpmc.simppay.SPPlugin;
import org.simpmc.simppay.menu.PaymentHistoryView;
import org.simpmc.simppay.util.FloodgateUtil;

public class ViewHistoryCommand {
public ViewHistoryCommand() {
new CommandAPICommand("lichsunapthe")
.withPermission(CommandPermission.NONE)
.withAliases("napthehistory", "xemgdnapthe")
.executesPlayer((player, args) -> {
boolean isFloodgateUUID = player.getUniqueId().getMostSignificantBits() == 0;
boolean floodgateEnabled = SPPlugin.getInstance().isFloodgateEnabled();
if (floodgateEnabled && isFloodgateUUID) {
// Use FloodgateUtil for accurate Bedrock player detection
if (SPPlugin.getInstance().isFloodgateEnabled() && FloodgateUtil.isBedrockPlayer(player)) {
try {
Class<?> viewHistoryFormClass = Class.forName("org.simpmc.simppay.forms.ViewHistoryForm");
Object form = viewHistoryFormClass.getMethod("getHistoryForm", Player.class).invoke(null, player);
Object form = viewHistoryFormClass.getMethod("getHistoryForm", Player.class).invoke(null,
player);

Class<?> floodgateUtilClass = Class.forName("org.simpmc.simppay.util.FloodgateUtil");
floodgateUtilClass.getMethod("sendForm", java.util.UUID.class, Object.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
* Phase 7: Enhanced Floodgate Utility
* <p>
* Provides helper methods for Floodgate integration (Bedrock player support).
* Includes initialization, player detection, and form sending with proper error handling.
* Includes initialization, player detection, and form sending with proper error
* handling.
*/
public class FloodgateUtil {
private static final Logger LOGGER = Logger.getLogger(FloodgateUtil.class.getName());
Expand Down Expand Up @@ -66,20 +67,7 @@ public static boolean isBedrockPlayer(Player player) {
return false;
}

UUID uuid = player.getUniqueId();

// Primary method: Use Floodgate API
if (initialized && floodgateApi != null) {
try {
return floodgateApi.isFloodgatePlayer(uuid);
} catch (Exception e) {
LOGGER.warning("Error checking if player is Bedrock via API: " + e.getMessage());
}
}

// Fallback method: Check UUID pattern
// Floodgate UUIDs have most significant bits set to 0
return uuid.getMostSignificantBits() == 0;
return isBedrockPlayer(player.getUniqueId());
}

/**
Expand All @@ -93,22 +81,29 @@ public static boolean isBedrockPlayer(UUID uuid) {
return false;
}

// Primary method: Use Floodgate API (most reliable)
if (initialized && floodgateApi != null) {
try {
return floodgateApi.isFloodgatePlayer(uuid);
} catch (Exception e) {
LOGGER.warning("Error checking UUID via Floodgate API: " + e.getMessage());
// Only fall back to UUID pattern if API throws exception
return uuid.getMostSignificantBits() == 0;
}
}

// Fallback method: Check UUID pattern
// ONLY used when Floodgate is NOT initialized (plugin not available)
// Floodgate UUIDs have most significant bits set to 0
return uuid.getMostSignificantBits() == 0;
}

/**
* Gets the Bedrock username for a player (without the prefix).
*
* @param player Player to get username for
* @return Bedrock username, or player's regular username if not a Bedrock player
* @return Bedrock username, or player's regular username if not a Bedrock
* player
*/
public static String getBedrockUsername(Player player) {
if (player == null) {
Expand Down