1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-16 13:11:19 +01:00

Shop can be used with Vault economy.

Point price is optional for shop items
Price renamed to pointPrice, old format still works
This commit is contained in:
Zrips 2023-02-15 17:16:39 +02:00
parent edb1d5d2e7
commit 2165e1fe68
9 changed files with 543 additions and 430 deletions

View File

@ -1,5 +1,9 @@
package com.gamingmesh.jobs.commands.list; package com.gamingmesh.jobs.commands.list;
import java.util.Map;
import java.util.UUID;
import java.util.WeakHashMap;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -31,7 +35,7 @@ public class clearownership implements Cmd {
} }
} }
if (jPlayer==null && sender instanceof Player) if (jPlayer == null && sender instanceof Player)
jPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender); jPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender);
if (jPlayer == null) { if (jPlayer == null) {
@ -42,15 +46,16 @@ public class clearownership implements Cmd {
return true; return true;
} }
final JobsPlayer jp = jPlayer; final UUID uuid = jPlayer.getUniqueId();
final java.util.Map<BlockTypes, Integer> amounts = new java.util.WeakHashMap<>(); final Map<BlockTypes, Integer> amounts = new WeakHashMap<>();
for (BlockTypes type : BlockTypes.values()) {
if (location == null)
plugin.getBlockOwnerShip(type).ifPresent(ownerShip -> amounts.put(type, ownerShip.clear(jp.getUniqueId())));
else {
String l = location; String l = location;
plugin.getBlockOwnerShip(type).ifPresent(ownerShip -> amounts.put(type, ownerShip.remove(jp.getUniqueId(), l)));
for (BlockTypes type : BlockTypes.values()) {
if (location == null)
plugin.getBlockOwnerShip(type).ifPresent(ownerShip -> amounts.put(type, ownerShip.clear(uuid)));
else {
plugin.getBlockOwnerShip(type).ifPresent(ownerShip -> amounts.put(type, ownerShip.remove(uuid, l)));
} }
} }

View File

@ -301,8 +301,11 @@ public class LanguageManager {
c.get("command.shop.help.info", "Opens special jobs shop."); c.get("command.shop.help.info", "Opens special jobs shop.");
c.get("command.shop.help.args", ""); c.get("command.shop.help.args", "");
c.get("command.shop.info.title", "&e------- &8Jobs shop &e-------"); c.get("command.shop.info.title", "&e------- &8Jobs shop &e-------");
c.get("command.shop.info.currentPoints", "&eYou have: &6%currentpoints%");
c.get("command.shop.info.price", "&ePrice: &6%price%"); c.get("command.shop.info.haveColor", "&2");
c.get("command.shop.info.pointsPrice", "&ePoint cost: &c%currentpoints%&e/&6%price%");
c.get("command.shop.info.moneyPrice", "&eMoney cost: &c%currentbalance%&e/&6%price%");
c.get("command.shop.info.reqJobs", "&eRequired jobs:"); c.get("command.shop.info.reqJobs", "&eRequired jobs:");
c.get("command.shop.info.reqJobsList", " &6%jobsname%&e: &e%level% lvl"); c.get("command.shop.info.reqJobsList", " &6%jobsname%&e: &e%level% lvl");
c.get("command.shop.info.reqTotalLevel", "&6Required total level: &e%totalLevel%"); c.get("command.shop.info.reqTotalLevel", "&6Required total level: &e%totalLevel%");
@ -312,8 +315,9 @@ public class LanguageManager {
c.get("command.shop.info.cantOpen", "&cCan't open this page"); c.get("command.shop.info.cantOpen", "&cCan't open this page");
c.get("command.shop.info.NoPermForItem", "&cYou don't have required permissions for this item!"); c.get("command.shop.info.NoPermForItem", "&cYou don't have required permissions for this item!");
c.get("command.shop.info.NoPermToBuy", "&cNo permissions to buy this item"); c.get("command.shop.info.NoPermToBuy", "&cNo permissions to buy this item");
c.get("command.shop.info.NoJobReqForitem", "&cYou don't have the required job (&6%jobname%&e) with required (&6%joblevel%&e) level"); c.get("command.shop.info.NoJobReqForitem", "&cYou don't have the required job (&6%jobname%&c) with required (&6%joblevel%&c) level");
c.get("command.shop.info.NoPoints", "&cYou don't have enough points"); c.get("command.shop.info.NoPoints", "&cYou don't have enough points");
c.get("command.shop.info.NoMoney", "&cYou don't have enough money");
c.get("command.shop.info.NoTotalLevel", "&cTotal jobs level is too low (%totalLevel%)"); c.get("command.shop.info.NoTotalLevel", "&cTotal jobs level is too low (%totalLevel%)");
c.get("command.shop.info.Paid", "&eYou have paid &6%amount% &efor this item"); c.get("command.shop.info.Paid", "&eYou have paid &6%amount% &efor this item");

View File

@ -39,6 +39,7 @@ import net.Zrips.CMILib.GUI.GUIManager.GUIClickType;
import net.Zrips.CMILib.GUI.GUIManager.GUIRows; import net.Zrips.CMILib.GUI.GUIManager.GUIRows;
import net.Zrips.CMILib.Items.CMIMaterial; import net.Zrips.CMILib.Items.CMIMaterial;
import net.Zrips.CMILib.Locale.LC; import net.Zrips.CMILib.Locale.LC;
import net.Zrips.CMILib.Messages.CMIMessages;
import net.Zrips.CMILib.Version.Version; import net.Zrips.CMILib.Version.Version;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -105,6 +106,8 @@ public class ShopManager {
double points = (int) (jPlayer.getPointsData().getCurrentPoints() * 100.0) / 100.0; double points = (int) (jPlayer.getPointsData().getCurrentPoints() * 100.0) / 100.0;
double balance = Jobs.getEconomy().getEconomy().getBalance(player);
for (int i = 0; i < ls.size(); i++) { for (int i = 0; i < ls.size(); i++) {
ShopItem item = ls.get(i); ShopItem item = ls.get(i);
List<String> lore = new ArrayList<>(); List<String> lore = new ArrayList<>();
@ -141,8 +144,15 @@ public class ShopManager {
lore.addAll(item.getIconLore()); lore.addAll(item.getIconLore());
lore.add(Jobs.getLanguage().getMessage("command.shop.info.currentPoints", "%currentpoints%", points)); if (item.getPointPrice() > 0) {
lore.add(Jobs.getLanguage().getMessage("command.shop.info.price", "%price%", item.getPrice())); String color = item.getPointPrice() >= points ? "" : Jobs.getLanguage().getMessage("command.shop.info.haveColor");
lore.add(Jobs.getLanguage().getMessage("command.shop.info.pointsPrice", "%currentpoints%", color + points, "%price%", item.getPointPrice()));
}
if (item.getVaultPrice() > 0) {
String color = item.getVaultPrice() >= balance ? "" : Jobs.getLanguage().getMessage("command.shop.info.haveColor");
lore.add(Jobs.getLanguage().getMessage("command.shop.info.moneyPrice", "%currentbalance%", color + Jobs.getEconomy().getEconomy().format(balance), "%price%", item.getVaultPrice()));
}
if (!item.getRequiredJobs().isEmpty()) { if (!item.getRequiredJobs().isEmpty()) {
lore.add(Jobs.getLanguage().getMessage("command.shop.info.reqJobs")); lore.add(Jobs.getLanguage().getMessage("command.shop.info.reqJobs"));
@ -204,7 +214,7 @@ public class ShopManager {
} else } else
guiItem.setItemMeta(meta); guiItem.setItemMeta(meta);
gui.addButton(new CMIGuiButton(i, guiItem) { CMIGuiButton button = new CMIGuiButton(i, guiItem) {
@Override @Override
public void click(GUIClickType type) { public void click(GUIClickType type) {
for (String onePerm : item.getRequiredPerm()) { for (String onePerm : item.getRequiredPerm()) {
@ -228,11 +238,16 @@ public class ShopManager {
} }
} }
if (jPlayer.getPointsData().getCurrentPoints() < item.getPrice()) { if (item.getPointPrice() > 0 && jPlayer.getPointsData().getCurrentPoints() < item.getPointPrice()) {
player.sendMessage(Jobs.getLanguage().getMessage("command.shop.info.NoPoints")); player.sendMessage(Jobs.getLanguage().getMessage("command.shop.info.NoPoints"));
return; return;
} }
if (item.getVaultPrice() > 0 && jPlayer.getBalance() < item.getVaultPrice()) {
player.sendMessage(Jobs.getLanguage().getMessage("command.shop.info.NoMoney"));
return;
}
int totalLevels = jPlayer.getTotalLevels(); int totalLevels = jPlayer.getTotalLevels();
if (item.getRequiredTotalLevels() != -1 && totalLevels < item.getRequiredTotalLevels()) { if (item.getRequiredTotalLevels() != -1 && totalLevels < item.getRequiredTotalLevels()) {
player.sendMessage(Jobs.getLanguage().getMessage("command.shop.info.NoTotalLevel", "%totalLevel%", totalLevels)); player.sendMessage(Jobs.getLanguage().getMessage("command.shop.info.NoTotalLevel", "%totalLevel%", totalLevels));
@ -258,11 +273,20 @@ public class ShopManager {
GiveItem.giveItemForPlayer(player, one.getItemStack(player)); GiveItem.giveItemForPlayer(player, one.getItemStack(player));
} }
jPlayer.getPointsData().takePoints(item.getPrice()); if (item.getPointPrice() > 0) {
jPlayer.getPointsData().takePoints(item.getPointPrice());
Jobs.getJobsDAO().savePoints(jPlayer); Jobs.getJobsDAO().savePoints(jPlayer);
player.sendMessage(Jobs.getLanguage().getMessage("command.shop.info.Paid", "%amount%", item.getPrice())); player.sendMessage(Jobs.getLanguage().getMessage("command.shop.info.Paid", "%amount%", item.getPointPrice()));
} }
}); if (item.getVaultPrice() > 0) {
jPlayer.withdraw(item.getPointPrice());
player.sendMessage(Jobs.getLanguage().getMessage("command.shop.info.Paid", "%amount%", Jobs.getEconomy().getEconomy().format(item.getVaultPrice())));
}
openShopGui(player, page);
}
};
button.hideItemFlags();
gui.addButton(button);
} }
ItemStack item = new ItemStack(Material.ARROW); ItemStack item = new ItemStack(Material.ARROW);
@ -322,12 +346,18 @@ public class ShopManager {
continue; continue;
} }
if (!nameSection.isDouble("Price")) { double pointPrice = nameSection.getDouble("Price", nameSection.getDouble("pointPrice", 0D));
Jobs.getPluginLogger().severe("Shop item " + category + " has an invalid Price property. Skipping!"); double vaultPrice = nameSection.getDouble("vaultPrice", 0D);
ShopItem sItem = new ShopItem(category);
if (pointPrice <= 0 && vaultPrice <= 0) {
CMIMessages.consoleMessage("&eShop item " + category + " has an invalid Price property. Skipping!");
continue; continue;
} }
ShopItem sItem = new ShopItem(category, nameSection.getDouble("Price")); sItem.setPointPrice(pointPrice);
sItem.setVaultPrice(vaultPrice);
if (nameSection.isString("Icon.Id")) if (nameSection.isString("Icon.Id"))
sItem.setIconMaterial(nameSection.getString("Icon.Id")); sItem.setIconMaterial(nameSection.getString("Icon.Id"));

View File

@ -1467,4 +1467,16 @@ public class JobsPlayer {
blockOwnerShipInform = new HashSet<String>(); blockOwnerShipInform = new HashSet<String>();
this.blockOwnerShipInform.add(location); this.blockOwnerShipInform.add(location);
} }
public double getBalance() {
if (this.isOnline())
return Jobs.getEconomy().getEconomy().getBalance(this.getPlayer());
return Jobs.getEconomy().getEconomy().getBalance(this.getName());
}
public boolean withdraw(double amount) {
if (this.isOnline())
return Jobs.getEconomy().getEconomy().withdrawPlayer(this.getPlayer(), amount);
return Jobs.getEconomy().getEconomy().withdrawPlayer(this.getName(), amount);
}
} }

View File

@ -7,11 +7,16 @@ import java.util.Map;
public class ShopItem { public class ShopItem {
private double price = 0D; private double pointPrice = 0D;
private double vaultPrice = 0D;
private int slot = -1, page = -1, iconAmount = 1; private int slot = -1;
private int page = -1;
private int iconAmount = 1;
private String nodeName, iconMaterial, iconName; private String nodeName;
private String iconMaterial;
private String iconName;
private boolean hideWithoutPerm = false; private boolean hideWithoutPerm = false;
private boolean hideNoEnoughPoint = false; private boolean hideNoEnoughPoint = false;
@ -20,15 +25,16 @@ public class ShopItem {
private Map<String, Integer> requiredJobs = new HashMap<>(); private Map<String, Integer> requiredJobs = new HashMap<>();
private final List<String> iconLore = new ArrayList<>(), requiredPerm = new ArrayList<>(), commands = new ArrayList<>(); private final List<String> iconLore = new ArrayList<>();
private final List<String> requiredPerm = new ArrayList<>();
private final List<String> commands = new ArrayList<>();
private final List<JobItems> items = new ArrayList<>(); private final List<JobItems> items = new ArrayList<>();
private String playerName; private String playerName;
private boolean useCurrentPlayer = false; private boolean useCurrentPlayer = false;
public ShopItem(String nodeName, double price) { public ShopItem(String nodeName) {
this.nodeName = nodeName; this.nodeName = nodeName;
this.price = price;
} }
public void setPage(Integer page) { public void setPage(Integer page) {
@ -127,8 +133,13 @@ public class ShopItem {
this.iconMaterial = iconMaterial; this.iconMaterial = iconMaterial;
} }
@Deprecated
public double getPrice() { public double getPrice() {
return price; return getPointPrice();
}
public double getPointPrice() {
return pointPrice;
} }
public void setIconAmount(int iconAmount) { public void setIconAmount(int iconAmount) {
@ -170,4 +181,16 @@ public class ShopItem {
public void setCustomHeadOwner(boolean useCurrentPlayer) { public void setCustomHeadOwner(boolean useCurrentPlayer) {
this.useCurrentPlayer = useCurrentPlayer; this.useCurrentPlayer = useCurrentPlayer;
} }
public double getVaultPrice() {
return vaultPrice;
}
public void setVaultPrice(double currencyPrice) {
this.vaultPrice = currencyPrice;
}
public void setPointPrice(double pointPrice) {
this.pointPrice = pointPrice;
}
} }

View File

@ -55,4 +55,19 @@ public class BlackholeEconomy implements Economy {
public boolean depositPlayer(String PlayerName, double money) { public boolean depositPlayer(String PlayerName, double money) {
return true; return true;
} }
@Override
public double getBalance(OfflinePlayer offlinePlayer) {
return 0;
}
@Override
public double getBalance(String PlayerName) {
return 0;
}
@Override
public String getFormatedBalance(OfflinePlayer offlinePlayer) {
return "";
}
} }

View File

@ -34,4 +34,10 @@ public interface Economy {
boolean withdrawPlayer(String PlayerName, double money); boolean withdrawPlayer(String PlayerName, double money);
boolean depositPlayer(String PlayerName, double money); boolean depositPlayer(String PlayerName, double money);
double getBalance(OfflinePlayer offlinePlayer);
double getBalance(String PlayerName);
String getFormatedBalance(OfflinePlayer offlinePlayer);
} }

View File

@ -63,4 +63,19 @@ public class VaultEconomy implements Economy {
return vault.format(money); return vault.format(money);
} }
@Override
public double getBalance(OfflinePlayer offlinePlayer) {
return vault.getBalance(offlinePlayer);
}
@Override
public double getBalance(String PlayerName) {
return vault.getBalance(PlayerName);
}
@Override
public String getFormatedBalance(OfflinePlayer offlinePlayer) {
return format(getBalance(offlinePlayer));
}
} }

View File

@ -1,7 +1,10 @@
Items: Items:
SuperPickAxe: SuperPickAxe:
# (REQUIRED) Item price in Jobs Points # (Optional) Item price in Jobs Points
Price: 10000.0 pointPrice: 10000.0
# (Optional) Item price in Vault economy currency.
# Atleast one type of currency needs to be defined
vaultPrice: 10000.0
Icon: Icon:
# (REQUIRED) Icon item # (REQUIRED) Icon item
Id: diamond_pickaxe Id: diamond_pickaxe
@ -66,7 +69,7 @@ Items:
# (Required) Item name # (Required) Item name
Id: apple Id: apple
WoodenShovel: WoodenShovel:
Price: 100.0 pointPrice: 100.0
Icon: Icon:
Id: wooden_shovel Id: wooden_shovel
Name: "&eWooden shovel" Name: "&eWooden shovel"
@ -79,7 +82,7 @@ Items:
- "msg &eThanks [player] for buying this shovel!" - "msg &eThanks [player] for buying this shovel!"
- "give [player] wooden_shovel 1" - "give [player] wooden_shovel 1"
LureEnchantBook: LureEnchantBook:
Price: 100.0 pointPrice: 100.0
Icon: Icon:
Id: enchanted_book Id: enchanted_book
Name: "&eEnchant book" Name: "&eEnchant book"
@ -98,7 +101,7 @@ Items:
Enchants: Enchants:
- LURE=3 - LURE=3
Elytra: Elytra:
Price: 100000.0 pointPrice: 100000.0
Icon: Icon:
Id: elytra Id: elytra
Name: "&eAngel wings" Name: "&eAngel wings"