mirror of
https://github.com/amalthea-mc/Ore-Market.git
synced 2024-11-09 12:11:08 +00:00
Added 2.1.0 files
https://www.spigotmc.org/resources/ore-market-stock-market-for-ores-in-minecraft.91015/updates
This commit is contained in:
parent
5c42384d91
commit
a559b0d606
@ -1,44 +1,33 @@
|
|||||||
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 org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
|
||||||
import java.text.Format;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class ValueUpdates {
|
public class ValueUpdates {
|
||||||
|
PlaceHolders plh = new PlaceHolders();
|
||||||
|
|
||||||
public void announceValue() {
|
public void announceValue() {
|
||||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(OreMarket.main(), new Runnable() {
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(OreMarket.main(), () -> {
|
||||||
@Override
|
for (String key : Objects.requireNonNull(OreMarket.main().getGuiConfig().getConfigurationSection("items")).getKeys(false)) {
|
||||||
public void run() {
|
ConfigurationSection keySection = Objects.requireNonNull(OreMarket.main().getGuiConfig().getConfigurationSection("items")).getConfigurationSection(key);
|
||||||
for (String oreItem : Objects.requireNonNull(OreMarket.main().getGuiConfig().getConfigurationSection("items")).getKeys(false)) {
|
String message = OreMarket.main().getConfig().getString("valueupdates.format");
|
||||||
ConfigurationSection keySection = Objects.requireNonNull(OreMarket.main().getGuiConfig().getConfigurationSection("items")).getConfigurationSection(oreItem);
|
|
||||||
|
|
||||||
assert keySection != null;
|
assert keySection != null;
|
||||||
String name = Objects.requireNonNull(keySection.getString("name"));
|
assert message != null;
|
||||||
int stock = keySection.getInt("stock");
|
|
||||||
double value = keySection.getDouble("value");
|
|
||||||
double cost = keySection.getDouble("cost");
|
|
||||||
double difference = (value-cost);
|
|
||||||
double change = (value/cost);
|
|
||||||
double percent = (change*100);
|
|
||||||
|
|
||||||
final Format DECIMAL_FORMAT = new DecimalFormat("#0.0#");
|
for (Player player: Bukkit.getOnlinePlayers()) {
|
||||||
String format = ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(OreMarket.main().getConfig().getString("valueupdates.format"))
|
if (keySection.getBoolean("hide")) {
|
||||||
.replace("[name]", name)
|
return;
|
||||||
.replace("[stock]", String.valueOf(stock))
|
}
|
||||||
.replace("[value]", DECIMAL_FORMAT.format(value))
|
player.sendMessage(plh.format(message, player, keySection));
|
||||||
.replace("[cost]", DECIMAL_FORMAT.format(cost))
|
|
||||||
.replace("[change]", DECIMAL_FORMAT.format(difference))
|
|
||||||
.replace("[percent]", DECIMAL_FORMAT.format(percent))
|
|
||||||
);
|
|
||||||
Bukkit.broadcastMessage(format);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}, 0L, (OreMarket.main().getConfig().getInt("valueupdates.time")* 20L*60));
|
}, 0L, (OreMarket.main().getConfig().getInt("valueupdates.time")* 20L*60));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.olliejw.oremarket.Commands;
|
||||||
|
|
||||||
|
import com.olliejw.oremarket.Events.MarketCrash;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class CrashMarket implements CommandExecutor {
|
||||||
|
MarketCrash mkCrash = new MarketCrash();
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
if (command.getName().equalsIgnoreCase("om-crash")) {
|
||||||
|
if (sender.hasPermission("oremarket.crashmarket")) {
|
||||||
|
mkCrash.forceCrash();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
20
src/main/java/com/olliejw/oremarket/Commands/OpenMarket.java
Normal file
20
src/main/java/com/olliejw/oremarket/Commands/OpenMarket.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package com.olliejw.oremarket.Commands;
|
||||||
|
|
||||||
|
import com.olliejw.oremarket.Utils.AddItem;
|
||||||
|
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();
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,8 @@
|
|||||||
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;
|
||||||
@ -10,8 +12,13 @@ public class Reload implements CommandExecutor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
OreMarket.main().reloadConfig();
|
if (sender.hasPermission("oremarket.reload")) {
|
||||||
sender.sendMessage(ChatColor.GREEN + "Reloaded successfully");
|
OreMarket.main().reloadConfig();
|
||||||
|
OreMarket.main().reloadGuiConfig();
|
||||||
|
sender.sendMessage(ChatColor.GREEN + "Reloaded successfully. Some options may require a restart to take place.");
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(ChatColor.RED + "You do not have permission to do this!");
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,24 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
public class StatsCommands implements CommandExecutor {
|
||||||
|
Stats stats = new Stats();
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
if (command.getName().equalsIgnoreCase("om-stats")) {
|
||||||
|
if (sender.hasPermission("oremarket.stats")) {
|
||||||
|
sender.sendMessage("Total Items: " + stats.totalItems());
|
||||||
|
sender.sendMessage("Total Value: " + stats.totalValues());
|
||||||
|
sender.sendMessage("https://bstats.org/plugin/bukkit/OreMarket/10961");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
36
src/main/java/com/olliejw/oremarket/Events/MarketCrash.java
Normal file
36
src/main/java/com/olliejw/oremarket/Events/MarketCrash.java
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package com.olliejw.oremarket.Events;
|
||||||
|
|
||||||
|
import com.olliejw.oremarket.OreMarket;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class MarketCrash implements Listener {
|
||||||
|
public void forceCrash() {
|
||||||
|
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"))));
|
||||||
|
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 10.0F, 1);
|
||||||
|
}
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startCrash() {
|
||||||
|
if (OreMarket.main().getConfig().getBoolean("marketcrash.enabled")) {
|
||||||
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(OreMarket.main(), this::forceCrash, (OreMarket.main().getConfig().getInt("marketcrash.time") * 20L * 60 * 60), (OreMarket.main().getConfig().getInt("marketcrash.time") * 20L * 60 * 60));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
package com.olliejw.oremarket.Listeners;
|
package com.olliejw.oremarket.Listeners;
|
||||||
|
|
||||||
import com.olliejw.oremarket.OreMarket;
|
import com.olliejw.oremarket.OreMarket;
|
||||||
import org.bukkit.Bukkit;
|
import com.olliejw.oremarket.Utils.Stats;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
@ -69,6 +69,8 @@ public class InventoryEvents implements Listener {
|
|||||||
double value = OreMarket.main().getGuiConfig().getDouble("items." + event.getSlot() + ".value"); // Ore Value
|
double value = OreMarket.main().getGuiConfig().getDouble("items." + event.getSlot() + ".value"); // Ore Value
|
||||||
int stock = OreMarket.main().getGuiConfig().getInt("items." + event.getSlot() + ".stock"); // Ore stock
|
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");
|
||||||
|
|
||||||
assert itemConfig != null;
|
assert itemConfig != null;
|
||||||
ItemStack clickedItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(itemConfig))); // Item that user clicked
|
ItemStack clickedItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(itemConfig))); // Item that user clicked
|
||||||
|
|
||||||
@ -90,6 +92,9 @@ public class InventoryEvents implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (close) {
|
||||||
|
player.closeInventory();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,23 +1,35 @@
|
|||||||
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.OpenMarket;
|
||||||
import com.olliejw.oremarket.Commands.Reload;
|
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.Listeners.InventoryEvents;
|
||||||
import com.olliejw.oremarket.Utils.AddItem;
|
import com.olliejw.oremarket.Utils.Stats;
|
||||||
|
import com.olliejw.oremarket.Utils.UpdateChecker;
|
||||||
|
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
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.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.Objects;
|
import java.util.Objects;
|
||||||
|
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 {
|
||||||
ValueUpdates valueUpdates = new ValueUpdates();
|
ValueUpdates valueUpdates = new ValueUpdates();
|
||||||
|
MarketCrash mkCrash = new MarketCrash();
|
||||||
|
Stats stats = new Stats();
|
||||||
|
|
||||||
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;
|
||||||
@ -29,20 +41,49 @@ public final class OreMarket extends JavaPlugin {
|
|||||||
instance = this;
|
instance = this;
|
||||||
saveDefaultConfig();
|
saveDefaultConfig();
|
||||||
createGuiConfig();
|
createGuiConfig();
|
||||||
|
Logger logger = this.getLogger();
|
||||||
|
|
||||||
|
// Spigot and bStats
|
||||||
|
new UpdateChecker(this, 91015).getVersion(version -> {
|
||||||
|
if (this.getDescription().getVersion().equalsIgnoreCase(version)) {
|
||||||
|
logger.info("You are up to date!");
|
||||||
|
} else {
|
||||||
|
logger.info("New updates available!");
|
||||||
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
|
if (player.hasPermission("oremarket.reload")) { player.sendMessage(ChatColor.GREEN + "New OreMarket version available!"); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
final Metrics metrics = new Metrics(this, 10961);
|
final Metrics metrics = new Metrics(this, 10961);
|
||||||
metrics.addCustomChart(new Metrics.SimplePie("", () -> ""));
|
metrics.addCustomChart(new Metrics.SingleLineChart("total_values", new Callable<Integer>() {
|
||||||
|
@Override
|
||||||
|
public Integer call() {
|
||||||
|
return stats.totalValues();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
metrics.addCustomChart(new Metrics.SingleLineChart("total_items", new Callable<Integer>() {
|
||||||
|
@Override
|
||||||
|
public Integer call() {
|
||||||
|
return stats.totalItems();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Commands and Events
|
||||||
this.getServer().getPluginManager().registerEvents(new InventoryEvents(), this);
|
this.getServer().getPluginManager().registerEvents(new InventoryEvents(), this);
|
||||||
Objects.requireNonNull(this.getCommand("openmarket")).setExecutor(new AddItem());
|
Objects.requireNonNull(this.getCommand("openmarket")).setExecutor(new OpenMarket());
|
||||||
Objects.requireNonNull(this.getCommand("om-reload")).setExecutor(new Reload());
|
Objects.requireNonNull(this.getCommand("om-reload")).setExecutor(new Reload());
|
||||||
|
Objects.requireNonNull(this.getCommand("om-stats")).setExecutor(new StatsCommands());
|
||||||
|
Objects.requireNonNull(this.getCommand("om-crash")).setExecutor(new CrashMarket());
|
||||||
|
|
||||||
|
valueUpdates.announceValue();
|
||||||
|
mkCrash.startCrash();
|
||||||
|
stats.reloadStats();
|
||||||
|
|
||||||
|
// Economy
|
||||||
if (!setupEconomy() ) {
|
if (!setupEconomy() ) {
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
valueUpdates.announceValue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileConfiguration getGuiConfig() {
|
public FileConfiguration getGuiConfig() {
|
||||||
@ -71,6 +112,13 @@ public final class OreMarket extends JavaPlugin {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void reloadGuiConfig() {
|
||||||
|
try {
|
||||||
|
guiConfig.load(guiFile);
|
||||||
|
} catch (IOException | InvalidConfigurationException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static OreMarket main(){
|
public static OreMarket main(){
|
||||||
return instance;
|
return instance;
|
||||||
|
@ -4,9 +4,6 @@ import com.olliejw.oremarket.OreMarket;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@ -14,67 +11,42 @@ import org.bukkit.inventory.Inventory;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
|
||||||
import java.text.Format;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class AddItem implements Listener, CommandExecutor {
|
public class AddItem implements Listener {
|
||||||
String title = OreMarket.main().getGuiConfig().getString("gui.title");
|
String title = OreMarket.main().getGuiConfig().getString("gui.title");
|
||||||
int rows = OreMarket.main().getGuiConfig().getInt("gui.rows");
|
int rows = OreMarket.main().getGuiConfig().getInt("gui.rows");
|
||||||
Inventory inv = Bukkit.createInventory(null, rows*9, ChatColor.translateAlternateColorCodes('&', title));
|
Inventory inv = Bukkit.createInventory(null, rows*9, ChatColor.translateAlternateColorCodes('&', title));
|
||||||
|
PlaceHolders plh = new PlaceHolders();
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
@Override
|
assert keySection != null;
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
||||||
if (command.getName().equalsIgnoreCase("openmarket")) {
|
|
||||||
Player player = (Player) sender;
|
|
||||||
|
|
||||||
for (String key : Objects.requireNonNull(OreMarket.main().getGuiConfig().getConfigurationSection("items")).getKeys(false)) {
|
ItemStack item = new ItemStack(Objects.requireNonNull(Material.matchMaterial(Objects.requireNonNull(keySection.getString("item")))));
|
||||||
ConfigurationSection keySection = Objects.requireNonNull(OreMarket.main().getGuiConfig().getConfigurationSection("items")).getConfigurationSection(key);
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
|
||||||
assert keySection != null;
|
|
||||||
int stock = keySection.getInt("stock");
|
|
||||||
|
|
||||||
final Format DECIMAL_FORMAT = new DecimalFormat("#0.0#");
|
|
||||||
double value = keySection.getDouble("value");
|
|
||||||
double cost = keySection.getDouble("cost");
|
|
||||||
double change = (value/cost);
|
|
||||||
double percent = (change*100);
|
|
||||||
|
|
||||||
ItemStack item = new ItemStack(Objects.requireNonNull(Material.matchMaterial(Objects.requireNonNull(keySection.getString("item")))));
|
|
||||||
ItemMeta meta = item.getItemMeta();
|
|
||||||
|
|
||||||
assert meta != null;
|
|
||||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(keySection.getString("name")))
|
|
||||||
.replace("[stock]", DECIMAL_FORMAT.format(stock))
|
|
||||||
.replace("[percent]", DECIMAL_FORMAT.format(percent))
|
|
||||||
.replace("[value]", DECIMAL_FORMAT.format(value))
|
|
||||||
.replace("[cost]", DECIMAL_FORMAT.format(cost))
|
|
||||||
);
|
|
||||||
|
|
||||||
List<String> lore = new ArrayList<>();
|
|
||||||
for (String loreItem : Objects.requireNonNull(keySection.getStringList("lore"))) {
|
|
||||||
String string = ChatColor.translateAlternateColorCodes('&', loreItem)
|
|
||||||
.replace("[stock]", DECIMAL_FORMAT.format(stock))
|
|
||||||
.replace("[percent]", DECIMAL_FORMAT.format(percent))
|
|
||||||
.replace("[value]", DECIMAL_FORMAT.format(value))
|
|
||||||
.replace("[cost]", DECIMAL_FORMAT.format(cost))
|
|
||||||
;
|
|
||||||
lore.add(string);
|
|
||||||
}
|
|
||||||
|
|
||||||
meta.setLore(lore);
|
|
||||||
|
|
||||||
item.setItemMeta(meta);
|
|
||||||
inv.setItem(Integer.parseInt(key), item);
|
|
||||||
player.openInventory(inv);
|
|
||||||
|
|
||||||
|
String name = keySection.getString("name");
|
||||||
|
assert meta != null;
|
||||||
|
assert name != null;
|
||||||
|
meta.setDisplayName(plh.format(name, player, keySection));
|
||||||
|
|
||||||
|
List<String> lore = new ArrayList<>();
|
||||||
|
for (String loreItem : Objects.requireNonNull(keySection.getStringList("lore"))) {
|
||||||
|
String string = plh.format(loreItem, player, keySection);
|
||||||
|
lore.add(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
meta.setLore(lore);
|
||||||
|
|
||||||
|
item.setItemMeta(meta);
|
||||||
|
inv.setItem(Integer.parseInt(key), item);
|
||||||
|
player.openInventory(inv);
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
38
src/main/java/com/olliejw/oremarket/Utils/PlaceHolders.java
Normal file
38
src/main/java/com/olliejw/oremarket/Utils/PlaceHolders.java
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
package com.olliejw.oremarket.Utils;
|
||||||
|
|
||||||
|
import com.olliejw.oremarket.OreMarket;
|
||||||
|
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;
|
||||||
|
|
||||||
|
public class 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;
|
||||||
|
return 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))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
36
src/main/java/com/olliejw/oremarket/Utils/Stats.java
Normal file
36
src/main/java/com/olliejw/oremarket/Utils/Stats.java
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package com.olliejw.oremarket.Utils;
|
||||||
|
|
||||||
|
import com.olliejw.oremarket.OreMarket;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class Stats {
|
||||||
|
|
||||||
|
public int totalItems () {
|
||||||
|
int items = 0;
|
||||||
|
for (String key : Objects.requireNonNull(OreMarket.main().getGuiConfig().getConfigurationSection("items")).getKeys(false)) {
|
||||||
|
items++;
|
||||||
|
}
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int totalValues() {
|
||||||
|
int values = 0;
|
||||||
|
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;
|
||||||
|
values = (values + keySection.getInt("value"));
|
||||||
|
}
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reloadStats() {
|
||||||
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(OreMarket.main(), () -> {
|
||||||
|
totalValues();
|
||||||
|
totalItems();
|
||||||
|
|
||||||
|
}, 0L, 10*20);
|
||||||
|
}
|
||||||
|
}
|
33
src/main/java/com/olliejw/oremarket/Utils/UpdateChecker.java
Normal file
33
src/main/java/com/olliejw/oremarket/Utils/UpdateChecker.java
Normal 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 UpdateChecker {
|
||||||
|
|
||||||
|
private final JavaPlugin plugin;
|
||||||
|
private final int resourceId;
|
||||||
|
|
||||||
|
public UpdateChecker(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());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -10,7 +10,7 @@ valueupdates:
|
|||||||
# The below will look like: (These values are just examples)
|
# The below will look like: (These values are just examples)
|
||||||
# "Diamond is now valued at $500 ($250 / 200% change from the original $250). 100 left in stock!"
|
# "Diamond is now valued at $500 ($250 / 200% change from the original $250). 100 left in stock!"
|
||||||
format: >
|
format: >
|
||||||
[name] is now valued at $[value] ($[change] / [percent]% change from the original [cost]). [stock] left in stock!
|
[name] is now valued at $[value] ($[change] / [percent]% change from the original $[cost]). [stock] left in stock!
|
||||||
|
|
||||||
# Tax (%) is added to every purchase and sale
|
# Tax (%) is added to every purchase and sale
|
||||||
tax: 10
|
tax: 10
|
||||||
@ -20,3 +20,13 @@ tax: 10
|
|||||||
# Default: 0.01 (RECOMMENDED)
|
# Default: 0.01 (RECOMMENDED)
|
||||||
multiplier: 0.01
|
multiplier: 0.01
|
||||||
|
|
||||||
|
# Market Crash is an event that completely kills the values of ores just like real life.
|
||||||
|
# As this is experimental I recommend that you do not enable this with a server full of people
|
||||||
|
marketcrash:
|
||||||
|
enabled: false
|
||||||
|
time: 8 # Hours
|
||||||
|
amount: 80 # Amount (%) the values of ores will decrease
|
||||||
|
message: >
|
||||||
|
&4&lMARKET CRASH! ORE VALUES DECREASED BY UP TO [amount]%
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,27 +1,7 @@
|
|||||||
# Example Item
|
# Customise the GUI here! View the GitHub wiki to utilise all of OreMarkets features
|
||||||
#0:
|
|
||||||
# # Item to be shown in the GUI and given/taken
|
|
||||||
# item: DIAMOND
|
|
||||||
# # Item name (Buying this ore will not give the user an ore with this name!)
|
|
||||||
# name: '&bDiamond Ore'
|
|
||||||
# # Lore (Infinite lines). Find the placeholders here -> https://github.com/OllieJW/Ore-Market/wiki/Placeholders
|
|
||||||
# lore:
|
|
||||||
# - '&aValue: $[value]'
|
|
||||||
# - '&aOriginal: $[cost]'
|
|
||||||
# - '&aStock: [stock]'
|
|
||||||
# - '&aChange: [percent]%'
|
|
||||||
# - '&7Right-Click to buy'
|
|
||||||
# - '&7Left-Click to sell'
|
|
||||||
# # Starting cost of ore
|
|
||||||
# cost: 1000
|
|
||||||
# # Current cost of ore (Changing this will edit the GUI value)
|
|
||||||
# value: 1000
|
|
||||||
# # Stock of the ore (Set to -1 for infinite)
|
|
||||||
# stock: 100
|
|
||||||
|
|
||||||
|
|
||||||
gui:
|
gui:
|
||||||
title: '&6OreMarket'
|
title: '&4OreMarket'
|
||||||
rows: 3
|
rows: 3
|
||||||
|
|
||||||
items:
|
items:
|
||||||
@ -64,4 +44,19 @@ items:
|
|||||||
- '&7Left-Click to sell'
|
- '&7Left-Click to sell'
|
||||||
cost: 250
|
cost: 250
|
||||||
value: 250
|
value: 250
|
||||||
stock: 100
|
stock: 100
|
||||||
|
|
||||||
|
5:
|
||||||
|
item: BARRIER
|
||||||
|
name: '&cClose'
|
||||||
|
lore:
|
||||||
|
- '&cClose GUI'
|
||||||
|
close: true
|
||||||
|
hide: true
|
||||||
|
|
||||||
|
6:
|
||||||
|
item: PAPER
|
||||||
|
name: '&aBalance'
|
||||||
|
lore:
|
||||||
|
- '&a$[balance]'
|
||||||
|
hide: true
|
@ -12,4 +12,10 @@ commands:
|
|||||||
usage: /<command>
|
usage: /<command>
|
||||||
om-reload:
|
om-reload:
|
||||||
description: Reloads OreMarket
|
description: Reloads OreMarket
|
||||||
|
usage: /<command>
|
||||||
|
om-stats:
|
||||||
|
description: Shows OreMarket stats
|
||||||
|
usage: /<command>
|
||||||
|
om-crash:
|
||||||
|
description: Crashes Market
|
||||||
usage: /<command>
|
usage: /<command>
|
Loading…
Reference in New Issue
Block a user