Version 2.2.0 files

This commit is contained in:
OllieJW 2021-07-17 17:06:10 +01:00 committed by GitHub
parent a559b0d606
commit fc90bd13ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 338 additions and 61 deletions

Binary file not shown.

13
pom.xml
View File

@ -6,7 +6,7 @@
<groupId>com.olliejw</groupId> <groupId>com.olliejw</groupId>
<artifactId>OreMarket</artifactId> <artifactId>OreMarket</artifactId>
<version>2.0-ALPHA</version> <version>2.2.0</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>OreMarket</name> <name>OreMarket</name>
@ -62,6 +62,10 @@
<id>sonatype</id> <id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url> <url>https://oss.sonatype.org/content/groups/public/</url>
</repository> </repository>
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
</repositories> </repositories>
<dependencies> <dependencies>
@ -78,5 +82,12 @@
<scope>system</scope> <scope>system</scope>
<systemPath>${project.basedir}/jars/Vault.jar</systemPath> <systemPath>${project.basedir}/jars/Vault.jar</systemPath>
</dependency> </dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.10.10</version>
<scope>system</scope>
<systemPath>${project.basedir}/jars/PlaceholderAPI-2.10.10.jar</systemPath>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -1,7 +1,7 @@
package com.olliejw.oremarket.Chat; package com.olliejw.oremarket.Chat;
import com.olliejw.oremarket.OreMarket; import com.olliejw.oremarket.OreMarket;
import com.olliejw.oremarket.Utils.PlaceHolders; import com.olliejw.oremarket.Utils.Placeholders;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -9,13 +9,13 @@ import org.bukkit.entity.Player;
import java.util.Objects; import java.util.Objects;
public class ValueUpdates { public class ValueUpdates {
PlaceHolders plh = new PlaceHolders(); Placeholders plh = new Placeholders();
public void announceValue() { public void announceValue() {
Bukkit.getScheduler().scheduleSyncRepeatingTask(OreMarket.main(), () -> { Bukkit.getScheduler().scheduleSyncRepeatingTask(OreMarket.main(), () -> {
for (String key : Objects.requireNonNull(OreMarket.main().getGuiConfig().getConfigurationSection("items")).getKeys(false)) { for (String key : Objects.requireNonNull(OreMarket.main().getGuiConfig().getConfigurationSection("items")).getKeys(false)) {
ConfigurationSection keySection = Objects.requireNonNull(OreMarket.main().getGuiConfig().getConfigurationSection("items")).getConfigurationSection(key); 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 keySection != null;
assert message != 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));
} }
} }

View File

@ -1,18 +1,18 @@
package com.olliejw.oremarket.Commands; 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.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class OpenMarket implements CommandExecutor { public class OpenMarket implements CommandExecutor {
AddItem addItem = new AddItem(); CreateGUI createGUI = new CreateGUI();
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (command.getName().equalsIgnoreCase("openmarket")) { if (command.getName().equalsIgnoreCase("openmarket")) {
if (sender.hasPermission("oremarket.open")) { if (sender.hasPermission("oremarket.open")) {
addItem.createGUI((Player) sender); createGUI.createGUI((Player) sender);
} }
} }
return true; return true;

View File

@ -1,8 +1,6 @@
package com.olliejw.oremarket.Commands; package com.olliejw.oremarket.Commands;
import com.olliejw.oremarket.Chat.ValueUpdates;
import com.olliejw.oremarket.OreMarket; import com.olliejw.oremarket.OreMarket;
import com.olliejw.oremarket.Utils.AddItem;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;

View File

@ -1,9 +1,6 @@
package com.olliejw.oremarket.Commands; package com.olliejw.oremarket.Commands;
import com.olliejw.oremarket.Utils.Stats; 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.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;

View File

@ -12,21 +12,28 @@ import java.util.Objects;
public class MarketCrash implements Listener { public class MarketCrash implements Listener {
public void forceCrash() { public void forceCrash() {
// Notification
String notification = OreMarket.main().getConfig().getString("marketcrash.message"); String notification = OreMarket.main().getConfig().getString("marketcrash.message");
for (Player player: Bukkit.getOnlinePlayers()) { for (Player player: Bukkit.getOnlinePlayers()) {
assert notification != null; 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); 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)) { for (String key : Objects.requireNonNull(OreMarket.main().getGuiConfig().getConfigurationSection("items")).getKeys(false)) {
ConfigurationSection keySection = Objects.requireNonNull(OreMarket.main().getGuiConfig().getConfigurationSection("items")).getConfigurationSection(key); ConfigurationSection keySection = Objects.requireNonNull(OreMarket.main().getGuiConfig().getConfigurationSection("items")).getConfigurationSection(key);
assert keySection != null; assert keySection != null;
if(keySection.getDouble("value") > 0) {
double value = keySection.getDouble("value"); double value = keySection.getDouble("value");
double amount = OreMarket.main().getConfig().getDouble("marketcrash.amount"); double amount = OreMarket.main().getConfig().getDouble("marketcrash.amount");
keySection.set("value", (value*(1-(amount/100)))); keySection.set("value", (value * (1 - (amount / 100))));
OreMarket.main().saveGuiConfig(); OreMarket.main().saveGuiConfig();
} }
} }
}
public void startCrash() { public void startCrash() {
if (OreMarket.main().getConfig().getBoolean("marketcrash.enabled")) { if (OreMarket.main().getConfig().getBoolean("marketcrash.enabled")) {

View File

@ -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<String> 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;
}
}

View File

@ -1,19 +1,26 @@
package com.olliejw.oremarket.Listeners; package com.olliejw.oremarket.Listeners;
import com.olliejw.oremarket.Inventory.CreateGUI;
import com.olliejw.oremarket.OreMarket; 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.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.HumanEntity; import org.bukkit.entity.HumanEntity;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent; import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import java.text.DecimalFormat;
import java.text.Format;
import java.util.Objects; import java.util.Objects;
public class InventoryEvents implements Listener { public class InventoryEvents implements Listener {
@ -37,9 +44,9 @@ public class InventoryEvents implements Listener {
double currentIncrease = ((Current / 100.0) * (100 + multiplier)); double currentIncrease = ((Current / 100.0) * (100 + multiplier));
double currentDecrease = ((Current / 100.0) * (100 - multiplier)); double currentDecrease = ((Current / 100.0) * (100 - multiplier));
if (Positive) { 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 { } 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(); OreMarket.main().saveGuiConfig();
} }
@ -57,44 +64,76 @@ public class InventoryEvents implements Listener {
} }
String title = ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(OreMarket.main().getGuiConfig().getString("gui.title"))); String title = ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(OreMarket.main().getGuiConfig().getString("gui.title")));
Placeholders plh = new Placeholders();
CreateGUI createGUI = new CreateGUI();
@EventHandler @EventHandler
public void clickEvent (InventoryClickEvent event) { 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 InventoryView playerView = event.getView(); // Player's inventory view
HumanEntity player = event.getWhoClicked(); // Player that clicked 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 (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. if (playerView.getTitle().equals(ChatColor.translateAlternateColorCodes('&', title))) {
double value = OreMarket.main().getGuiConfig().getDouble("items." + event.getSlot() + ".value"); // Ore Value event.setCancelled(true); // I know. Its a bad way of checking.
int stock = OreMarket.main().getGuiConfig().getInt("items." + event.getSlot() + ".stock"); // Ore stock
String itemConfig = OreMarket.main().getGuiConfig().getString("items." + event.getSlot() + ".item"); // Config location of item 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; 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 ((event.getClick() == ClickType.LEFT) && (!OreMarket.main().getGuiConfig().getBoolean("items." + event.getSlot() + ".buyonly"))) { // Sell Mode
if (playerInventory.containsAtLeast(clickedItem, 1)) { 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); playerInventory.removeItem(clickedItem);
}
addMoney(value, player); addMoney(value, player);
valueChange(event.getSlot(), value, true); valueChange(slot, value, true);
stockChange(event.getSlot(), stock, 1, 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 (balance(player) > value) {
if (stock > 1 || stock == -1) { if (value < 1) { return; } if ((stock > 1 || stock == -1) && (value > 1)) {
if (OreMarket.main().getGuiConfig().getBoolean("items." + slot + ".copymeta")) {
playerInventory.addItem(event.getCurrentItem());
}
else {
playerInventory.addItem(clickedItem); playerInventory.addItem(clickedItem);
}
takeMoney(value, player); takeMoney(value, player);
valueChange(event.getSlot(), value, false); valueChange(slot, value, false);
stockChange(event.getSlot(), stock, 1, false); stockChange(slot, stock, 1, false);
} }
} }
} }
if (close) {
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(); player.closeInventory();
} }
else if (toSend.contains("[msg]")) {
player.sendMessage(toSend.replace("[msg] ", ""));
}
else {
Bukkit.dispatchCommand(player, toSend);
}
}
}
} }
} }

