mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2025-12-23 08:59:34 +00:00
money format
This commit is contained in:
@@ -7,7 +7,7 @@ plugins {
|
|||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
|
|
||||||
version = "2.1.2"
|
version = "2.1.2.1"
|
||||||
|
|
||||||
apply<JavaPlugin>()
|
apply<JavaPlugin>()
|
||||||
apply(plugin = "java")
|
apply(plugin = "java")
|
||||||
|
|||||||
@@ -24,12 +24,14 @@ import net.momirealms.customfishing.api.mechanic.market.MarketGUIHolder;
|
|||||||
import net.momirealms.customfishing.api.util.InventoryUtils;
|
import net.momirealms.customfishing.api.util.InventoryUtils;
|
||||||
import net.momirealms.customfishing.api.util.LogUtils;
|
import net.momirealms.customfishing.api.util.LogUtils;
|
||||||
import net.momirealms.customfishing.util.ItemUtils;
|
import net.momirealms.customfishing.util.ItemUtils;
|
||||||
|
import net.momirealms.customfishing.util.NumberUtils;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.text.DecimalFormat;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -155,9 +157,11 @@ public class MarketGUI {
|
|||||||
if (totalWorth <= 0) {
|
if (totalWorth <= 0) {
|
||||||
sellElement.setItemStack(
|
sellElement.setItemStack(
|
||||||
manager.getSellIconDenyBuilder().build(owner,
|
manager.getSellIconDenyBuilder().build(owner,
|
||||||
Map.of("{money}", String.format("%.2f", totalWorth)
|
Map.of("{money}", NumberUtils.money(totalWorth)
|
||||||
|
,"{money_formatted}", String.format("%.2f", totalWorth)
|
||||||
,"{player}", owner.getName()
|
,"{player}", owner.getName()
|
||||||
,"{rest}", String.format("%.2f", earningLimit - earningData.earnings)
|
,"{rest}", NumberUtils.money(earningLimit - earningData.earnings)
|
||||||
|
,"{rest_formatted}", String.format("%.2f", (earningLimit - earningData.earnings))
|
||||||
,"{sold-item-amount}", String.valueOf(soldAmount)
|
,"{sold-item-amount}", String.valueOf(soldAmount)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -165,9 +169,11 @@ public class MarketGUI {
|
|||||||
} else if (earningLimit != -1 && (earningLimit - earningData.earnings < totalWorth)) {
|
} else if (earningLimit != -1 && (earningLimit - earningData.earnings < totalWorth)) {
|
||||||
sellElement.setItemStack(
|
sellElement.setItemStack(
|
||||||
manager.getSellIconLimitBuilder().build(owner,
|
manager.getSellIconLimitBuilder().build(owner,
|
||||||
Map.of("{money}", String.format("%.2f", totalWorth)
|
Map.of("{money}", NumberUtils.money(totalWorth)
|
||||||
|
,"{money_formatted}", String.format("%.2f", totalWorth)
|
||||||
,"{player}", owner.getName()
|
,"{player}", owner.getName()
|
||||||
,"{rest}", String.format("%.2f", earningLimit - earningData.earnings)
|
,"{rest}", NumberUtils.money(earningLimit - earningData.earnings)
|
||||||
|
,"{rest_formatted}", String.format("%.2f", (earningLimit - earningData.earnings))
|
||||||
,"{sold-item-amount}", String.valueOf(soldAmount)
|
,"{sold-item-amount}", String.valueOf(soldAmount)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -175,9 +181,11 @@ public class MarketGUI {
|
|||||||
} else {
|
} else {
|
||||||
sellElement.setItemStack(
|
sellElement.setItemStack(
|
||||||
manager.getSellIconAllowBuilder().build(owner,
|
manager.getSellIconAllowBuilder().build(owner,
|
||||||
Map.of("{money}", String.format("%.2f", totalWorth)
|
Map.of("{money}", NumberUtils.money(totalWorth)
|
||||||
|
,"{money_formatted}", String.format("%.2f", totalWorth)
|
||||||
,"{player}", owner.getName()
|
,"{player}", owner.getName()
|
||||||
,"{rest}", String.format("%.2f", earningLimit - earningData.earnings)
|
,"{rest}", NumberUtils.money(earningLimit - earningData.earnings)
|
||||||
|
,"{rest_formatted}", String.format("%.2f", (earningLimit - earningData.earnings))
|
||||||
,"{sold-item-amount}", String.valueOf(soldAmount)
|
,"{sold-item-amount}", String.valueOf(soldAmount)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -199,9 +207,11 @@ public class MarketGUI {
|
|||||||
if (totalWorth <= 0) {
|
if (totalWorth <= 0) {
|
||||||
sellAllElement.setItemStack(
|
sellAllElement.setItemStack(
|
||||||
manager.getSellAllIconDenyBuilder().build(owner,
|
manager.getSellAllIconDenyBuilder().build(owner,
|
||||||
Map.of("{money}", String.format("%.2f", totalWorth)
|
Map.of("{money}", NumberUtils.money(totalWorth)
|
||||||
|
,"{money_formatted}", String.format("%.2f", totalWorth)
|
||||||
,"{player}", owner.getName()
|
,"{player}", owner.getName()
|
||||||
,"{rest}", String.format("%.2f", earningLimit - earningData.earnings)
|
,"{rest}", NumberUtils.money(earningLimit - earningData.earnings)
|
||||||
|
,"{rest_formatted}", String.format("%.2f", (earningLimit - earningData.earnings))
|
||||||
,"{sold-item-amount}", String.valueOf(sellAmount)
|
,"{sold-item-amount}", String.valueOf(sellAmount)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -209,9 +219,11 @@ public class MarketGUI {
|
|||||||
} else if (earningLimit != -1 && (earningLimit - earningData.earnings < totalWorth)) {
|
} else if (earningLimit != -1 && (earningLimit - earningData.earnings < totalWorth)) {
|
||||||
sellAllElement.setItemStack(
|
sellAllElement.setItemStack(
|
||||||
manager.getSellAllIconLimitBuilder().build(owner,
|
manager.getSellAllIconLimitBuilder().build(owner,
|
||||||
Map.of("{money}", String.format("%.2f", totalWorth)
|
Map.of("{money}", NumberUtils.money(totalWorth)
|
||||||
|
,"{money_formatted}", String.format("%.2f", totalWorth)
|
||||||
,"{player}", owner.getName()
|
,"{player}", owner.getName()
|
||||||
,"{rest}", String.format("%.2f", earningLimit - earningData.earnings)
|
,"{rest}", NumberUtils.money(earningLimit - earningData.earnings)
|
||||||
|
,"{rest_formatted}", String.format("%.2f", (earningLimit - earningData.earnings))
|
||||||
,"{sold-item-amount}", String.valueOf(sellAmount)
|
,"{sold-item-amount}", String.valueOf(sellAmount)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -219,9 +231,11 @@ public class MarketGUI {
|
|||||||
} else {
|
} else {
|
||||||
sellAllElement.setItemStack(
|
sellAllElement.setItemStack(
|
||||||
manager.getSellAllIconAllowBuilder().build(owner,
|
manager.getSellAllIconAllowBuilder().build(owner,
|
||||||
Map.of("{money}", String.format("%.2f", totalWorth)
|
Map.of("{money}", NumberUtils.money(totalWorth)
|
||||||
|
,"{money_formatted}", String.format("%.2f", totalWorth)
|
||||||
,"{player}", owner.getName()
|
,"{player}", owner.getName()
|
||||||
,"{rest}", String.format("%.2f", earningLimit - earningData.earnings)
|
,"{rest}", NumberUtils.money(earningLimit - earningData.earnings)
|
||||||
|
,"{rest_formatted}", String.format("%.2f", (earningLimit - earningData.earnings))
|
||||||
,"{sold-item-amount}", String.valueOf(sellAmount)
|
,"{sold-item-amount}", String.valueOf(sellAmount)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import net.momirealms.customfishing.api.scheduler.CancellableTask;
|
|||||||
import net.momirealms.customfishing.api.util.LogUtils;
|
import net.momirealms.customfishing.api.util.LogUtils;
|
||||||
import net.momirealms.customfishing.compatibility.papi.PlaceholderManagerImpl;
|
import net.momirealms.customfishing.compatibility.papi.PlaceholderManagerImpl;
|
||||||
import net.momirealms.customfishing.util.ConfigUtils;
|
import net.momirealms.customfishing.util.ConfigUtils;
|
||||||
|
import net.momirealms.customfishing.util.NumberUtils;
|
||||||
import net.objecthunter.exp4j.ExpressionBuilder;
|
import net.objecthunter.exp4j.ExpressionBuilder;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@@ -47,6 +48,7 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
|||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.text.DecimalFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@@ -327,8 +329,10 @@ public class MarketManagerImpl implements MarketManager, Listener {
|
|||||||
int amount = gui.getSoldAmount();
|
int amount = gui.getSoldAmount();
|
||||||
double earningLimit = getEarningLimit(player);
|
double earningLimit = getEarningLimit(player);
|
||||||
Condition condition = new Condition(player, new HashMap<>(Map.of(
|
Condition condition = new Condition(player, new HashMap<>(Map.of(
|
||||||
"{money}", String.format("%.2f", worth)
|
"{money}", NumberUtils.money(worth),
|
||||||
,"{rest}", String.format("%.2f", (earningLimit - data.earnings))
|
"{rest}", NumberUtils.money(earningLimit - data.earnings),
|
||||||
|
"{money_formatted}", String.format("%.2f", worth)
|
||||||
|
,"{rest_formatted}", String.format("%.2f", (earningLimit - data.earnings))
|
||||||
,"{sold-item-amount}", String.valueOf(amount)
|
,"{sold-item-amount}", String.valueOf(amount)
|
||||||
)));
|
)));
|
||||||
if (worth > 0) {
|
if (worth > 0) {
|
||||||
@@ -343,7 +347,8 @@ public class MarketManagerImpl implements MarketManager, Listener {
|
|||||||
// Clear items and update earnings
|
// Clear items and update earnings
|
||||||
gui.clearWorthyItems();
|
gui.clearWorthyItems();
|
||||||
data.earnings += worth;
|
data.earnings += worth;
|
||||||
condition.insertArg("{rest}", String.format("%.2f", (earningLimit - data.earnings)));
|
condition.insertArg("{rest}", NumberUtils.money(earningLimit - data.earnings));
|
||||||
|
condition.insertArg("{rest_formatted}", String.format("%.2f", (earningLimit - data.earnings)));
|
||||||
if (getSellAllowActions() != null) {
|
if (getSellAllowActions() != null) {
|
||||||
for (Action action : getSellAllowActions()) {
|
for (Action action : getSellAllowActions()) {
|
||||||
action.trigger(condition);
|
action.trigger(condition);
|
||||||
@@ -370,8 +375,10 @@ public class MarketManagerImpl implements MarketManager, Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Condition condition = new Condition(player, new HashMap<>(Map.of(
|
Condition condition = new Condition(player, new HashMap<>(Map.of(
|
||||||
"{money}", String.format("%.2f", worth)
|
"{money}", NumberUtils.money(worth),
|
||||||
,"{rest}", String.format("%.2f", (earningLimit - data.earnings))
|
"{rest}", NumberUtils.money(earningLimit - data.earnings),
|
||||||
|
"{money_formatted}", String.format("%.2f", worth)
|
||||||
|
,"{rest_formatted}", String.format("%.2f", (earningLimit - data.earnings))
|
||||||
,"{sold-item-amount}", String.valueOf(amount)
|
,"{sold-item-amount}", String.valueOf(amount)
|
||||||
)));
|
)));
|
||||||
if (worth > 0) {
|
if (worth > 0) {
|
||||||
@@ -392,7 +399,8 @@ public class MarketManagerImpl implements MarketManager, Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
data.earnings += worth;
|
data.earnings += worth;
|
||||||
condition.insertArg("{rest}", String.format("%.2f", (earningLimit - data.earnings)));
|
condition.insertArg("{rest}", NumberUtils.money(earningLimit - data.earnings));
|
||||||
|
condition.insertArg("{rest_formatted}", String.format("%.2f", (earningLimit - data.earnings)));
|
||||||
if (getSellAllAllowActions() != null) {
|
if (getSellAllAllowActions() != null) {
|
||||||
for (Action action : getSellAllAllowActions()) {
|
for (Action action : getSellAllAllowActions()) {
|
||||||
action.trigger(condition);
|
action.trigger(condition);
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) <2022> <XiaoMoMi>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.momirealms.customfishing.util;
|
||||||
|
|
||||||
|
public class NumberUtils {
|
||||||
|
|
||||||
|
public static String money(double money) {
|
||||||
|
String str = String.format("%.2f", money);
|
||||||
|
return str.replace(",", ".");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -45,7 +45,7 @@ sell-all-icons:
|
|||||||
display:
|
display:
|
||||||
name: '<#00CED1><b>● <!b>Ship the fish'
|
name: '<#00CED1><b>● <!b>Ship the fish'
|
||||||
lore:
|
lore:
|
||||||
- '<font:uniform><gradient:#E6E6FA:#48D1CC:#E6E6FA>You will get <green>{money}$</green> by selling the fish from inventory and bag</gradient></font>'
|
- '<font:uniform><gradient:#E6E6FA:#48D1CC:#E6E6FA>You will get <green>{money_formatted}$</green> by selling the fish from inventory and bag</gradient></font>'
|
||||||
action:
|
action:
|
||||||
sound_action:
|
sound_action:
|
||||||
type: sound
|
type: sound
|
||||||
@@ -56,7 +56,7 @@ sell-all-icons:
|
|||||||
pitch: 1
|
pitch: 1
|
||||||
message_action:
|
message_action:
|
||||||
type: message
|
type: message
|
||||||
value: 'You earned {money}$ by selling the fish! You can still get {rest}$ from market today'
|
value: 'You earned {money_formatted}$ by selling the fish! You can still get {rest_formatted}$ from market today'
|
||||||
command_action:
|
command_action:
|
||||||
type: command
|
type: command
|
||||||
value: 'money give {player} {money}'
|
value: 'money give {player} {money}'
|
||||||
@@ -101,7 +101,7 @@ sell-icons:
|
|||||||
display:
|
display:
|
||||||
name: '<#00CED1><b>● <!b>Ship the fish'
|
name: '<#00CED1><b>● <!b>Ship the fish'
|
||||||
lore:
|
lore:
|
||||||
- '<font:uniform><gradient:#E6E6FA:#48D1CC:#E6E6FA>You will get <green>{money}$</green> by selling the fish</gradient></font>'
|
- '<font:uniform><gradient:#E6E6FA:#48D1CC:#E6E6FA>You will get <green>{money_formatted}$</green> by selling the fish</gradient></font>'
|
||||||
action:
|
action:
|
||||||
sound_action:
|
sound_action:
|
||||||
type: sound
|
type: sound
|
||||||
@@ -112,7 +112,7 @@ sell-icons:
|
|||||||
pitch: 1
|
pitch: 1
|
||||||
message_action:
|
message_action:
|
||||||
type: message
|
type: message
|
||||||
value: 'You earned {money}$ by selling the fish! You can still get {rest}$ from market today'
|
value: 'You earned {money_formatted}$ by selling the fish! You can still get {rest_formatted}$ from market today'
|
||||||
command_action:
|
command_action:
|
||||||
type: command
|
type: command
|
||||||
value: 'money give {player} {money}'
|
value: 'money give {player} {money}'
|
||||||
|
|||||||
Reference in New Issue
Block a user