Skip to content

Commit

Permalink
Merge branch 'release/0.2-BETA'
Browse files Browse the repository at this point in the history
  • Loading branch information
BrendonButler committed Aug 26, 2023
2 parents 6367714 + 956d8df commit 21198c4
Show file tree
Hide file tree
Showing 46 changed files with 1,196 additions and 547 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Shops plugin for Bukkit/Spigot 2022+

![Shops social image](https://repository-images.githubusercontent.com/388618586/0d033997-0fcd-44db-a53d-c635f8bc38f5)
![Shops social image](https://repository-images.githubusercontent.com/388618586/2bc0f5a2-80f8-4cc7-859b-962e4d5e773d)

**Depends on:** [Vault](https://github.com/MilkBowl/Vault)

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<name>Shops</name>
<groupId>net.sparkzz</groupId>
<artifactId>shops</artifactId>
<version>0.1-BETA</version>
<version>0.2-BETA</version>
<description>Location based shops plugin for Spigot ${spigot-api.version}</description>
<url>https://shops.sparkzz.net/</url>

Expand Down
442 changes: 245 additions & 197 deletions src/main/java/net/sparkzz/command/ShopCommand.java

Large diffs are not rendered by default.

19 changes: 3 additions & 16 deletions src/main/java/net/sparkzz/command/SubCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.sparkzz.command;

import net.sparkzz.shops.Shops;
import net.sparkzz.shops.Store;
import net.sparkzz.util.Notifiable;
import org.bukkit.command.Command;
Expand All @@ -8,7 +9,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
* Interface for sub command layout
Expand Down Expand Up @@ -40,20 +40,7 @@ public abstract class SubCommand extends Notifiable {
* @param nameOrUUID input name or UUID
* @return the optional store if found or optional empty if not found or duplicates are found
*/
protected Optional<Store> identifyStore(String nameOrUUID) {
Optional<Store> store = Optional.empty();

if (nameOrUUID.contains("~")) {
String[] input = nameOrUUID.split("~");

stores = Store.STORES.stream().filter(s -> s.getName().equalsIgnoreCase(input[0]) && s.getUUID().toString().equalsIgnoreCase(input[1])).collect(Collectors.toCollection(ArrayList::new));
} else {
stores = Store.STORES.stream().filter(s -> s.getName().equalsIgnoreCase(nameOrUUID) || s.getUUID().toString().equalsIgnoreCase(nameOrUUID)).collect(Collectors.toCollection(ArrayList::new));
}

if (stores.size() == 1)
store = Optional.of(stores.get(0));

return store;
protected Optional<Store> identifyStore(String nameOrUUID) throws Shops.MultipleStoresMatchedException {
return Store.identifyStore(nameOrUUID);
}
}
2 changes: 1 addition & 1 deletion src/main/java/net/sparkzz/command/sub/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public boolean process(CommandSender sender, Command command, String label, Stri
setArgsAsAttributes(args);
Material material = (Material) setAttribute("material", Material.matchMaterial(args[1]));
Player player = (Player) setAttribute("sender", sender);
Store store = (Store) setAttribute("store", InventoryManagementSystem.locateCurrentStore(player));
Store store = (Store) setAttribute("store", InventoryManagementSystem.locateCurrentStore(player).orElse(null));
int quantity = (Integer) setAttribute("quantity", 0);
String message = "";

Expand Down
10 changes: 7 additions & 3 deletions src/main/java/net/sparkzz/command/sub/BrowseCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import static net.sparkzz.util.Notifier.CipherKey.INVALID_PAGE_NUM;
import static net.sparkzz.util.Notifier.CipherKey.NO_STORE_FOUND;
import static net.sparkzz.util.Notifier.CipherKey.*;

/**
* Browse subcommand used for browsing items to a shop
Expand All @@ -24,7 +23,7 @@ public boolean process(CommandSender sender, Command command, String label, Stri
resetAttributes();
setArgsAsAttributes(args);
Player player = (Player) setAttribute("sender", sender);
Store store = (Store) setAttribute("store", InventoryManagementSystem.locateCurrentStore(player));
Store store = (Store) setAttribute("store", InventoryManagementSystem.locateCurrentStore(player).orElse(null));

if (store == null) {
Notifier.process(player, NO_STORE_FOUND, getAttributes());
Expand All @@ -33,6 +32,11 @@ public boolean process(CommandSender sender, Command command, String label, Stri

int pageNumber = (args.length > 1) ? Integer.parseInt(args[1]) : 1;

if (store.getItems().isEmpty()) {
Notifier.process(sender, STORE_NO_ITEMS, getAttributes());
return true;
}

String page = Notifier.Paginator.buildBrowsePage(store, pageNumber);

if (page == null) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/sparkzz/command/sub/BuyCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public boolean process(CommandSender sender, Command command, String label, Stri
Material material = (Material) setAttribute("material", Material.matchMaterial(args[1]));
Player player = (Player) setAttribute("sender", sender);
int quantity = (Integer) setAttribute("quantity", 1);
Store store = (Store) setAttribute("store", InventoryManagementSystem.locateCurrentStore(player));
Store store = (Store) setAttribute("store", InventoryManagementSystem.locateCurrentStore(player).orElse(null));

if (store == null) {
Notifier.process(player, NO_STORE_FOUND, getAttributes());
Expand Down
1 change: 0 additions & 1 deletion src/main/java/net/sparkzz/command/sub/CreateCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ public boolean process(CommandSender sender, Command command, String label, Stri
double limitMaxY = (double) setAttribute("limit-max-y", maxDims[1]);
double limitMaxZ = (double) setAttribute("limit-max-z", maxDims[2]);

// TODO: make 0 or negative limits ignore check
if ((maxX - minX) < limitMinX || (maxY - minY) < limitMinY || (maxZ - minZ) < limitMinZ) {
Notifier.process(sender, Notifier.CipherKey.STORE_CREATE_FAIL_MIN_DIMS, getAttributes());
return true;
Expand Down
98 changes: 49 additions & 49 deletions src/main/java/net/sparkzz/command/sub/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,65 +25,65 @@ public class DeleteCommand extends SubCommand {
@Override
public boolean process(CommandSender sender, Command command, String label, String[] args)
throws NumberFormatException {
resetAttributes();
setArgsAsAttributes(args);
Optional<Store> foundStore = identifyStore(args[1]);
setAttribute("sender", sender);
setAttribute("store", (foundStore.isPresent() ? foundStore.get() : args[1]));

if (stores.size() > 1) {
Notifier.process(sender, STORE_MULTI_MATCH, getAttributes());
return true;
}

if (foundStore.isEmpty()) {
Notifier.process(sender, STORE_NO_STORE_FOUND, getAttributes());
return true;
}

boolean ignoreInv = false, ignoreFunds = false;
try {
resetAttributes();
setArgsAsAttributes(args);
Optional<Store> foundStore = identifyStore(args[1]);
setAttribute("sender", sender);
setAttribute("store", (foundStore.isPresent() ? foundStore.get() : args[1]));

if (foundStore.isEmpty()) {
Notifier.process(sender, STORE_NO_STORE_FOUND, getAttributes());
return true;
}

// TODO: determine a way to check if a player can remove all items from the shop, if they can, remove them all
// TODO: add force flags (-f will ignore all inventory, then process) (-F will ignore all inventory and finances, then process)
if (args.length == 3) {
switch (args[2]) {
// soft force delete
case "-f" -> ignoreInv = true;
// hard force delete
case "-F" -> {
ignoreInv = true;
ignoreFunds = true;
boolean ignoreInv = false, ignoreFunds = false;

// TODO: determine a way to check if a player can remove all items from the shop, if they can, remove them all
// TODO: add force flags (-f will ignore all inventory, then process) (-F will ignore all inventory and finances, then process)
if (args.length == 3) {
switch (args[2]) {
// soft force delete
case "-f" -> ignoreInv = true;
// hard force delete
case "-F" -> {
ignoreInv = true;
ignoreFunds = true;
}
default -> {
}
}
default -> {}
}
}

boolean canInsertAll = false;
Store store = foundStore.get();
Player player = (Player) sender;
boolean canInsertAll = false;
Store store = foundStore.get();
Player player = (Player) sender;

setAttribute("store", store.getName());
setAttribute("store", store.getName());

if (!ignoreInv)
canInsertAll = InventoryManagementSystem.canInsertAll(player, store.getItems().entrySet().stream()
.map(entry -> new ItemStack(entry.getKey(), (int) entry.getValue().getOrDefault("quantity", 0)))
.collect(Collectors.toList()));
if (!ignoreInv)
canInsertAll = InventoryManagementSystem.canInsertAll(player, store.getItems().entrySet().stream()
.map(entry -> new ItemStack(entry.getKey(), (int) entry.getValue().getOrDefault("quantity", 0)))
.collect(Collectors.toList()));

if (!ignoreInv && !canInsertAll) {
Notifier.process(sender, STORE_DELETE_INSUFFICIENT_INV_PLAYER, getAttributes());
return true;
}
if (!ignoreInv && !canInsertAll) {
Notifier.process(sender, STORE_DELETE_INSUFFICIENT_INV_PLAYER, getAttributes());
return true;
}

if (!ignoreFunds) {
Shops.getEconomy().depositPlayer(player, store.getBalance());
store.setBalance(0);
}
if (!ignoreFunds) {
Shops.getEconomy().depositPlayer(player, store.getBalance());
store.setBalance(0);
}

boolean success = Store.STORES.remove(store);
boolean success = Store.STORES.remove(store);

if (success)
Notifier.process(sender, STORE_DELETE_SUCCESS, getAttributes());
else Notifier.process(sender, STORE_DELETE_FAIL, getAttributes());
if (success)
Notifier.process(sender, STORE_DELETE_SUCCESS, getAttributes());
else Notifier.process(sender, STORE_DELETE_FAIL, getAttributes());
} catch (Shops.MultipleStoresMatchedException exception) {
Notifier.process(sender, STORE_MULTI_MATCH, getAttributes());
}
return true;
}
}
2 changes: 1 addition & 1 deletion src/main/java/net/sparkzz/command/sub/DepositCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public boolean process(CommandSender sender, Command command, String label, Stri
resetAttributes();
setArgsAsAttributes(args);
Player player = (Player) setAttribute("sender", sender);
Store store = (Store) setAttribute("store", InventoryManagementSystem.locateCurrentStore(player));
Store store = (Store) setAttribute("store", InventoryManagementSystem.locateCurrentStore(player).orElse(null));
double amount = (Double) setAttribute("amount", Double.parseDouble(args[1]));

if (store == null) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/sparkzz/command/sub/RemoveCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public boolean process(CommandSender sender, Command command, String label, Stri
setArgsAsAttributes(args);
Material material = (Material) setAttribute("material", Material.matchMaterial(args[1]));
Player player = (Player) setAttribute("sender", sender);
Store store = (Store) setAttribute("store", InventoryManagementSystem.locateCurrentStore(player));
Store store = (Store) setAttribute("store", InventoryManagementSystem.locateCurrentStore(player).orElse(null));

if (store == null) {
Notifier.process(player, NO_STORE_FOUND, getAttributes());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/sparkzz/command/sub/SellCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public boolean process(CommandSender sender, Command command, String label, Stri
setArgsAsAttributes(args);
Material material = (Material) setAttribute("material", Material.matchMaterial(args[1]));
Player player = (Player) setAttribute("sender", sender);
Store store = (Store) setAttribute("store", InventoryManagementSystem.locateCurrentStore(player));
Store store = (Store) setAttribute("store", InventoryManagementSystem.locateCurrentStore(player).orElse(null));
int quantity = (Integer) setAttribute("quantity", 1);

if (store == null) {
Expand Down
76 changes: 38 additions & 38 deletions src/main/java/net/sparkzz/command/sub/TransferCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,54 +25,54 @@ public class TransferCommand extends SubCommand {
@Override
public boolean process(CommandSender sender, Command command, String label, String[] args)
throws NumberFormatException {
resetAttributes();
setArgsAsAttributes(args);
setAttribute("sender", sender);
Optional<Store> foundStore = identifyStore(args[1]);
setAttribute("store", (foundStore.isPresent() ? foundStore.get() : args[1]));

if (stores.size() > 1) {
Notifier.process(sender, STORE_MULTI_MATCH, getAttributes());
return true;
}
try {
resetAttributes();
setArgsAsAttributes(args);
setAttribute("sender", sender);
Optional<Store> foundStore;
foundStore = identifyStore(args[1]);
setAttribute("store", (foundStore.isPresent() ? foundStore.get() : args[1]));

if (foundStore.isEmpty()) {
Notifier.process(sender, STORE_NO_STORE_FOUND, getAttributes());
return true;
}

if (foundStore.isEmpty()) {
Notifier.process(sender, STORE_NO_STORE_FOUND, getAttributes());
return true;
}
boolean isUUID = args[2].matches("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$");

boolean isUUID = args[2].matches("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$");
// TODO: remove mock references once Server mocking is updated to fix issues with getServer()
setAttribute("target", args[2]);
Server server = (!Shops.isTest()) ? Shops.getPlugin(Shops.class).getServer() : Shops.getMockServer();
OfflinePlayer targetPlayer = (!isUUID) ? server.getPlayer(args[2]) : server.getOfflinePlayer(UUID.fromString(args[2]));

// TODO: remove mock references once Server mocking is updated to fix issues with getServer()
setAttribute("target", args[2]);
Server server = (!Shops.isTest()) ? Shops.getPlugin(Shops.class).getServer() : Shops.getMockServer();
OfflinePlayer targetPlayer = (!isUUID) ? server.getPlayer(args[2]) : server.getOfflinePlayer(UUID.fromString(args[2]));
if (targetPlayer == null) {
Notifier.process(sender, PLAYER_NOT_FOUND, getAttributes());
return true;
}

if (targetPlayer == null) {
Notifier.process(sender, PLAYER_NOT_FOUND, getAttributes());
return true;
}
Store store = foundStore.get();

Store store = foundStore.get();
setAttribute("target", targetPlayer.getName());

setAttribute("target", targetPlayer.getName());
if (!sender.isOp()) {
int shopsOwned = 0;

if (!sender.isOp()) {
int shopsOwned = 0;
for (Store existingStore : Store.STORES)
if (existingStore.getOwner().equals(targetPlayer.getUniqueId())) {
shopsOwned++;
}

for (Store existingStore : Store.STORES)
if (existingStore.getOwner().equals(targetPlayer.getUniqueId())) {
shopsOwned++;
if (shopsOwned >= (int) setAttribute("max-stores", Config.getMaxOwnedStores())) {
Notifier.process(sender, Notifier.CipherKey.STORE_TRANSFER_FAIL_MAX_STORES, getAttributes());
return true;
}

if (shopsOwned >= (int) setAttribute("max-stores", Config.getMaxOwnedStores())) {
Notifier.process(sender, Notifier.CipherKey.STORE_TRANSFER_FAIL_MAX_STORES, getAttributes());
return true;
}
}

store.setOwner(targetPlayer.getUniqueId());
Notifier.process(sender, STORE_TRANSFER_SUCCESS, getAttributes());
store.setOwner(targetPlayer.getUniqueId());
Notifier.process(sender, STORE_TRANSFER_SUCCESS, getAttributes());
} catch (Shops.MultipleStoresMatchedException exception) {
Notifier.process(sender, STORE_MULTI_MATCH, getAttributes());
}
return true;
}
}
}
9 changes: 7 additions & 2 deletions src/main/java/net/sparkzz/command/sub/UpdateCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ public boolean process(CommandSender sender, Command command, String label, Stri
resetAttributes();
setArgsAsAttributes(args);
Player player = (Player) setAttribute("sender", sender);
Store store = (Store) setAttribute("store", InventoryManagementSystem.locateCurrentStore(player));
Store store = (Store) setAttribute("store", InventoryManagementSystem.locateCurrentStore(player).orElse(null));

if (args.length >= 8 && args[1].equalsIgnoreCase("location")) {
if (!player.hasPermission("shops.update.location")) {
Notifier.process(sender, NO_PERMS_LOCATION, getAttributes());
return true;
}

switch (args.length) {
case 8 -> {
if (store == null) {
Expand Down Expand Up @@ -116,7 +121,7 @@ public boolean process(CommandSender sender, Command command, String label, Stri

store.setInfiniteStock(Boolean.parseBoolean(args[2]));
}
case "shop-name" -> store.setName(args[2]);
case "store-name" -> store.setName(args[2]);
default -> {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/sparkzz/command/sub/WithdrawCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public boolean process(CommandSender sender, Command command, String label, Stri
resetAttributes();
setArgsAsAttributes(args);
Player player = (Player) setAttribute("sender", sender);
Store store = (Store) setAttribute("store", InventoryManagementSystem.locateCurrentStore(player));
double amount = (Double) setAttribute("amount", (args[1].equalsIgnoreCase("all")) ? store.getBalance() : Double.parseDouble(args[1]));
Store store = (Store) setAttribute("store", InventoryManagementSystem.locateCurrentStore(player).orElse(null));
double amount = (Double) setAttribute("amount", (args[1].equalsIgnoreCase("all")) ? (store == null) ? 0 : store.getBalance() : Double.parseDouble(args[1]));

if (store == null) {
Notifier.process(player, NO_STORE_FOUND, getAttributes());
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/sparkzz/event/EntranceListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ public void onPlayerMove(PlayerMoveEvent event) {
playerStoreStatus.put(player, true);
Notifier.process(player, Notifier.CipherKey.STORE_WELCOME_MSG, getAttributes());
} else if (!isInShop && playerStoreStatus.getOrDefault(player, true)) {
if (playerStoreStatus.containsKey(player))
Notifier.process(player, Notifier.CipherKey.STORE_GOODBYE_MSG, getAttributes());
playerStoreStatus.put(player, false);
Notifier.process(player, Notifier.CipherKey.STORE_GOODBYE_MSG, getAttributes());
}
}
}
Loading

0 comments on commit 21198c4

Please sign in to comment.