View File

@ -9,13 +9,7 @@ import java.io.InputStreamReader;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.*;
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.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
@ -576,10 +570,8 @@ public class Metrics {
/** /**
* Class constructor. * Class constructor.
*
* @param chartId The id of the chart. * @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data. * @param callable The callable which is used to request the chart data.*/
*/
public SimplePie(String chartId, Callable<String> callable) { public SimplePie(String chartId, Callable<String> callable) {
super(chartId); super(chartId);
this.callable = callable; this.callable = callable;

View File

@ -1,4 +1,5 @@
package com.olliejw.oremarket; package com.olliejw.oremarket;
import com.olliejw.oremarket.Chat.ValueUpdates; import com.olliejw.oremarket.Chat.ValueUpdates;
import com.olliejw.oremarket.Commands.CrashMarket; import com.olliejw.oremarket.Commands.CrashMarket;
import com.olliejw.oremarket.Commands.OpenMarket; 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.Commands.StatsCommands;
import com.olliejw.oremarket.Events.MarketCrash; import com.olliejw.oremarket.Events.MarketCrash;
import com.olliejw.oremarket.Listeners.InventoryEvents; import com.olliejw.oremarket.Listeners.InventoryEvents;
import com.olliejw.oremarket.Utils.Placeholders;
import com.olliejw.oremarket.Utils.Stats; 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 net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -16,27 +17,28 @@ import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.logging.Logger; import java.util.logging.Logger;
public final class OreMarket extends JavaPlugin { public final class OreMarket extends JavaPlugin implements Listener {
ValueUpdates valueUpdates = new ValueUpdates(); ValueUpdates valueUpdates = new ValueUpdates();
MarketCrash mkCrash = new MarketCrash(); MarketCrash mkCrash = new MarketCrash();
Stats stats = new Stats(); Stats stats = new Stats();
private File guiFile;
private FileConfiguration guiConfig;
private static OreMarket instance; private static OreMarket instance;
private static final Logger log = Logger.getLogger("Minecraft"); private static final Logger log = Logger.getLogger("Minecraft");
private static Economy econ = null; private static Economy econ = null;
private File guiFile;
private FileConfiguration guiConfig;
public void onEnable() { public void onEnable() {
instance = this; instance = this;
saveDefaultConfig(); saveDefaultConfig();
@ -44,7 +46,7 @@ public final class OreMarket extends JavaPlugin {
Logger logger = this.getLogger(); Logger logger = this.getLogger();
// Spigot and bStats // Spigot and bStats
new UpdateChecker(this, 91015).getVersion(version -> { new Updates(this, 91015).getVersion(version -> {
if (this.getDescription().getVersion().equalsIgnoreCase(version)) { if (this.getDescription().getVersion().equalsIgnoreCase(version)) {
logger.info("You are up to date!"); logger.info("You are up to date!");
} else { } else {
@ -84,7 +86,13 @@ public final class OreMarket extends JavaPlugin {
log.severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName())); log.severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
getServer().getPluginManager().disablePlugin(this); getServer().getPluginManager().disablePlugin(this);
} }
// Placeholder API
if(Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null){
new Placeholders().register();
} }
}
public FileConfiguration getGuiConfig() { public FileConfiguration getGuiConfig() {
return this.guiConfig; return this.guiConfig;
@ -104,7 +112,6 @@ public final class OreMarket extends JavaPlugin {
e.printStackTrace(); e.printStackTrace();
} }
} }
public void saveGuiConfig() { public void saveGuiConfig() {
try { try {
guiConfig.save(guiFile); guiConfig.save(guiFile);
@ -120,6 +127,7 @@ public final class OreMarket extends JavaPlugin {
} }
} }
public static OreMarket main(){ public static OreMarket main(){
return instance; return instance;
} }

View File

@ -0,0 +1,4 @@
package com.olliejw.oremarket.Utils;
public class Economy {
}

View File

@ -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;
}
}

View File

@ -33,4 +33,5 @@ public class Stats {
}, 0L, 10*20); }, 0L, 10*20);
} }
} }

