Skip to content

Commit

Permalink
1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
TFAGaming committed Sep 11, 2024
1 parent 96dddf4 commit d06a048
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 26 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
target/
.vscode/
.vscode/
effective-pom.xml
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# SimpleShopGUI

**SimpleShopGUI** is a simple and user-friendly Minecraft shop plugin based on GUIs. Players can browse through a wide range of items, each organized into specific categories and types, making it easier to find exactly what they're looking for.
**SimpleShopGUI** is a simple and user-friendly Minecraft shop plugin based on GUIs. Players can browse a wide range of items, each organized into specific categories and types, making finding exactly what they're looking for easier.

The current database is **SQLite**, other providers are still unsupported.

YouTube video: https://www.youtube.com/watch?v=2oxVJxw8HZE

## Features

- Open-source
Expand All @@ -30,7 +32,7 @@ Expired items are not gone forever, they will stay as an item in the shop, but n

## Commands

- `/shop`: Opens a GUI with all available categories in the shop.
- `/shop (category)`: Opens a GUI with all available categories in the shop.
- `/listed`: View all items that you are currently selling and the expired ones.
- `/sell [price]`: Sell an item that you are currently holding with your hand.

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>simpleshopgui</groupId>
<artifactId>simpleshopgui</artifactId>
<version>1.0.1</version>
<version>1.1.0</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/simpleshopgui/Plugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void onDisable() {
}

public static String getVersion() {
return "1.0.1";
return "1.1.0";
}

private void disablePlugin() {
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/simpleshopgui/commands/SellCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
return true;
}

if (Plugin.config.getStringList("banned_items").contains(itemInHand.getType().name())) {
player.sendMessage(ChatColorTranslator
.translate(Plugin.config.getString("messages.commands.sell.item_is_banned")));
return true;
}

if (args.length == 0) {
player.sendMessage(ChatColorTranslator
.translate(Plugin.config.getString("messages.commands.sell.no_price_provided")));
Expand Down Expand Up @@ -100,7 +106,7 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
return Lists.newArrayList();
}

return Lists.newArrayList(ShopUtils.parseFromDoubleToString(parsed).replace(",", "."));
return Lists.newArrayList(ShopUtils.parseFromDoubleToString(parsed));
}

return Lists.newArrayList();
Expand Down
71 changes: 67 additions & 4 deletions src/main/java/simpleshopgui/commands/ShopCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,71 @@

import simpleshopgui.Plugin;
import simpleshopgui.gui.ShopGUI;
import simpleshopgui.gui.ShopGUIBuildingBlocks;
import simpleshopgui.gui.ShopGUIFood;
import simpleshopgui.gui.ShopGUIMinerals;
import simpleshopgui.gui.ShopGUIMiscellaneous;
import simpleshopgui.gui.ShopGUINatural;
import simpleshopgui.gui.ShopGUIRedstone;
import simpleshopgui.gui.ShopGUITools;
import simpleshopgui.utils.colors.ChatColorTranslator;
import simpleshopgui.utils.players.PlayerUtils;
import simpleshopgui.utils.shop.ShopUtils;

