Skip to content

Commit

Permalink
2.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
OllieJW authored Nov 25, 2021
1 parent 4200669 commit 750dd28
Show file tree
Hide file tree
Showing 7 changed files with 202 additions and 57 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.3.2</version>
<version>2.5.0</version>
<packaging>jar</packaging>

<name>OreMarket</name>
Expand Down
41 changes: 21 additions & 20 deletions src/main/java/me/olliejw/oremarket/OreMarket.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,27 +181,28 @@ public static Economy getEconomy() {
}

public void logToFile(String string) {
try {
File dataFolder = getDataFolder();
if(!dataFolder.exists()) {
dataFolder.mkdir();
}
File logsFile = new File(getDataFolder(), "logs.txt");
if (!logsFile.exists()) {
logsFile.createNewFile();
if (getConfig().getBoolean("logs.enabled"))
try {
File dataFolder = getDataFolder();
if(!dataFolder.exists()) {
dataFolder.mkdir();
}
File logsFile = new File(getDataFolder(), "logs.txt");
if (!logsFile.exists()) {
logsFile.createNewFile();
}

SimpleDateFormat formatter = new SimpleDateFormat("[dd/MM/yyyy HH:mm:ss]: ");
Date date = new Date(System.currentTimeMillis());

FileWriter fw = new FileWriter(logsFile, true);
PrintWriter pw = new PrintWriter(fw);
pw.println(formatter.format(date) + ChatColor.stripColor(string.replaceAll("&", "§")));
pw.flush();
pw.close();
} catch (IOException e) {
e.printStackTrace();
}

SimpleDateFormat formatter = new SimpleDateFormat("[dd/MM/yyyy HH:mm:ss]: ");
Date date = new Date(System.currentTimeMillis());

FileWriter fw = new FileWriter(logsFile, true);
PrintWriter pw = new PrintWriter(fw);
pw.println(formatter.format(date) + ChatColor.stripColor(string.replaceAll("&", "§")));
pw.flush();
pw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

2 changes: 1 addition & 1 deletion src/main/java/me/olliejw/oremarket/chat/ValueUpdates.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void announceValue() {
assert message != null;

for (Player player: Bukkit.getOnlinePlayers()) {
if (keySection.getBoolean("hide")) {
if (keySection.getBoolean(".flags.hide")) {
return;
}
player.sendMessage(plh.format(message, player, keySection));
Expand Down
45 changes: 26 additions & 19 deletions src/main/java/me/olliejw/oremarket/listeners/InventoryEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,37 @@
import java.util.Objects;

public class InventoryEvents implements Listener {
private double calculateTotalWithTax(double price, boolean operation) {
private double calculateTotalWithTax(double price) {
double tax = OreMarket.main().getConfig().getDouble("tax", 0.0);
double total;
if (tax == 0.0) {
total = price;
} else {
if (operation) {
total = (price + (price * (tax/100)));
} else {
total = (price - (price * (tax/100)));
}
}
return total;
return price - (tax/100);
}
private void changePlayerBalance(double Money, HumanEntity player, boolean operation, int Slot) { // Buy
double total = calculateTotalWithTax(Money, operation);
if (Money > 0) {
if (operation) { // true is take, false is give
OreMarket.getEconomy().withdrawPlayer((OfflinePlayer) player, total);
private void changePlayerBalance(double previous, HumanEntity player, boolean operation, int Slot) { // Buy
/**
@param previous = Ore Value before any changes
@param player = Player whose balance will be changes
@param operation = T=Add F=Remove money
@param slot = Slot's ore that's value will be affected
*/

double total = calculateTotalWithTax(previous);

if (previous > 0) {
if (operation) {
OreMarket.getEconomy().withdrawPlayer((OfflinePlayer) player, previous-(total*OreMarket.main().getConfig().getDouble("multiplier")));
OreMarket.main().getGuiConfig().set("items." + Slot + ".value",
previous+(total*OreMarket.main().getConfig().getDouble("multiplier")));
// 1000 + (120 x 0.01)
// 1000 + 1.12
// 1000 -> 1001.12
} else {
OreMarket.getEconomy().depositPlayer((OfflinePlayer) player, total);
OreMarket.getEconomy().depositPlayer((OfflinePlayer) player, previous-(total*OreMarket.main().getConfig().getDouble("multiplier")));
OreMarket.main().getGuiConfig().set("items." + Slot + ".value",
previous-(total*OreMarket.main().getConfig().getDouble("multiplier")));
// 1000 - (80 x 0.01)
// 1000 - 0.08
// 1000 -> 999.92
}
}
OreMarket.main().getGuiConfig().set("items." + Slot + ".value", total+(total*(OreMarket.main().getConfig().getDouble("multiplier", 0.01))));
OreMarket.main().saveGuiConfig();
}
private double balance (HumanEntity Player) {
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/me/olliejw/oremarket/menus/MainGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ public void createGUI (Player player) {
}

// Set values
assert name != null;
if (name == null) {
// If a name is not given, we will make it blank
name = " ";
}

meta.setDisplayName(plh.format(name, player, keySection));
meta.setLore(lore);
item.setItemMeta(meta);
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

prefix: '&bOreMarket '

# Logs.txt settings. More soon
logs:
enabled: true

valuemessage:
enabled: true
# Time (in minutes) to send this message
Expand Down
159 changes: 144 additions & 15 deletions src/main/resources/gui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ gui:
rows: 3

items:
0:

# Buyable items
'11':
item: DIAMOND
name: '&bDiamond Ore'
lore:
Expand All @@ -17,11 +19,11 @@ items:
- '&7Left-Click to sell'
cost: 1000
value: 1000
stock: 100
stock: 25
flags:
buy-sound: BLOCK_ANVIL_PLACE
sell-sound: BLOCK_CHEST_OPEN
1:
'12':
item: GOLD_INGOT
name: '&6Gold Ingot'
lore:
Expand All @@ -33,9 +35,8 @@ items:
- '&7Left-Click to sell'
cost: 500
value: 500
stock: 100

2:
stock: 50
'13':
item: IRON_INGOT
name: '&7Iron Ore'
lore:
Expand All @@ -48,8 +49,44 @@ items:
cost: 250
value: 250
stock: 100
'14':
item: NETHERITE_INGOT
name: '&dNetherite Ore'
lore:
- '&aValue: $[value]'
- '&aOriginal: $[cost]'
- '&aStock: [stock]'
- '&aChange: [percent]%'
- '&7Right-Click to buy'
- '&7Left-Click to sell'
cost: 2500
value: 2500
stock: 10
'15':
item: EMERALD
name: '&aEmerald'
lore:
- '&aValue: $[value]'
- '&aOriginal: $[cost]'
- '&aStock: [stock]'
- '&aChange: [percent]%'
- '&7Right-Click to buy'
- '&7Left-Click to sell'
cost: 1250
value: 1250
stock: 15

5:
# Command Items
'18':
item: PAPER
name: '&aBalance'
lore:
- '&a$[balance]'
commands:
- '[msg] Your balance: [balance]'
flags:
hide: true
'26':
item: BARRIER
name: '&cClose'
lore:
Expand All @@ -59,12 +96,104 @@ items:
flags:
hide: true

6:
item: PAPER
name: '&aBalance'
lore:
- '&a$[balance]'
commands:
- '[msg] Your balance: [balance]'
# Style items
'9':
item: RED_STAINED_GLASS_PANE
name: ' '
flags:
hide: true
'0':
item: RED_STAINED_GLASS_PANE
name: ' '
flags:
hide: true
'1':
item: RED_STAINED_GLASS_PANE
name: ' '
flags:
hide: true
hide: true
'2':
item: RED_STAINED_GLASS_PANE
name: ' '
flags:
hide: true
'3':
item: RED_STAINED_GLASS_PANE
name: ' '
flags:
hide: true
'4':
item: RED_STAINED_GLASS_PANE
name: ' '
flags:
hide: true
'5':
item: RED_STAINED_GLASS_PANE
name: ' '
flags:
hide: true
'6':
item: RED_STAINED_GLASS_PANE
name: ' '
flags:
hide: true
'7':
item: RED_STAINED_GLASS_PANE
name: ' '
flags:
hide: true
'8':
item: RED_STAINED_GLASS_PANE
name: ' '
flags:
hide: true
'17':
item: RED_STAINED_GLASS_PANE
name: ' '
flags:
hide: true
'19':
item: RED_STAINED_GLASS_PANE
name: ' '
flags:
hide: true
'20':
item: RED_STAINED_GLASS_PANE
name: ' '
flags:
hide: true
'21':
item: RED_STAINED_GLASS_PANE
name: ' '
flags:
hide: true
'22':
item: RED_STAINED_GLASS_PANE
name: ' '
flags:
hide: true
'23':
item: RED_STAINED_GLASS_PANE
name: ' '
flags:
hide: true
'24':
item: RED_STAINED_GLASS_PANE
name: ' '
flags:
hide: true
'25':
item: RED_STAINED_GLASS_PANE
name: ' '
flags:
hide: true
'10':
item: GREEN_STAINED_GLASS_PANE
name: ' '
flags:
hide: true
'16':
item: GREEN_STAINED_GLASS_PANE
name: ' '
flags:
hide: true

0 comments on commit 750dd28

Please sign in to comment.