Skip to content

Commit

Permalink
Added basic join message for shop statuses
Browse files Browse the repository at this point in the history
* Did minor testing, seems to be working
  • Loading branch information
KillerOfPie committed Oct 27, 2020
1 parent 22f60f8 commit dc8a4a2
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 9 deletions.
4 changes: 1 addition & 3 deletions src/main/java/org/shanerx/tradeshop/enumys/ShopRole.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,13 @@ public enum ShopRole {
MEMBER(false, false, true, false),
SHOPPER(false, false, false, true);

private String roleName;
private transient boolean destroy, edit, open, shop;
private final transient boolean destroy, edit, open, shop;

ShopRole(boolean destroy, boolean edit, boolean open, boolean shop) {
this.destroy = destroy;
this.edit = edit;
this.open = open;
this.shop = shop;
roleName = name();
}

public boolean canDestroy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@
import org.shanerx.tradeshop.TradeShop;
import org.shanerx.tradeshop.enumys.Message;
import org.shanerx.tradeshop.enumys.Permissions;
import org.shanerx.tradeshop.enumys.ShopRole;
import org.shanerx.tradeshop.objects.PlayerSetting;
import org.shanerx.tradeshop.objects.Shop;
import org.shanerx.tradeshop.objects.ShopLocation;
import org.shanerx.tradeshop.utils.BukkitVersion;
import org.shanerx.tradeshop.utils.Updater;
import org.shanerx.tradeshop.utils.Utils;
Expand All @@ -51,13 +54,44 @@ public void onJoin(PlayerJoinEvent event) {

Player player = event.getPlayer();
PlayerSetting playerSetting = plugin.getDataStorage().loadPlayer(player.getUniqueId());
plugin.getDataStorage().savePlayer(playerSetting != null ? playerSetting : new PlayerSetting(player.getUniqueId()));

if (Permissions.hasPermission(player, Permissions.ADMIN)) {
//If player does not have setting data, create new Default settings data ad save
if (playerSetting == null)
plugin.getDataStorage().savePlayer(new PlayerSetting(player.getUniqueId()));

//If player has Manage permission and plugin is behind, then send update message
if (Permissions.hasPermission(player, Permissions.MANAGE_PLUGIN)) {
BukkitVersion ver = new BukkitVersion();
if (plugin.getUpdater().compareVersions((short) ver.getMajor(), (short) ver.getMinor(), (short) ver.getPatch()).equals(Updater.RelationalStatus.BEHIND))
player.sendMessage(Message.PLUGIN_BEHIND.getPrefixed());
}

StringBuilder sb = new StringBuilder();
sb.append("%eInventory status of your shops: \n");
sb.append("&eShop Role &f| &eLocation &f| &eInventory Status\n&b");
if (playerSetting.getOwnedShops().size() > 0) {
playerSetting.getOwnedShops().forEach(s -> {
Shop shop = plugin.getDataStorage().loadShopFromSign(ShopLocation.deserialize(s));
if (shop.checkRole(player.getUniqueId()) != ShopRole.SHOPPER) {
sb.append(shop.checkRole(player.getUniqueId()).toString()).append(" &f|&d ");
sb.append(s).append(" &f| ");
sb.append(shop.getStatus().getLine()).append("\n&b");
}
});
}
if (playerSetting.getStaffShops().size() > 0) {
playerSetting.getOwnedShops().forEach(s -> {
Shop shop = plugin.getDataStorage().loadShopFromSign(ShopLocation.deserialize(s));
if (shop.checkRole(player.getUniqueId()) != ShopRole.SHOPPER) {
sb.append(shop.checkRole(player.getUniqueId()).toString()).append(" &f|&d ");
sb.append(s).append(" &f| ");
sb.append(shop.getStatus().getLine()).append("\n&b");
}
});
}

sb.deleteCharAt(sb.lastIndexOf("\n"));
player.sendMessage(colorize(sb.toString()));
}
}

26 changes: 23 additions & 3 deletions src/main/java/org/shanerx/tradeshop/objects/Shop.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ public class Shop implements Serializable {
private ShopUser owner;
private List<UUID> managers, members;
private ShopType shopType;
private ShopLocation shopLoc, chestLoc;
private List<ShopItemStack> product, cost;
private final ShopLocation shopLoc;
private final List<ShopItemStack> product;
private final List<ShopItemStack> cost;
private ShopLocation chestLoc;
private transient SignChangeEvent signChangeEvent;
private transient Inventory storageInv;
private transient Utils utils = new Utils();
private ShopStatus status = ShopStatus.INCOMPLETE;
private ShopStatus status = ShopStatus.INCOMPLETE;

/**
* Creates a Shop object
Expand Down Expand Up @@ -946,4 +948,22 @@ public Boolean checkCost(int multiplier) {
setStorageInventory();
return utils.checkInventory(storageInv, cost, multiplier);
}

/**
* Returns the ShopRole of the supplied UUID
*
* @param uuidToCheck uuid to check for role of
* @return the ShopRole of the supplied UUID
*/
public ShopRole checkRole(UUID uuidToCheck) {
if (owner.getUUID().equals(uuidToCheck)) {
return ShopRole.OWNER;
} else if (managers.contains(uuidToCheck)) {
return ShopRole.MANAGER;
} else if (members.contains(uuidToCheck)) {
return ShopRole.MEMBER;
} else {
return ShopRole.SHOPPER;
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/shanerx/tradeshop/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class Utils {
protected final String PREFIX = "&a[&eTradeShop&a] ";
private final UUID KOPUUID = UUID.fromString("daf79be7-bc1d-47d3-9896-f97b8d4cea7d");
private final UUID LORIUUID = UUID.fromString("e296bc43-2972-4111-9843-48fc32302fd4");
public TradeShop plugin = (TradeShop) Bukkit.getPluginManager().getPlugin("TradeShop");
public final TradeShop plugin = (TradeShop) Bukkit.getPluginManager().getPlugin("TradeShop");
protected PluginDescriptionFile pdf = plugin.getDescription();

public Debug debugger;
Expand Down

0 comments on commit dc8a4a2

Please sign in to comment.