Uploaded v2.0-ALPHA

This commit is contained in:
OllieJW 2021-07-03 16:44:44 +01:00 committed by GitHub
parent 2b047cb6d1
commit 6544b5ddba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 265 additions and 0 deletions

BIN
jars/Vault.jar Normal file

Binary file not shown.

82
pom.xml Normal file
View File

@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.olliejw</groupId>
<artifactId>OreMarket</artifactId>
<version>2.0-ALPHA</version>
<packaging>jar</packaging>
<name>OreMarket</name>
<description>Realistic stock market for ores</description>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<repositories>
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.5-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.MilkBowl</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.7</version>
<scope>system</scope>
<systemPath>${project.basedir}/jars/Vault.jar</systemPath>
</dependency>
</dependencies>
</project>

View File

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

View File

@ -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<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
if (rsp == null) {
return false;
}
econ = rsp.getProvider();
return econ != null;
}
public static Economy getEconomy() {
return econ;
}
}

View File

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

View File

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

View File

@ -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: /<command>
om-reload:
description: Reloads OreMarket
usage: /<command>