Skip to content

Commit

Permalink
✨ Added ability to customize command aliases
Browse files Browse the repository at this point in the history
Took 22 minutes
  • Loading branch information
kiranhart committed Aug 14, 2024
1 parent 16d8483 commit b4bc478
Show file tree
Hide file tree
Showing 25 changed files with 217 additions and 229 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import ca.tweetzy.auctionhouse.guis.core.GUIActiveAuctions;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.commands.AbstractCommand;
import ca.tweetzy.core.utils.TextUtils;
import org.bukkit.Bukkit;
Expand All @@ -38,7 +39,7 @@
public class CommandActive extends AbstractCommand {

public CommandActive() {
super(CommandType.PLAYER_ONLY, "active");
super(CommandType.PLAYER_ONLY, Settings.CMD_ALIAS_SUB_ACTIVE.getStringList().toArray(new String[0]));
}

@Override
Expand All @@ -47,12 +48,11 @@ protected ReturnType runCommand(CommandSender sender, String... args) {

if (CommandMiddleware.handle(player) == ReturnType.FAILURE) return ReturnType.FAILURE;

final AuctionHouse instance = AuctionHouse.getInstance();
if (instance.getAuctionPlayerManager().getPlayer(player.getUniqueId()) == null) {
instance.getLocale().newMessage(TextUtils.formatText("&cCould not find auction player instance for&f: &e" + player.getName() + "&c creating one now.")).sendPrefixedMessage(Bukkit.getConsoleSender());
instance.getAuctionPlayerManager().addPlayer(new AuctionPlayer(player));
if (AuctionHouse.getAuctionPlayerManager().getPlayer(player.getUniqueId()) == null) {
AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&cCould not find auction player instance for&f: &e" + player.getName() + "&c creating one now.")).sendPrefixedMessage(Bukkit.getConsoleSender());
AuctionHouse.getAuctionPlayerManager().addPlayer(new AuctionPlayer(player));
}
instance.getGuiManager().showGUI(player, new GUIActiveAuctions(instance.getAuctionPlayerManager().getPlayer(player.getUniqueId())));
AuctionHouse.getGuiManager().showGUI(player, new GUIActiveAuctions(AuctionHouse.getAuctionPlayerManager().getPlayer(player.getUniqueId())));
return ReturnType.SUCCESS;
}

Expand Down
69 changes: 34 additions & 35 deletions src/main/java/ca/tweetzy/auctionhouse/commands/CommandAdmin.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,23 @@
public class CommandAdmin extends AbstractCommand {

public CommandAdmin() {
super(CommandType.CONSOLE_OK, "admin");
super(CommandType.CONSOLE_OK, Settings.CMD_ALIAS_SUB_ADMIN.getStringList().toArray(new String[0]));
}

@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length < 1) return ReturnType.FAILURE;
if (AuctionAPI.tellMigrationStatus(sender)) return ReturnType.FAILURE;

final AuctionHouse instance = AuctionHouse.getInstance();
switch (args[0].toLowerCase()) {
case "logs":
if (!(sender instanceof Player)) break;
Player player = (Player) sender;
if (!player.hasPermission("auctionhouse.cmd.admin.logs")) return ReturnType.FAILURE;

instance.getDataManager().getAdminLogs((error, logs) -> {
AuctionHouse.getDataManager().getAdminLogs((error, logs) -> {
if (error == null)
AuctionHouse.newChain().sync(() -> instance.getGuiManager().showGUI(player, new GUIAdminLogs(player, logs))).execute();
AuctionHouse.newChain().sync(() -> AuctionHouse.getGuiManager().showGUI(player, new GUIAdminLogs(player, logs))).execute();
else
error.printStackTrace();
});
Expand All @@ -98,42 +97,42 @@ protected ReturnType runCommand(CommandSender sender, String... args) {
}

if (target == null) {
instance.getLocale().getMessage("general.playernotfound").processPlaceholder("player", args[1]).sendPrefixedMessage(sender);
AuctionHouse.getInstance().getLocale().getMessage("general.playernotfound").processPlaceholder("player", args[1]).sendPrefixedMessage(sender);
return ReturnType.FAILURE;
}

instance.getGuiManager().showGUI(player, new GUIAdminExpired(player, target));
AuctionHouse.getGuiManager().showGUI(player, new GUIAdminExpired(player, target));

break;
case "endall":
if (!sender.hasPermission("auctionhouse.cmd.admin.endall")) return ReturnType.FAILURE;
for (UUID id : instance.getAuctionItemManager().getItems().keySet()) {
instance.getAuctionItemManager().getItems().get(id).setExpired(true);
for (UUID id : AuctionHouse.getAuctionItemManager().getItems().keySet()) {
AuctionHouse.getAuctionItemManager().getItems().get(id).setExpired(true);
}
instance.getLocale().getMessage("general.endedallauctions").sendPrefixedMessage(sender);
AuctionHouse.getInstance().getLocale().getMessage("general.endedallauctions").sendPrefixedMessage(sender);
break;
case "bans":
if (!(sender instanceof Player)) break;
player = (Player) sender;
if (!player.hasPermission("auctionhouse.cmd.admin.bans")) return ReturnType.FAILURE;
instance.getGuiManager().showGUI(player, new GUIBans(player));
AuctionHouse.getGuiManager().showGUI(player, new GUIBans(player));
break;
case "relistall":
if (!sender.hasPermission("auctionhouse.cmd.admin.relistall")) return ReturnType.FAILURE;
for (UUID id : instance.getAuctionItemManager().getItems().keySet()) {
if (instance.getAuctionItemManager().getItems().get(id).isExpired()) {
int relistTime = args.length == 1 ? instance.getAuctionItemManager().getItems().get(id).isBidItem() ? Settings.DEFAULT_AUCTION_LISTING_TIME.getInt() : Settings.DEFAULT_BIN_LISTING_TIME.getInt() : Integer.parseInt(args[1]);
for (UUID id : AuctionHouse.getAuctionItemManager().getItems().keySet()) {
if (AuctionHouse.getAuctionItemManager().getItems().get(id).isExpired()) {
int relistTime = args.length == 1 ? AuctionHouse.getAuctionItemManager().getItems().get(id).isBidItem() ? Settings.DEFAULT_AUCTION_LISTING_TIME.getInt() : Settings.DEFAULT_BIN_LISTING_TIME.getInt() : Integer.parseInt(args[1]);

instance.getAuctionItemManager().getItems().get(id).setExpiresAt(System.currentTimeMillis() + 1000L * relistTime);
instance.getAuctionItemManager().getItems().get(id).setExpired(false);
AuctionHouse.getAuctionItemManager().getItems().get(id).setExpiresAt(System.currentTimeMillis() + 1000L * relistTime);
AuctionHouse.getAuctionItemManager().getItems().get(id).setExpired(false);
}
}
instance.getLocale().getMessage("general.relisteditems").sendPrefixedMessage(sender);
AuctionHouse.getInstance().getLocale().getMessage("general.relisteditems").sendPrefixedMessage(sender);
break;
case "clearall":
if (!sender.hasPermission("auctionhouse.cmd.admin.clearall")) return ReturnType.FAILURE;
// Don't tell ppl that this exists
instance.getAuctionItemManager().getItems().clear();
AuctionHouse.getAuctionItemManager().getItems().clear();
break;
case "clear":
if (args.length < 4) return ReturnType.FAILURE;
Expand Down Expand Up @@ -171,29 +170,29 @@ protected ReturnType runCommand(CommandSender sender, String... args) {
ItemStack itemToSell = PlayerHelper.getHeldItem(player).clone();

if (itemToSell.getType() == XMaterial.AIR.parseMaterial() && Settings.SELL_MENU_REQUIRES_USER_TO_HOLD_ITEM.getBoolean()) {
instance.getLocale().getMessage("general.air").sendPrefixedMessage(player);
AuctionHouse.getInstance().getLocale().getMessage("general.air").sendPrefixedMessage(player);
return ReturnType.FAILURE;
} else {
final AuctionPlayer auctionPlayer = instance.getAuctionPlayerManager().getPlayer(player.getUniqueId());
final AuctionPlayer auctionPlayer = AuctionHouse.getAuctionPlayerManager().getPlayer(player.getUniqueId());

if (Settings.SELL_MENU_SKIPS_TYPE_SELECTION.getBoolean()) {
if (Settings.FORCE_AUCTION_USAGE.getBoolean()) {
AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUISellPlaceItem(auctionPlayer, GUISellPlaceItem.ViewMode.SINGLE_ITEM, ListingType.AUCTION));
AuctionHouse.getGuiManager().showGUI(player, new GUISellPlaceItem(auctionPlayer, GUISellPlaceItem.ViewMode.SINGLE_ITEM, ListingType.AUCTION));
return ReturnType.SUCCESS;
}

if (!Settings.ALLOW_USAGE_OF_BID_SYSTEM.getBoolean()) {
AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUISellPlaceItem(auctionPlayer, GUISellPlaceItem.ViewMode.SINGLE_ITEM, ListingType.BIN));
AuctionHouse.getGuiManager().showGUI(player, new GUISellPlaceItem(auctionPlayer, GUISellPlaceItem.ViewMode.SINGLE_ITEM, ListingType.BIN));
return ReturnType.SUCCESS;
}

AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUISellListingType(auctionPlayer, selected -> {
AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUISellPlaceItem(auctionPlayer, GUISellPlaceItem.ViewMode.SINGLE_ITEM, selected));
AuctionHouse.getGuiManager().showGUI(player, new GUISellListingType(auctionPlayer, selected -> {
AuctionHouse.getGuiManager().showGUI(player, new GUISellPlaceItem(auctionPlayer, GUISellPlaceItem.ViewMode.SINGLE_ITEM, selected));
}));

} else {
instance.getGuiManager().showGUI(player, new GUISellListingType(auctionPlayer, selected -> {
instance.getGuiManager().showGUI(player, new GUISellPlaceItem(auctionPlayer, GUISellPlaceItem.ViewMode.SINGLE_ITEM, selected));
AuctionHouse.getGuiManager().showGUI(player, new GUISellListingType(auctionPlayer, selected -> {
AuctionHouse.getGuiManager().showGUI(player, new GUISellPlaceItem(auctionPlayer, GUISellPlaceItem.ViewMode.SINGLE_ITEM, selected));
}));
}
}
Expand All @@ -207,12 +206,12 @@ protected ReturnType runCommand(CommandSender sender, String... args) {

if (CommandMiddleware.handle(player) == ReturnType.FAILURE) return ReturnType.FAILURE;

if (instance.getAuctionPlayerManager().getPlayer(player.getUniqueId()) == null) {
instance.getLocale().newMessage(TextUtils.formatText("&cCould not find auction player instance for&f: &e" + player.getName() + "&c creating one now.")).sendPrefixedMessage(Bukkit.getConsoleSender());
instance.getAuctionPlayerManager().addPlayer(new AuctionPlayer(player));
if (AuctionHouse.getAuctionPlayerManager().getPlayer(player.getUniqueId()) == null) {
AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&cCould not find auction player instance for&f: &e" + player.getName() + "&c creating one now.")).sendPrefixedMessage(Bukkit.getConsoleSender());
AuctionHouse.getAuctionPlayerManager().addPlayer(new AuctionPlayer(player));
}

instance.getGuiManager().showGUI(player, new GUIAuctionHouse(instance.getAuctionPlayerManager().getPlayer(player.getUniqueId())));
AuctionHouse.getGuiManager().showGUI(player, new GUIAuctionHouse(AuctionHouse.getAuctionPlayerManager().getPlayer(player.getUniqueId())));
break;
}

Expand Down Expand Up @@ -244,15 +243,15 @@ public String getDescription() {
}

private void handleUserBidClear(final Player player, final boolean returnMoney) {
final List<AuctionedItem> items = AuctionHouse.getInstance().getAuctionItemManager().getHighestBidItems(player);
final List<AuctionedItem> items = AuctionHouse.getAuctionItemManager().getHighestBidItems(player);

for (AuctionedItem auctionedItem : items) {
auctionedItem.setHighestBidder(auctionedItem.getOwner());
auctionedItem.setHighestBidderName(auctionedItem.getOwnerName());

if (returnMoney && Settings.BIDDING_TAKES_MONEY.getBoolean())
if (Settings.STORE_PAYMENTS_FOR_MANUAL_COLLECTION.getBoolean())
AuctionHouse.getInstance().getDataManager().insertAuctionPayment(new AuctionPayment(
AuctionHouse.getDataManager().insertAuctionPayment(new AuctionPayment(
player.getUniqueId(),
auctionedItem.getCurrentPrice(),
auctionedItem.getItem(),
Expand All @@ -265,13 +264,13 @@ private void handleUserBidClear(final Player player, final boolean returnMoney)
}

private void handleUserClear(final Player player, final boolean returnBids, final boolean giveItemsBack) {
final AuctionPlayer auctionPlayer = AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId());
final AuctionPlayer auctionPlayer = AuctionHouse.getAuctionPlayerManager().getPlayer(player.getUniqueId());
final List<AuctionedItem> items = auctionPlayer.getAllItems();

for (AuctionedItem auctionItem : items) {
if (auctionItem.isExpired()) {
if (!giveItemsBack)
AuctionHouse.getInstance().getAuctionItemManager().sendToGarbage(auctionItem);
AuctionHouse.getAuctionItemManager().sendToGarbage(auctionItem);
continue;
}

Expand All @@ -280,7 +279,7 @@ private void handleUserClear(final Player player, final boolean returnBids, fina
final OfflinePlayer oldBidder = Bukkit.getOfflinePlayer(auctionItem.getHighestBidder());

if (Settings.STORE_PAYMENTS_FOR_MANUAL_COLLECTION.getBoolean())
AuctionHouse.getInstance().getDataManager().insertAuctionPayment(new AuctionPayment(
AuctionHouse.getDataManager().insertAuctionPayment(new AuctionPayment(
oldBidder.getUniqueId(),
auctionItem.getCurrentPrice(),
auctionItem.getItem(),
Expand All @@ -300,7 +299,7 @@ private void handleUserClear(final Player player, final boolean returnBids, fina
auctionItem.setExpiresAt(System.currentTimeMillis());
auctionItem.setExpired(true);
} else {
AuctionHouse.getInstance().getAuctionItemManager().sendToGarbage(auctionItem);
AuctionHouse.getAuctionItemManager().sendToGarbage(auctionItem);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import ca.tweetzy.auctionhouse.guis.core.GUIAuctionHouse;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.commands.AbstractCommand;
import ca.tweetzy.core.utils.TextUtils;
import org.apache.commons.lang.StringUtils;
Expand All @@ -40,7 +41,7 @@
public class CommandAuctionHouse extends AbstractCommand {

public CommandAuctionHouse() {
super(CommandType.PLAYER_ONLY, "auctionhouse");
super(CommandType.PLAYER_ONLY, Settings.CMD_ALIAS_MAIN.getStringList().toArray(new String[0]));
}

@Override
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/ca/tweetzy/auctionhouse/commands/CommandBan.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.guis.admin.bans.GUIBanUser;
import ca.tweetzy.auctionhouse.guis.selector.GUIPlayerSelector;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.commands.AbstractCommand;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
Expand All @@ -38,40 +39,39 @@
public class CommandBan extends AbstractCommand {

public CommandBan() {
super(CommandType.PLAYER_ONLY, "ban");
super(CommandType.PLAYER_ONLY, Settings.CMD_ALIAS_SUB_BAN.getStringList().toArray(new String[0]));
}

@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
final Player player = (Player) sender;
final AuctionHouse instance = AuctionHouse.getInstance();

if (args.length == 0) {
// open the player picker then redirect to the ban user menu
instance.getGuiManager().showGUI(player, new GUIPlayerSelector(player, selected -> {
if (instance.getBanManager().isBannedAlready(selected)) {
instance.getLocale().getMessage("ban.user already banned").processPlaceholder("player_name", selected.getName()).sendPrefixedMessage(player);
AuctionHouse.getGuiManager().showGUI(player, new GUIPlayerSelector(player, selected -> {
if (AuctionHouse.getBanManager().isBannedAlready(selected)) {
AuctionHouse.getInstance().getLocale().getMessage("ban.user already banned").processPlaceholder("player_name", selected.getName()).sendPrefixedMessage(player);
return;
}

instance.getGuiManager().showGUI(player, new GUIBanUser(player, instance.getBanManager().generateEmptyBan(player, selected)));
AuctionHouse.getGuiManager().showGUI(player, new GUIBanUser(player, AuctionHouse.getBanManager().generateEmptyBan(player, selected)));
}));
return ReturnType.SUCCESS;
}

final Player target = Bukkit.getPlayerExact(args[0]);

if (target == null) {
instance.getLocale().getMessage("general.playernotfound").processPlaceholder("player", args[0]).sendPrefixedMessage(player);
AuctionHouse.getInstance().getLocale().getMessage("general.playernotfound").processPlaceholder("player", args[0]).sendPrefixedMessage(player);
return ReturnType.FAILURE;
}

if (instance.getBanManager().isBannedAlready(target)) {
instance.getLocale().getMessage("ban.user already banned").processPlaceholder("player_name", args[0]).sendPrefixedMessage(player);
if (AuctionHouse.getBanManager().isBannedAlready(target)) {
AuctionHouse.getInstance().getLocale().getMessage("ban.user already banned").processPlaceholder("player_name", args[0]).sendPrefixedMessage(player);
return ReturnType.FAILURE;
}

instance.getGuiManager().showGUI(player, new GUIBanUser(player, instance.getBanManager().generateEmptyBan(player, target)));
AuctionHouse.getGuiManager().showGUI(player, new GUIBanUser(player, AuctionHouse.getBanManager().generateEmptyBan(player, target)));
return ReturnType.SUCCESS;
}

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/ca/tweetzy/auctionhouse/commands/CommandBids.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import ca.tweetzy.auctionhouse.guis.core.bid.GUIActiveBids;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.commands.AbstractCommand;
import ca.tweetzy.core.utils.TextUtils;
import org.bukkit.Bukkit;
Expand All @@ -38,7 +39,7 @@
public class CommandBids extends AbstractCommand {

public CommandBids() {
super(CommandType.PLAYER_ONLY, "bids");
super(CommandType.PLAYER_ONLY, Settings.CMD_ALIAS_SUB_BIDS.getStringList().toArray(new String[0]));
}

@Override
Expand All @@ -47,12 +48,11 @@ protected ReturnType runCommand(CommandSender sender, String... args) {

if (CommandMiddleware.handle(player) == ReturnType.FAILURE) return ReturnType.FAILURE;

final AuctionHouse instance = AuctionHouse.getInstance();
if (instance.getAuctionPlayerManager().getPlayer(player.getUniqueId()) == null) {
instance.getLocale().newMessage(TextUtils.formatText("&cCould not find auction player instance for&f: &e" + player.getName() + "&c creating one now.")).sendPrefixedMessage(Bukkit.getConsoleSender());
instance.getAuctionPlayerManager().addPlayer(new AuctionPlayer(player));
if (AuctionHouse.getAuctionPlayerManager().getPlayer(player.getUniqueId()) == null) {
AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&cCould not find auction player instance for&f: &e" + player.getName() + "&c creating one now.")).sendPrefixedMessage(Bukkit.getConsoleSender());
AuctionHouse.getAuctionPlayerManager().addPlayer(new AuctionPlayer(player));
}
instance.getGuiManager().showGUI(player, new GUIActiveBids(instance.getAuctionPlayerManager().getPlayer(player.getUniqueId())));
AuctionHouse.getGuiManager().showGUI(player, new GUIActiveBids(AuctionHouse.getAuctionPlayerManager().getPlayer(player.getUniqueId())));
return ReturnType.SUCCESS;
}

Expand Down
Loading

0 comments on commit b4bc478

Please sign in to comment.