Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
OllieJW authored Sep 22, 2021
1 parent 1994e87 commit bf5ba94
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 29 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.olliejw</groupId>
<artifactId>OreMarket</artifactId>
<version>2.2.3</version>
<version>2.2.5</version>
<packaging>jar</packaging>

<name>OreMarket</name>
Expand Down
32 changes: 30 additions & 2 deletions src/main/java/me/olliejw/oremarket/OreMarket.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import me.olliejw.oremarket.utils.Placeholders;
import me.olliejw.oremarket.utils.Stats;
import me.olliejw.oremarket.utils.Updates;
import net.milkbowl.vault.chat.Chat;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
Expand Down Expand Up @@ -38,15 +39,15 @@ public final class OreMarket extends JavaPlugin implements Listener {
public void onEnable() {
saveDefaultConfig();
createGuiConfig();

createMsgConfig();
instance = this;

// Spigot and bStats
new Updates(this, 91015).getVersion(version -> {
if (this.getDescription().getVersion().equalsIgnoreCase(version)) {
this.getServer().getConsoleSender().sendMessage(ChatColor.AQUA + " ___ __ __ ");
this.getServer().getConsoleSender().sendMessage(ChatColor.AQUA + " / _ \\ | \\/ | " + ChatColor.GREEN +"OreMarket v"+this.getDescription().getVersion());
this.getServer().getConsoleSender().sendMessage(ChatColor.AQUA + " | (_) || |\\/| |");
this.getServer().getConsoleSender().sendMessage(ChatColor.AQUA + " | (_) || |\\/| | " + ChatColor.GREEN +"Up to date!");
this.getServer().getConsoleSender().sendMessage(ChatColor.AQUA + " \\___/ |_| |_|");
this.getServer().getConsoleSender().sendMessage("");
}
Expand Down Expand Up @@ -134,6 +135,33 @@ public void reloadGuiConfig() {
}
}

private File msgFile;
private FileConfiguration msgConfig;
public FileConfiguration getMsgConfig() {
return this.msgConfig;
}
private void createMsgConfig() {
msgFile = new File(getDataFolder(), "messages.yml");
if (!msgFile.exists()) {
msgFile.getParentFile().mkdirs();
saveResource("messages.yml", false);
}

msgConfig = new YamlConfiguration();
try {
msgConfig.load(msgFile);
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
}
public void reloadMsgConfig() {
try {
msgConfig.load(msgFile);
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
}

public static OreMarket main(){
return instance;
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/me/olliejw/oremarket/commands/CrashMarket.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package me.olliejw.oremarket.commands;

import me.olliejw.oremarket.OreMarket;
import me.olliejw.oremarket.events.MarketCrash;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
Expand All @@ -12,6 +14,9 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
if (command.getName().equalsIgnoreCase("om-crash")) {
if (sender.hasPermission("oremarket.crashmarket")) {
mkCrash.forceCrash();
} else {
String message = OreMarket.main().getMsgConfig().getString("messages.insufficient-permission", "&cYou do not have permission to do this!");
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
}
}
return true;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/me/olliejw/oremarket/commands/OpenMarket.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package me.olliejw.oremarket.commands;

import me.olliejw.oremarket.OreMarket;
import me.olliejw.oremarket.menus.MainGUI;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
Expand All @@ -13,6 +15,9 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
if (command.getName().equalsIgnoreCase("openmarket")) {
if (sender.hasPermission("oremarket.open")) {
mainGUI.createGUI((Player) sender);
} else {
String message = OreMarket.main().getMsgConfig().getString("messages.insufficient-permission", "&cYou do not have permission to do this!");
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
}
}
return true;
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/me/olliejw/oremarket/commands/Reload.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
if (sender.hasPermission("oremarket.reload")) {
OreMarket.main().reloadConfig();
OreMarket.main().reloadGuiConfig();
sender.sendMessage(ChatColor.GREEN + "Reloaded successfully. Some options may require a restart to take place.");
String message = OreMarket.main().getMsgConfig().getString("messages.reload", "&aReloaded successfully. Some options may require a restart to take place.");
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
} else {
sender.sendMessage(ChatColor.RED + "You do not have permission to do this!");
String message = OreMarket.main().getMsgConfig().getString("messages.insufficient-permission", "&cYou do not have permission to do this!");
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package me.olliejw.oremarket.commands;

import me.olliejw.oremarket.OreMarket;
import me.olliejw.oremarket.utils.Stats;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
Expand All @@ -14,6 +16,9 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
sender.sendMessage("Total Items: " + stats.totalItems());
sender.sendMessage("Total Value: " + stats.totalValues());
sender.sendMessage("https://bstats.org/plugin/bukkit/OreMarket/10961");
} else {
String message = OreMarket.main().getMsgConfig().getString("messages.insufficient-permission", "&cYou do not have permission to do this!");
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
}
}
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/olliejw/oremarket/events/MarketCrash.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class MarketCrash implements Listener {
public void forceCrash() {
// Notification
String notification = OreMarket.main().getConfig().getString("marketcrash.message");
String notification = OreMarket.main().getMsgConfig().getString("messages.market-crash");
for (Player player: Bukkit.getOnlinePlayers()) {
assert notification != null;
String message = ChatColor.translateAlternateColorCodes('&', notification).replace("[amount]", Objects.requireNonNull(OreMarket.main().getConfig().getString("marketcrash.amount")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ private double calculateTotalWithTax(double price, boolean operation) {
total = price;
} else {
if (operation) {
total = (price + (price/tax));
total = (price + (price * (tax/100)));
} else {
total = (price - (price/tax));
total = (price - (price * (tax/100)));
}
}
return total;
Expand Down Expand Up @@ -76,7 +76,6 @@ public void clickEvent (InventoryClickEvent event) {
int slot = event.getSlot();

if (OreMarket.main().getGuiConfig().contains("items." + event.getSlot() + ".commands")) {

for (String command : Objects.requireNonNull(OreMarket.main().getGuiConfig().getStringList("items." + event.getSlot() + ".commands"))) {
if (command != null) {
assert keySection != null;
Expand All @@ -98,13 +97,13 @@ else if (toSend.contains("[msg]")) {
if ((event.getClick() == ClickType.LEFT)) { // Sell Mode
if (OreMarket.main().getGuiConfig().getBoolean("items." + event.getSlot() + ".buyonly")) {
// You cannot sell this, Buy only item
String message = OreMarket.main().getGuiConfig().getString("messages.buy-only", "&cThis item can only be bought");
String message = OreMarket.main().getMsgConfig().getString("messages.buy-only", "&cThis item can only be bought");
player.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
return;
}

if (!(playerInventory.containsAtLeast(clickedItem, 1))) {
String message = OreMarket.main().getGuiConfig().getString("messages.no-item", "&cYou don't have that item!");
String message = OreMarket.main().getMsgConfig().getString("messages.no-item", "&cYou don't have that item!");
player.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
return;
}
Expand All @@ -125,13 +124,13 @@ else if (toSend.contains("[msg]")) {
OreMarket.main().getGuiConfig().set("items." + slot + ".stock", itemStock+1);
OreMarket.main().saveGuiConfig();

String message = OreMarket.main().getGuiConfig().getString("messages.successfully-bought", "&aYou have successfully bought this item!");
String message = OreMarket.main().getMsgConfig().getString("messages.successfully-sold", "&aYou have successfully sold this item!");
player.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
}
if ((event.getClick() == ClickType.RIGHT)) { // Buy Mode
if (OreMarket.main().getGuiConfig().getBoolean("items." + event.getSlot() + ".sellonly")) {
// You cannot buy this, Sell only item
String message = OreMarket.main().getGuiConfig().getString("messages.sell-only", "&cThis item can only be sold");
String message = OreMarket.main().getMsgConfig().getString("messages.sell-only", "&cThis item can only be sold");
player.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
return;
}
Expand All @@ -140,7 +139,7 @@ else if (toSend.contains("[msg]")) {
int itemStock = OreMarket.main().getGuiConfig().getInt("items." + slot + ".stock");

if (balance(player) < itemValue) {
String message = OreMarket.main().getGuiConfig().getString("insufficient-balance", "&cYou don't have enough money to buy this item!");
String message = OreMarket.main().getMsgConfig().getString("messages.insufficient-balance", "&cYou don't have enough money to buy this item!");
player.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
return;
}
Expand All @@ -158,7 +157,7 @@ else if (toSend.contains("[msg]")) {
OreMarket.main().getGuiConfig().set("items." + slot + ".stock", itemStock-1);
OreMarket.main().saveGuiConfig();

String message = OreMarket.main().getGuiConfig().getString("messages.successfully-sold", "&aYou have successfully bought the item!");
String message = OreMarket.main().getMsgConfig().getString("messages.successfully-bought", "&aYou have successfully bought the item!");
player.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
}
mainGUI.createGUI((Player) player); // Reload GUI
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/me/olliejw/oremarket/utils/Placeholders.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ public String format(String string, HumanEntity player, ConfigurationSection con
return PlaceholderAPI.setPlaceholders(playerObj, formatted);
}


// Placeholder API

@Override
public boolean canRegister() {
return true;
Expand Down
10 changes: 0 additions & 10 deletions src/main/resources/gui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@ gui:
title: '&4OreMarket'
rows: 3

messages:
sell-only: "&cThis item can only be sold!"
buy-only: "&cThis item can only be bought"
no-item: "&cYou don't have that item!"
insufficient-balance: "&cYou don't have enough money to buy this item!"
price-too-low: "&cPrice of item is too low for buying!"
no-stocks: "&cMarket is run out of item stocks!"
successfully-bought: "&aYou have successfully bought the item!"
successfully-sold: "&aYou have successfully sold the item!"

items:
0:
item: DIAMOND
Expand Down
15 changes: 15 additions & 0 deletions src/main/resources/messages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
messages:
# GUI
sell-only: "&cThis item can only be sold!"
buy-only: "&cThis item can only be bought"
no-item: "&cYou don't have that item!"
insufficient-balance: "&cYou don't have enough money to buy this item!"
price-too-low: "&cPrice of item is too low for buying!"
no-stocks: "&cMarket is run out of item stocks!"
successfully-bought: "&aYou have successfully bought the item!"
successfully-sold: "&aYou have successfully sold the item!"
# Market Crash
market-crash: "&4&lMARKET CRASH! ORE VALUES DECREASED BY UP TO [amount]%"
# Commands
insufficient-permission: "&cYou do not have permission to do this!"
reload: "&aReloaded successfully. Some options may require a restart to take place."
4 changes: 2 additions & 2 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ permissions:
oremarket.reload:
default: op
oremarket.open:
default: not op
default: true
oremarket.stats:
default: not op
default: true

0 comments on commit bf5ba94

Please sign in to comment.