diff --git a/jars/PlaceholderAPI-2.10.10.jar b/jars/PlaceholderAPI-2.10.10.jar
new file mode 100644
index 0000000..40a1182
Binary files /dev/null and b/jars/PlaceholderAPI-2.10.10.jar differ
diff --git a/pom.xml b/pom.xml
index d7ee412..a8a2b72 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.olliejw
OreMarket
- 2.0-ALPHA
+ 2.2.0
jar
OreMarket
@@ -62,6 +62,10 @@
sonatype
https://oss.sonatype.org/content/groups/public/
+
+ placeholderapi
+ https://repo.extendedclip.com/content/repositories/placeholderapi/
+
@@ -78,5 +82,12 @@
system
${project.basedir}/jars/Vault.jar
+
+ me.clip
+ placeholderapi
+ 2.10.10
+ system
+ ${project.basedir}/jars/PlaceholderAPI-2.10.10.jar
+
diff --git a/src/main/java/com/olliejw/oremarket/Chat/ValueUpdates.java b/src/main/java/com/olliejw/oremarket/Chat/ValueUpdates.java
index a73b513..f58172c 100644
--- a/src/main/java/com/olliejw/oremarket/Chat/ValueUpdates.java
+++ b/src/main/java/com/olliejw/oremarket/Chat/ValueUpdates.java
@@ -1,7 +1,7 @@
package com.olliejw.oremarket.Chat;
import com.olliejw.oremarket.OreMarket;
-import com.olliejw.oremarket.Utils.PlaceHolders;
+import com.olliejw.oremarket.Utils.Placeholders;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
@@ -9,13 +9,13 @@ import org.bukkit.entity.Player;
import java.util.Objects;
public class ValueUpdates {
- PlaceHolders plh = new PlaceHolders();
+ Placeholders plh = new Placeholders();
public void announceValue() {
Bukkit.getScheduler().scheduleSyncRepeatingTask(OreMarket.main(), () -> {
for (String key : Objects.requireNonNull(OreMarket.main().getGuiConfig().getConfigurationSection("items")).getKeys(false)) {
ConfigurationSection keySection = Objects.requireNonNull(OreMarket.main().getGuiConfig().getConfigurationSection("items")).getConfigurationSection(key);
- String message = OreMarket.main().getConfig().getString("valueupdates.format");
+ String message = OreMarket.main().getConfig().getString("valuemessage.format");
assert keySection != null;
assert message != null;
@@ -28,6 +28,6 @@ public class ValueUpdates {
}
}
- }, 0L, (OreMarket.main().getConfig().getInt("valueupdates.time")* 20L*60));
+ }, 0L, (OreMarket.main().getConfig().getInt("valuemessage.time")* 20L*60));
}
}
diff --git a/src/main/java/com/olliejw/oremarket/Commands/OpenMarket.java b/src/main/java/com/olliejw/oremarket/Commands/OpenMarket.java
index 767596b..38cfde0 100644
--- a/src/main/java/com/olliejw/oremarket/Commands/OpenMarket.java
+++ b/src/main/java/com/olliejw/oremarket/Commands/OpenMarket.java
@@ -1,18 +1,18 @@
package com.olliejw.oremarket.Commands;
-import com.olliejw.oremarket.Utils.AddItem;
+import com.olliejw.oremarket.Inventory.CreateGUI;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class OpenMarket implements CommandExecutor {
- AddItem addItem = new AddItem();
+ CreateGUI createGUI = new CreateGUI();
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (command.getName().equalsIgnoreCase("openmarket")) {
if (sender.hasPermission("oremarket.open")) {
- addItem.createGUI((Player) sender);
+ createGUI.createGUI((Player) sender);
}
}
return true;
diff --git a/src/main/java/com/olliejw/oremarket/Commands/Reload.java b/src/main/java/com/olliejw/oremarket/Commands/Reload.java
index a024526..8d0bc07 100644
--- a/src/main/java/com/olliejw/oremarket/Commands/Reload.java
+++ b/src/main/java/com/olliejw/oremarket/Commands/Reload.java
@@ -1,8 +1,6 @@
package com.olliejw.oremarket.Commands;
-import com.olliejw.oremarket.Chat.ValueUpdates;
import com.olliejw.oremarket.OreMarket;
-import com.olliejw.oremarket.Utils.AddItem;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
diff --git a/src/main/java/com/olliejw/oremarket/Commands/StatsCommands.java b/src/main/java/com/olliejw/oremarket/Commands/StatsCommands.java
index 6b3f854..bd2b586 100644
--- a/src/main/java/com/olliejw/oremarket/Commands/StatsCommands.java
+++ b/src/main/java/com/olliejw/oremarket/Commands/StatsCommands.java
@@ -1,9 +1,6 @@
package com.olliejw.oremarket.Commands;
import com.olliejw.oremarket.Utils.Stats;
-import net.md_5.bungee.api.chat.ClickEvent;
-import net.md_5.bungee.api.chat.TextComponent;
-import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
diff --git a/src/main/java/com/olliejw/oremarket/Events/MarketCrash.java b/src/main/java/com/olliejw/oremarket/Events/MarketCrash.java
index ae0e8db..1679b8e 100644
--- a/src/main/java/com/olliejw/oremarket/Events/MarketCrash.java
+++ b/src/main/java/com/olliejw/oremarket/Events/MarketCrash.java
@@ -12,19 +12,26 @@ import java.util.Objects;
public class MarketCrash implements Listener {
public void forceCrash() {
+ // Notification
String notification = OreMarket.main().getConfig().getString("marketcrash.message");
for (Player player: Bukkit.getOnlinePlayers()) {
assert notification != null;
- player.sendMessage(ChatColor.translateAlternateColorCodes('&', notification).replace("[amount]", Objects.requireNonNull(OreMarket.main().getConfig().getString("marketcrash.amount"))));
+ String message = ChatColor.translateAlternateColorCodes('&', notification).replace("[amount]", Objects.requireNonNull(OreMarket.main().getConfig().getString("marketcrash.amount")));
+ player.sendMessage(message);
+
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 10.0F, 1);
}
+
+ // Change value
for (String key : Objects.requireNonNull(OreMarket.main().getGuiConfig().getConfigurationSection("items")).getKeys(false)) {
ConfigurationSection keySection = Objects.requireNonNull(OreMarket.main().getGuiConfig().getConfigurationSection("items")).getConfigurationSection(key);
assert keySection != null;
- double value = keySection.getDouble("value");
- double amount = OreMarket.main().getConfig().getDouble("marketcrash.amount");
- keySection.set("value", (value*(1-(amount/100))));
- OreMarket.main().saveGuiConfig();
+ if(keySection.getDouble("value") > 0) {
+ double value = keySection.getDouble("value");
+ double amount = OreMarket.main().getConfig().getDouble("marketcrash.amount");
+ keySection.set("value", (value * (1 - (amount / 100))));
+ OreMarket.main().saveGuiConfig();
+ }
}
}
diff --git a/src/main/java/com/olliejw/oremarket/Inventory/CreateGUI.java b/src/main/java/com/olliejw/oremarket/Inventory/CreateGUI.java
new file mode 100644
index 0000000..d566ae6
--- /dev/null
+++ b/src/main/java/com/olliejw/oremarket/Inventory/CreateGUI.java
@@ -0,0 +1,74 @@
+package com.olliejw.oremarket.Inventory;
+
+import com.olliejw.oremarket.OreMarket;
+import com.olliejw.oremarket.Utils.Placeholders;
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.Material;
+import org.bukkit.configuration.ConfigurationSection;
+import org.bukkit.entity.Player;
+import org.bukkit.event.Listener;
+import org.bukkit.inventory.Inventory;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
+import org.bukkit.inventory.meta.SkullMeta;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+public class CreateGUI implements Listener {
+ String title = OreMarket.main().getGuiConfig().getString("gui.title");
+ int rows = OreMarket.main().getGuiConfig().getInt("gui.rows");
+ Inventory inv = Bukkit.createInventory(null, rows*9, ChatColor.translateAlternateColorCodes('&', title));
+ Placeholders plh = new Placeholders();
+ SkullMeta skullMeta;
+
+ public void createGUI (Player player) {
+ for (String key : Objects.requireNonNull(OreMarket.main().getGuiConfig().getConfigurationSection("items")).getKeys(false)) {
+ ConfigurationSection keySection = Objects.requireNonNull(OreMarket.main().getGuiConfig().getConfigurationSection("items")).getConfigurationSection(key);
+ assert keySection != null;
+
+ // Getting the item type
+ ItemStack item = new ItemStack(Objects.requireNonNull(Material.matchMaterial(Objects.requireNonNull(keySection.getString("item")))));
+
+ // Getting the item meta
+ ItemMeta meta = item.getItemMeta(); assert meta != null;
+ String name = keySection.getString("name");
+
+ // Get the lore from config
+ List lore = new ArrayList<>();
+ for (String loreItem : Objects.requireNonNull(keySection.getStringList("lore"))) {
+ String string = plh.format(loreItem, player, keySection);
+ lore.add(string);
+ }
+
+ // Set values
+ assert name != null;
+ meta.setDisplayName(plh.format(name, player, keySection));
+ meta.setLore(lore);
+ item.setItemMeta(meta);
+
+ // Player head?
+ if (Objects.requireNonNull(keySection.getString("item")).equals("PLAYER_HEAD")) {
+ skullMeta = (SkullMeta) item.getItemMeta();
+ String skullID = keySection.getString("head");
+ assert skullMeta != null;
+ assert skullID != null;
+ skullMeta.setOwningPlayer(Objects.requireNonNull(Bukkit.getPlayer(skullID)).getPlayer());
+ skullMeta.setLore(lore);
+ skullMeta.setDisplayName(plh.format(name, player, keySection));
+ item.setItemMeta(skullMeta);
+ }
+
+
+ // Set items and open GUI
+ inv.setItem(Integer.parseInt(key), item);
+ player.openInventory(inv);
+ }
+ }
+ public SkullMeta getSkullMeta() {
+ return skullMeta;
+ }
+}
+
diff --git a/src/main/java/com/olliejw/oremarket/Listeners/InventoryEvents.java b/src/main/java/com/olliejw/oremarket/Listeners/InventoryEvents.java
index 9301f80..2692e1c 100644
--- a/src/main/java/com/olliejw/oremarket/Listeners/InventoryEvents.java
+++ b/src/main/java/com/olliejw/oremarket/Listeners/InventoryEvents.java
@@ -1,19 +1,26 @@
package com.olliejw.oremarket.Listeners;
+import com.olliejw.oremarket.Inventory.CreateGUI;
import com.olliejw.oremarket.OreMarket;
-import com.olliejw.oremarket.Utils.Stats;
+import com.olliejw.oremarket.Utils.Placeholders;
+import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
+import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.HumanEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
+import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.SkullMeta;
+import java.text.DecimalFormat;
+import java.text.Format;
import java.util.Objects;
public class InventoryEvents implements Listener {
@@ -37,9 +44,9 @@ public class InventoryEvents implements Listener {
double currentIncrease = ((Current / 100.0) * (100 + multiplier));
double currentDecrease = ((Current / 100.0) * (100 - multiplier));
if (Positive) {
- OreMarket.main().getGuiConfig().set("items." + Slot + ".value", currentIncrease);
+ OreMarket.main().getGuiConfig().set("items." + Slot + ".value", Math.round(currentIncrease*100.0)/100.0);
} else {
- OreMarket.main().getGuiConfig().set("items." + Slot + ".value", currentDecrease);
+ OreMarket.main().getGuiConfig().set("items." + Slot + ".value", Math.round(currentDecrease*100.0)/100.0);
}
OreMarket.main().saveGuiConfig();
}
@@ -57,43 +64,75 @@ public class InventoryEvents implements Listener {
}
String title = ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(OreMarket.main().getGuiConfig().getString("gui.title")));
+ Placeholders plh = new Placeholders();
+ CreateGUI createGUI = new CreateGUI();
@EventHandler
public void clickEvent (InventoryClickEvent event) {
- org.bukkit.inventory.Inventory playerInventory = event.getWhoClicked().getInventory(); // Player's inventory
+ Inventory playerInventory = event.getWhoClicked().getInventory(); // Player's inventory
InventoryView playerView = event.getView(); // Player's inventory view
HumanEntity player = event.getWhoClicked(); // Player that clicked
+ ConfigurationSection keySection = null;
+ for (String key : Objects.requireNonNull(OreMarket.main().getGuiConfig().getConfigurationSection("items")).getKeys(false)) {
+ keySection = Objects.requireNonNull(OreMarket.main().getGuiConfig().getConfigurationSection("items")).getConfigurationSection(key);
+ }
if (event.getCurrentItem() == null) { return; } // Null check. Prevents errors
- if (playerView.getTitle().equals(ChatColor.translateAlternateColorCodes('&', title))) { event.setCancelled(true); // I know. Its a bad way of checking.
- double value = OreMarket.main().getGuiConfig().getDouble("items." + event.getSlot() + ".value"); // Ore Value
- int stock = OreMarket.main().getGuiConfig().getInt("items." + event.getSlot() + ".stock"); // Ore stock
+ if (playerView.getTitle().equals(ChatColor.translateAlternateColorCodes('&', title))) {
+ event.setCancelled(true); // I know. Its a bad way of checking.
String itemConfig = OreMarket.main().getGuiConfig().getString("items." + event.getSlot() + ".item"); // Config location of item
- boolean close = OreMarket.main().getGuiConfig().getBoolean("items." + event.getSlot() + ".close");
+ ItemStack clickedItem;
assert itemConfig != null;
- ItemStack clickedItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(itemConfig))); // Item that user clicked
+ clickedItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(itemConfig))); // Item that user clicked
+ int slot = event.getSlot();
- if (event.getClick() == ClickType.LEFT) { // Sell Mode
- if (playerInventory.containsAtLeast(clickedItem, 1)) {
- playerInventory.removeItem(clickedItem);
+ if ((event.getClick() == ClickType.LEFT) && (!OreMarket.main().getGuiConfig().getBoolean("items." + event.getSlot() + ".buyonly"))) { // Sell Mode
+ double value = OreMarket.main().getGuiConfig().getDouble("items." + slot + ".value");
+ int stock = OreMarket.main().getGuiConfig().getInt("items." + slot + ".stock");
+ if (playerInventory.containsAtLeast(clickedItem, 1) || OreMarket.main().getGuiConfig().getBoolean("items." + slot + ".copymeta")) {
+ if (OreMarket.main().getGuiConfig().getBoolean("items." + slot + ".copymeta")) {
+ playerInventory.removeItem(event.getCurrentItem());
+ }
+ else {
+ playerInventory.removeItem(clickedItem);
+ }
addMoney(value, player);
- valueChange(event.getSlot(), value, true);
- stockChange(event.getSlot(), stock, 1, true);
+ valueChange(slot, value, true);
+ stockChange(slot, stock, 1, true);
}
}
- if (event.getClick() == ClickType.RIGHT) { // Buy Mode
+ if ((event.getClick() == ClickType.RIGHT) && (!OreMarket.main().getGuiConfig().getBoolean("items." + event.getSlot() + ".sellonly"))) { // Buy Mode
+ double value = OreMarket.main().getGuiConfig().getDouble("items." + slot + ".value");
+ int stock = OreMarket.main().getGuiConfig().getInt("items." + slot + ".stock");
if (balance(player) > value) {
- if (stock > 1 || stock == -1) { if (value < 1) { return; }
- playerInventory.addItem(clickedItem);
+ if ((stock > 1 || stock == -1) && (value > 1)) {
+ if (OreMarket.main().getGuiConfig().getBoolean("items." + slot + ".copymeta")) {
+ playerInventory.addItem(event.getCurrentItem());
+ }
+ else {
+ playerInventory.addItem(clickedItem);
+ }
takeMoney(value, player);
- valueChange(event.getSlot(), value, false);
- stockChange(event.getSlot(), stock, 1, false);
+ valueChange(slot, value, false);
+ stockChange(slot, stock, 1, false);
}
}
}
- if (close) {
- player.closeInventory();
+
+ assert keySection != null;
+ for (String command : Objects.requireNonNull(OreMarket.main().getGuiConfig().getStringList("items." + event.getSlot() + ".commands"))) {
+ if (command != null) { String toSend = plh.format(command, player, keySection);
+ if (toSend.equals("[close]")) {
+ player.closeInventory();
+ }
+ else if (toSend.contains("[msg]")) {
+ player.sendMessage(toSend.replace("[msg] ", ""));
+ }
+ else {
+ Bukkit.dispatchCommand(player, toSend);
+ }
+ }
}
}
}
diff --git a/src/main/java/com/olliejw/oremarket/Metrics.java b/src/main/java/com/olliejw/oremarket/Metrics.java
index 5d56681..4f60541 100644
--- a/src/main/java/com/olliejw/oremarket/Metrics.java
+++ b/src/main/java/com/olliejw/oremarket/Metrics.java
@@ -9,13 +9,7 @@ import java.io.InputStreamReader;
import java.lang.reflect.Method;
import java.net.URL;
import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-import java.util.UUID;
+import java.util.*;
import java.util.concurrent.Callable;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@@ -576,10 +570,8 @@ public class Metrics {
/**
* Class constructor.
- *
- * @param chartId The id of the chart.
- * @param callable The callable which is used to request the chart data.
- */
+ * @param chartId The id of the chart.
+ * @param callable The callable which is used to request the chart data.*/
public SimplePie(String chartId, Callable callable) {
super(chartId);
this.callable = callable;
diff --git a/src/main/java/com/olliejw/oremarket/OreMarket.java b/src/main/java/com/olliejw/oremarket/OreMarket.java
index 4b64492..a292481 100644
--- a/src/main/java/com/olliejw/oremarket/OreMarket.java
+++ b/src/main/java/com/olliejw/oremarket/OreMarket.java
@@ -1,4 +1,5 @@
package com.olliejw.oremarket;
+
import com.olliejw.oremarket.Chat.ValueUpdates;
import com.olliejw.oremarket.Commands.CrashMarket;
import com.olliejw.oremarket.Commands.OpenMarket;
@@ -6,9 +7,9 @@ import com.olliejw.oremarket.Commands.Reload;
import com.olliejw.oremarket.Commands.StatsCommands;
import com.olliejw.oremarket.Events.MarketCrash;
import com.olliejw.oremarket.Listeners.InventoryEvents;
+import com.olliejw.oremarket.Utils.Placeholders;
import com.olliejw.oremarket.Utils.Stats;
-import com.olliejw.oremarket.Utils.UpdateChecker;
-
+import com.olliejw.oremarket.Utils.Updates;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@@ -16,27 +17,28 @@ import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
+import org.bukkit.event.Listener;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.IOException;
+import java.util.List;
import java.util.Objects;
import java.util.concurrent.Callable;
import java.util.logging.Logger;
-public final class OreMarket extends JavaPlugin {
+public final class OreMarket extends JavaPlugin implements Listener {
ValueUpdates valueUpdates = new ValueUpdates();
MarketCrash mkCrash = new MarketCrash();
Stats stats = new Stats();
+ private File guiFile;
+ private FileConfiguration guiConfig;
private static OreMarket instance;
private static final Logger log = Logger.getLogger("Minecraft");
private static Economy econ = null;
- private File guiFile;
- private FileConfiguration guiConfig;
-
public void onEnable() {
instance = this;
saveDefaultConfig();
@@ -44,7 +46,7 @@ public final class OreMarket extends JavaPlugin {
Logger logger = this.getLogger();
// Spigot and bStats
- new UpdateChecker(this, 91015).getVersion(version -> {
+ new Updates(this, 91015).getVersion(version -> {
if (this.getDescription().getVersion().equalsIgnoreCase(version)) {
logger.info("You are up to date!");
} else {
@@ -84,8 +86,14 @@ public final class OreMarket extends JavaPlugin {
log.severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
getServer().getPluginManager().disablePlugin(this);
}
+
+ // Placeholder API
+ if(Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null){
+ new Placeholders().register();
+ }
}
+
public FileConfiguration getGuiConfig() {
return this.guiConfig;
}
@@ -104,7 +112,6 @@ public final class OreMarket extends JavaPlugin {
e.printStackTrace();
}
}
-
public void saveGuiConfig() {
try {
guiConfig.save(guiFile);
@@ -120,6 +127,7 @@ public final class OreMarket extends JavaPlugin {
}
}
+
public static OreMarket main(){
return instance;
}
diff --git a/src/main/java/com/olliejw/oremarket/Utils/Economy.java b/src/main/java/com/olliejw/oremarket/Utils/Economy.java
new file mode 100644
index 0000000..28458ff
--- /dev/null
+++ b/src/main/java/com/olliejw/oremarket/Utils/Economy.java
@@ -0,0 +1,4 @@
+package com.olliejw.oremarket.Utils;
+
+public class Economy {
+}
diff --git a/src/main/java/com/olliejw/oremarket/Utils/Placeholders.java b/src/main/java/com/olliejw/oremarket/Utils/Placeholders.java
new file mode 100644
index 0000000..85849be
--- /dev/null
+++ b/src/main/java/com/olliejw/oremarket/Utils/Placeholders.java
@@ -0,0 +1,109 @@
+package com.olliejw.oremarket.Utils;
+
+import com.olliejw.oremarket.OreMarket;
+import me.clip.placeholderapi.PlaceholderAPI;
+import me.clip.placeholderapi.expansion.PlaceholderExpansion;
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.OfflinePlayer;
+import org.bukkit.configuration.ConfigurationSection;
+import org.bukkit.entity.HumanEntity;
+import org.bukkit.entity.Player;
+
+import java.text.DecimalFormat;
+import java.text.Format;
+import java.util.Objects;
+
+public class Placeholders extends PlaceholderExpansion {
+
+ // Return placeholders
+ public String format(String string, HumanEntity player, ConfigurationSection configurationSection) {
+ Player playerObj = (Player) player;
+ String name = configurationSection.getString("name");
+ final Format DECIMAL_FORMAT = new DecimalFormat("#0.0#");
+ int stock = configurationSection.getInt("stock");
+ double value = configurationSection.getDouble("value");
+ double cost = configurationSection.getDouble("cost");
+ double difference = (value - cost);
+ double change = (value / cost);
+ double percent = ((change * 100) - 100);
+ double balance = OreMarket.getEconomy().getBalance(playerObj);
+
+ assert name != null;
+ String formatted = ChatColor.translateAlternateColorCodes('&', string
+ .replace("[name]", name)
+ .replace("[stock]", String.valueOf(stock))
+ .replace("[value]", DECIMAL_FORMAT.format(value))
+ .replace("[cost]", DECIMAL_FORMAT.format(cost))
+ .replace("[change]", DECIMAL_FORMAT.format(difference))
+ .replace("[percent]", DECIMAL_FORMAT.format(percent))
+ .replace("[balance]", DECIMAL_FORMAT.format(balance))
+ );
+ return PlaceholderAPI.setPlaceholders(playerObj, formatted);
+ }
+
+
+ // Placeholder API
+
+ @Override
+ public boolean canRegister() {
+ return true;
+ }
+
+ @Override
+ public String getAuthor(){
+ return OreMarket.main().getDescription().getAuthors().toString();
+ }
+
+ @Override
+ public String getIdentifier() {
+ return "oremarket";
+ }
+
+ @Override
+ public String getVersion() {
+ return OreMarket.main().getDescription().getVersion();
+ }
+
+ @Override
+ public boolean persist() {
+ return true;
+ }
+
+ @Override
+ public String onPlaceholderRequest(Player player, String identifier){
+ for (String key : Objects.requireNonNull(OreMarket.main().getGuiConfig().getConfigurationSection("items")).getKeys(false)) {
+ ConfigurationSection keySection = Objects.requireNonNull(OreMarket.main().getGuiConfig().getConfigurationSection("items")).getConfigurationSection(key);
+ assert keySection != null;
+
+ final Format df = new DecimalFormat("#0.0#");
+ double difference = (keySection.getDouble("value") - keySection.getDouble("cost"));
+ double change = (keySection.getDouble("value") / keySection.getDouble("cost"));
+ double percent = ((change * 100) - 100);;
+
+ // %oremarket_{identifier}_{slot}%
+ if (identifier.equals("value_" + key)) {
+ return String.valueOf(keySection.getDouble("value"));
+ }
+ if (identifier.equals("name_" + key)) {
+ return keySection.getString("name");
+ }
+ if (identifier.equals("stock_" + key)) {
+ return String.valueOf(keySection.getInt("stock"));
+ }
+ if (identifier.equals("cost_" + key)) {
+ return String.valueOf(keySection.getDouble("cost"));
+ }
+ if (identifier.equals("change_" + key)) {
+ return df.format(difference);
+ }
+ if (identifier.equals("percent_" + key)) {
+ return df.format(percent);
+ }
+ if (identifier.equals("test")) {
+ return "Oremarket PAPI works!";
+ }
+ }
+ return null;
+ }
+}
diff --git a/src/main/java/com/olliejw/oremarket/Utils/Stats.java b/src/main/java/com/olliejw/oremarket/Utils/Stats.java
index 257e3ff..ef1a0d9 100644
--- a/src/main/java/com/olliejw/oremarket/Utils/Stats.java
+++ b/src/main/java/com/olliejw/oremarket/Utils/Stats.java
@@ -33,4 +33,5 @@ public class Stats {
}, 0L, 10*20);
}
+
}
diff --git a/src/main/java/com/olliejw/oremarket/Utils/Updates.java b/src/main/java/com/olliejw/oremarket/Utils/Updates.java
new file mode 100644
index 0000000..39560e8
--- /dev/null
+++ b/src/main/java/com/olliejw/oremarket/Utils/Updates.java
@@ -0,0 +1,33 @@
+package com.olliejw.oremarket.Utils;
+
+import org.bukkit.Bukkit;
+import org.bukkit.plugin.java.JavaPlugin;
+import org.bukkit.util.Consumer;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Scanner;
+
+public class Updates {
+
+ private final JavaPlugin plugin;
+ private final int resourceId;
+
+ public Updates(JavaPlugin plugin, int resourceId) {
+ this.plugin = plugin;
+ this.resourceId = resourceId;
+ }
+
+ public void getVersion(final Consumer consumer) {
+ Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
+ try (InputStream inputStream = new URL("https://api.spigotmc.org/legacy/update.php?resource=" + this.resourceId).openStream(); Scanner scanner = new Scanner(inputStream)) {
+ if (scanner.hasNext()) {
+ consumer.accept(scanner.next());
+ }
+ } catch (IOException exception) {
+ this.plugin.getLogger().info("Cannot look for updates: " + exception.getMessage());
+ }
+ });
+ }
+}
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index 5bb6bd5..c2f636b 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -4,7 +4,7 @@
prefix: '&bOreMarket '
-valueupdates:
+valuemessage:
# Time (in minutes) to send this message
time: 5
# The below will look like: (These values are just examples)
@@ -24,7 +24,7 @@ multiplier: 0.01
# As this is experimental I recommend that you do not enable this with a server full of people
marketcrash:
enabled: false
- time: 8 # Hours
+ time: 8 # Hours to repeat
amount: 80 # Amount (%) the values of ores will decrease
message: >
&4&lMARKET CRASH! ORE VALUES DECREASED BY UP TO [amount]%
diff --git a/src/main/resources/gui.yml b/src/main/resources/gui.yml
index ee3eb7a..8aee281 100644
--- a/src/main/resources/gui.yml
+++ b/src/main/resources/gui.yml
@@ -51,7 +51,8 @@ items:
name: '&cClose'
lore:
- '&cClose GUI'
- close: true
+ commands:
+ - '[close]'
hide: true
6:
@@ -59,4 +60,6 @@ items:
name: '&aBalance'
lore:
- '&a$[balance]'
+ commands:
+ - '[msg] Your balance: [balance]'
hide: true
\ No newline at end of file
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 33d9023..8e4cb4f 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -3,6 +3,7 @@ version: ${project.version}
main: com.olliejw.oremarket.OreMarket
api-version: 1.16
depend: [ Vault ]
+softdepend: [ PlaceholderAPI ]
authors: [ OllieJW ]
description: Realistic stock market for ores