public class ShopCommand implements TabExecutor {
private List<String> availableCategories = Lists.newArrayList("Blocks", "Tools", "Food", "Minerals", "Natural",
"Redstone", "Miscellaneous");

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof Player) {
Player player = (Player) sender;

if (!PlayerUtils.hasPermission(player, "shop")) {
player.sendMessage(ChatColorTranslator
player.sendMessage(ChatColorTranslator
.translate(Plugin.config.getString("messages.permission_error")));
return true;
return true;
}

ShopGUI gui = new ShopGUI(player);
if (args.length == 1) {
if (!availableCategories.contains(args[0])) {
player.sendMessage(ChatColorTranslator
.translate(Plugin.config.getString("messages.commands.shop.invalid_category")));
return true;
}

switch (args[0]) {
case "Blocks":
ShopGUIBuildingBlocks.create(player);
break;
case "Tools":
ShopGUITools.create(player);
break;
case "Food":
ShopGUIFood.create(player);
break;
case "Minerals":
ShopGUIMinerals.create(player);
break;
case "Natural":
ShopGUINatural.create(player);
break;
case "Redstone":
ShopGUIRedstone.create(player);
break;
case "Miscellaneous":
ShopGUIMiscellaneous.create(player);
break;
default:
break;
}

ShopUtils.playerTriggerEvent.put(player.getUniqueId(), true);
} else {
ShopGUI gui = new ShopGUI(player);

gui.openInventory();
gui.openInventory();
}

return true;
}
Expand All @@ -38,6 +85,22 @@ public boolean onCommand(CommandSender sender, Command command, String label, St

@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
if (args.length == 1) {
if (args[0].length() <= 0) {
return availableCategories;
}

List<String> finalList = Lists.newArrayList();

for (String category : availableCategories) {
if (category.toLowerCase().startsWith(args[0].toLowerCase())) {
finalList.add(category);
}
}

return finalList;
}

return Lists.newArrayList();
}
}
4 changes: 2 additions & 2 deletions src/main/java/simpleshopgui/events/gui/NormalGUIListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void onClick(InventoryClickEvent event) {
break;
}

