diff --git a/jars/Vault.jar b/jars/Vault.jar new file mode 100644 index 0000000..4bcaa89 Binary files /dev/null and b/jars/Vault.jar differ diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..d7ee412 --- /dev/null +++ b/pom.xml @@ -0,0 +1,82 @@ + + + 4.0.0 + + com.olliejw + OreMarket + 2.0-ALPHA + jar + + OreMarket + + Realistic stock market for ores + + 1.8 + UTF-8 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.4 + + + package + + shade + + + false + + + + + + + + src/main/resources + true + + + + + + + spigotmc-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + sonatype + https://oss.sonatype.org/content/groups/public/ + + + + + + org.spigotmc + spigot-api + 1.16.5-R0.1-SNAPSHOT + provided + + + com.github.MilkBowl + VaultAPI + 1.7 + system + ${project.basedir}/jars/Vault.jar + + + diff --git a/src/main/java/com/olliejw/oremarket/Commands/Reload.java b/src/main/java/com/olliejw/oremarket/Commands/Reload.java new file mode 100644 index 0000000..ef85c98 --- /dev/null +++ b/src/main/java/com/olliejw/oremarket/Commands/Reload.java @@ -0,0 +1,17 @@ +package com.olliejw.oremarket.Commands; + +import com.olliejw.oremarket.OreMarket; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; + +public class Reload implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + OreMarket.main().reloadConfig(); + sender.sendMessage(ChatColor.GREEN + "Reloaded successfully"); + return true; + } +} diff --git a/src/main/java/com/olliejw/oremarket/OreMarket.java b/src/main/java/com/olliejw/oremarket/OreMarket.java new file mode 100644 index 0000000..04ff2b9 --- /dev/null +++ b/src/main/java/com/olliejw/oremarket/OreMarket.java @@ -0,0 +1,52 @@ +package com.olliejw.oremarket; + +import com.olliejw.oremarket.Commands.Reload; +import com.olliejw.oremarket.Utils.MarketGUI; +import net.milkbowl.vault.economy.Economy; +import org.bukkit.plugin.RegisteredServiceProvider; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.logging.Logger; + +public final class OreMarket extends JavaPlugin { + + private static OreMarket instance; + private static final Logger log = Logger.getLogger("Minecraft"); + private static Economy econ = null; + + public void onEnable() { + instance = this; + + saveDefaultConfig(); + this.getServer().getPluginManager().registerEvents(new MarketGUI(), this); + this.getCommand("openmarket").setExecutor(new MarketGUI()); + this.getCommand("om-reload").setExecutor(new Reload()); + + if (!setupEconomy() ) { + log.severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName())); + getServer().getPluginManager().disablePlugin(this); + return; + } + } + + public static OreMarket main(){ + return instance; + } + + private boolean setupEconomy() { + if (getServer().getPluginManager().getPlugin("Vault") == null) { + return false; + } + RegisteredServiceProvider rsp = getServer().getServicesManager().getRegistration(Economy.class); + if (rsp == null) { + return false; + } + econ = rsp.getProvider(); + return econ != null; + } + + public static Economy getEconomy() { + return econ; + } +} + diff --git a/src/main/java/com/olliejw/oremarket/Utils/MarketGUI.java b/src/main/java/com/olliejw/oremarket/Utils/MarketGUI.java new file mode 100644 index 0000000..c9702e2 --- /dev/null +++ b/src/main/java/com/olliejw/oremarket/Utils/MarketGUI.java @@ -0,0 +1,70 @@ +package com.olliejw.oremarket.Utils; + +import com.olliejw.oremarket.OreMarket; +import net.milkbowl.vault.economy.EconomyResponse; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +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.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryDragEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.Objects; + +public class MarketGUI implements Listener, CommandExecutor { + Inventory inv = Bukkit.createInventory(null, 27, "OreMarket Coming soon!"); + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (command.getName().equalsIgnoreCase("openmarket")) { + Player player = (Player) sender; + + for (String key : OreMarket.main().getConfig().getConfigurationSection("items").getKeys(false)) { + ConfigurationSection keySection = OreMarket.main().getConfig().getConfigurationSection("items").getConfigurationSection(key); + assert keySection != null; + + ItemStack item = new ItemStack(Material.matchMaterial(keySection.getString("item"))); + ItemMeta meta = item.getItemMeta(); + meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', keySection.getString("name"))); + item.setItemMeta(meta); + + inv.setItem(Integer.parseInt(key), item); + player.openInventory(inv); + } + } + return true; + } + + @EventHandler + public void dragEvent (InventoryDragEvent event) { + if (event.getInventory() == inv) { + event.setCancelled(true); + } + } + @EventHandler + public void clickEvent (InventoryClickEvent event) { + Player player = (Player) event.getWhoClicked(); + + int pay = OreMarket.main().getConfig().getInt("items." + event.getSlot() + ".value"); + EconomyResponse r = OreMarket.getEconomy().depositPlayer(event.getWhoClicked().getName(), pay); + + if(r.transactionSuccess()) { + event.getWhoClicked().sendMessage(String.format("You were given %s and now have %s", OreMarket.getEconomy().format(r.amount), OreMarket.getEconomy().format(r.balance))); + } else { + event.getWhoClicked().sendMessage(String.format("An error occured: %s", r.errorMessage)); + } + + event.setCancelled(true); + + } +} + diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..9ab1e58 --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,29 @@ +# Cost = Initial cost of ore. (0% change) +# Value = Current cost of ore. (With % change) +# When adding a new ore make the cost and value to same + +items: + 0: + item: DIAMOND + name: '&bDiamond Ore' + lore: + - '&a$1000' + cost: 1000 + value: 1000 + + 1: + item: GOLD_INGOT + name: '&6Gold Ingot' + lore: + - '&a$500' + cost: 500 + value: 500 + + 2: + item: IRON_INGOT + name: '&7Iron Ore' + lore: + - '&a$250' + cost: 250 + value: 250 + diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..53e1eb6 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,15 @@ +name: OreMarket +version: ${project.version} +main: com.olliejw.oremarket.OreMarket +api-version: 1.16 +depend: [ Vault ] +authors: [ OllieJW ] +description: Realistic stock market for ores + +commands: + openmarket: + description: Opens OreMarket GUI + usage: / + om-reload: + description: Reloads OreMarket + usage: / \ No newline at end of file