View File

@ -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<String> 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());
}
});
}
}

View File

@ -4,7 +4,7 @@
prefix: '&bOreMarket ' prefix: '&bOreMarket '
valueupdates: valuemessage:
# Time (in minutes) to send this message # Time (in minutes) to send this message
time: 5 time: 5
# The below will look like: (These values are just examples) # 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 # As this is experimental I recommend that you do not enable this with a server full of people
marketcrash: marketcrash:
enabled: false enabled: false
time: 8 # Hours time: 8 # Hours to repeat
amount: 80 # Amount (%) the values of ores will decrease amount: 80 # Amount (%) the values of ores will decrease
message: > message: >
&4&lMARKET CRASH! ORE VALUES DECREASED BY UP TO [amount]% &4&lMARKET CRASH! ORE VALUES DECREASED BY UP TO [amount]%

View File

@ -51,7 +51,8 @@ items:
name: '&cClose' name: '&cClose'
lore: lore:
- '&cClose GUI' - '&cClose GUI'
close: true commands:
- '[close]'
hide: true hide: true
6: 6:
@ -59,4 +60,6 @@ items:
name: '&aBalance' name: '&aBalance'
lore: lore:
- '&a$[balance]' - '&a$[balance]'
commands:
- '[msg] Your balance: [balance]'
hide: true hide: true

View File

@ -3,6 +3,7 @@ version: ${project.version}
main: com.olliejw.oremarket.OreMarket main: com.olliejw.oremarket.OreMarket
api-version: 1.16 api-version: 1.16
depend: [ Vault ] depend: [ Vault ]
softdepend: [ PlaceholderAPI ]
authors: [ OllieJW ] authors: [ OllieJW ]
description: Realistic stock market for ores description: Realistic stock market for ores