ShopUtils.playerTriggerBuy.put(player.getUniqueId(), false);
ShopUtils.playerTriggerEvent.put(player.getUniqueId(), false);
} else if (ShopUtils.getCurrentInventoryId(player) == 4) {
event.setCancelled(true);

Expand Down Expand Up @@ -238,7 +238,7 @@ public void onClose(InventoryCloseEvent event) {
Player player = (Player) event.getPlayer();

ShopUtils.removeCurrentInventoryId(player);
ShopUtils.playerTriggerBuy.remove(player.getUniqueId());
ShopUtils.playerTriggerEvent.remove(player.getUniqueId());
}

private void deletePlayerData(Player player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ public void onClick(InventoryClickEvent event) {

gui.openInventory();

ShopUtils.playerTriggerBuy.put(player.getUniqueId(), false);
ShopUtils.playerTriggerEvent.put(player.getUniqueId(), false);
} else {
pagegui.previousPage();
}
} else if (event.getSlot() == last_index_last_line) {
pagegui.nextPage();
} else {
if (ShopUtils.playerTriggerBuy.containsKey(player.getUniqueId()) && !ShopUtils.playerTriggerBuy.get(player.getUniqueId())) {
ShopUtils.playerTriggerBuy.put(player.getUniqueId(), true);
if (ShopUtils.playerTriggerEvent.containsKey(player.getUniqueId()) && !ShopUtils.playerTriggerEvent.get(player.getUniqueId())) {
ShopUtils.playerTriggerEvent.put(player.getUniqueId(), true);
} else {
ShopUtils.playerTriggerBuy.put(player.getUniqueId(), false);
ShopUtils.playerTriggerEvent.put(player.getUniqueId(), false);

SpecificItemsGUIListener.listen(event, player, pagegui,
ShopGUI.playerCurrentCategory.get(player.getUniqueId()));
Expand All @@ -90,7 +90,7 @@ public void onClick(InventoryClickEvent event) {
if (event.getSlot() == first_index_last_line_3) {
if (pagegui_3.getPage() == 0) {
if (ShopGUI.playerCurrentCategory.containsKey(player.getUniqueId())) {
ShopUtils.playerTriggerBuy.put(player.getUniqueId(), false);
ShopUtils.playerTriggerEvent.put(player.getUniqueId(), false);
ShopGUI.playerCurrentMaterial.remove(player.getUniqueId());

switch (ShopGUI.playerCurrentCategory.get(player.getUniqueId())) {
Expand Down Expand Up @@ -119,7 +119,7 @@ public void onClick(InventoryClickEvent event) {
break;
}
} else {
ShopUtils.playerTriggerBuy.put(player.getUniqueId(), false);
ShopUtils.playerTriggerEvent.put(player.getUniqueId(), false);
ShopGUI.playerCurrentCategory.remove(player.getUniqueId());
ShopGUI.playerCurrentMaterial.remove(player.getUniqueId());

Expand All @@ -128,7 +128,7 @@ public void onClick(InventoryClickEvent event) {
gui.openInventory();
}

// ShopUtils.playerTriggerBuy.put(player.getUniqueId(), false);
// ShopUtils.playerTriggerEvent.put(player.getUniqueId(), false);
} else {
pagegui_3.previousPage();
}
Expand Down Expand Up @@ -183,7 +183,7 @@ public void onClose(InventoryCloseEvent event) {

//ShopGUI.playerCurrentCategory.remove(player.getUniqueId());

//ShopUtils.playerTriggerBuy.remove(player.getUniqueId());
//ShopUtils.playerTriggerEvent.remove(player.getUniqueId());
}
}
}
7 changes: 3 additions & 4 deletions src/main/java/simpleshopgui/utils/shop/ShopUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import simpleshopgui.Plugin;

public class ShopUtils {
public static Map<UUID, Boolean> playerTriggerBuy = new HashMap<UUID, Boolean>();
public static Map<UUID, Boolean> playerTriggerEvent = new HashMap<UUID, Boolean>();
public static Map<UUID, Integer> inventoryCache = new HashMap<UUID, Integer>();

public static void setCurrentInventoryId(Player player, int id) {
Expand All @@ -43,9 +43,11 @@ public static int getCurrentInventoryId(Player player) {

public static String userFriendlyItemName(String input) {
String output = "";

for (String s : input.split("_")) {
output += s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase() + " ";
}

return output.substring(0, output.length() - 1);
}

Expand Down Expand Up @@ -129,9 +131,6 @@ public static String getTimeRemaining(double futureTimeMillis) {

long seconds = (long) (timeDifference / 1000);

// return String.format("%d days, %d hours, %d minutes, %d seconds", days,
// hours, minutes, seconds);

return Plugin.config.getString("shop.time_remaining_format")
.replace("%seconds%", "" + seconds).replace("%minutes%", "" + minutes)
.replace("%hours%", "" + hours).replace("%days%", "" + days);
Expand Down
15 changes: 14 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ database:

shop:
max_items_duration: 604800000 # 1 week
show_buy_notification: true
show_buy_notification: true # Show notification to sellers when there is a player bought one of their items (true = Enable, false = Disable)
time_remaining_format: "%days% days, %hours% hours, %minutes% minutes, %seconds% seconds"
max_item_price: 100000000000000000000 # 10000,0Q

# The items that are not allowed to be listed in shop
banned_items:
- BEDROCK
- COMMAND_BLOCK

# Set each rank with a custom limit
# • max_listed_items (integer): The maximum items that the player can list in the shop
ranks:
default:
max_listed_items: 4
Expand All @@ -21,6 +28,7 @@ ranks:
owner:
max_listed_items: 100

# GUIs configuration
gui:
__CONFIG_PAGINATION__:
PREVIOUS_PAGE:
Expand Down Expand Up @@ -178,15 +186,20 @@ gui:
- ""
- "&7Click to Remove"

# Messages configuration
messages:
commands:
sell:
no_item_in_hand: "&8[&9Shop&8] &cYou are not holding an item to sell!"
item_is_banned: "&8[&9Shop&8] &cThis item is not allowed to be on shop!"
no_price_provided: "&8[&9Shop&8] &cYou must provide the price of the item! &7/sell [price]"
price_error: "&8[&9Shop&8] &cThe price of the item must be a positive integer and/or end with a valid suffix (k, M, B, T, or Q)."
price_over_max: "&8[&9Shop&8] &cToo expensive! The maximum price is %max_price%."
max_listed_items_reached: "&8[&9Shop&8] &cYou cannot sell more items! Upgrade to Premium to unlock more features."
item_sold: "&8[&9Shop&8] &aThe item &b%item_amount%x %item_name% &ais now listed in the shop!"

shop:
invalid_category: "&8[&9Shop&8] &cInvalid category!"

guis:
buy:
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: SimpleShopGUI
main: simpleshopgui.Plugin
version: 1.0.1
version: 1.1.0
api-version: 1.21.1
softdepend: [Vault]
commands:
Expand Down

0 comments on commit d06a048

Please sign in to comment.