Skip to content

Commit

Permalink
Various Fixes for Currency Menu, reset icon.
Browse files Browse the repository at this point in the history
  • Loading branch information
creatorfromhell committed Jul 20, 2024
1 parent e5273bb commit 0a7382e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Core/resources/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# All configurable messages in TNE
Messages:

config-version: 3
config-version: 4

General:
Version: "<white>TNE Version: <green>$version <white>- Build: <green>$build"
Expand Down Expand Up @@ -124,6 +124,7 @@ Messages:

Shared:
Save: "Save"
Reset: "Reset"
PreviousPageDisplay: "Previous Page"
PreviousPage: "Click to go to previous page."
NextPageDisplay: "Next Page"
Expand Down Expand Up @@ -161,6 +162,7 @@ Messages:

Currency:
SaveLore: "Click to save the currencies."
ResetLore: "Click to clear changes, and reset to previous currencies."
CurrencyExistsMessage: "A currency with that identifier already exists! Enter an identifier for the currency:"
SetIdentifierMessage: "Enter an identifier for the currency:"
AddCurrencyDisplay: "Add Currency"
Expand Down
10 changes: 10 additions & 0 deletions Core/src/net/tnemc/core/currency/item/ItemDenomination.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
*/

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.tnemc.core.currency.Denomination;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
Expand Down Expand Up @@ -104,6 +106,14 @@ public List<Component> getLore() {
return lore;
}

public LinkedList<String> getLoreAsString() {
final LinkedList<String> loreAsString = new LinkedList<>();
for(Component component : lore) {
loreAsString.add(MiniMessage.miniMessage().serialize(component));
}
return loreAsString;
}

public void setLore(List<Component> lore) {
this.lore.clear();
this.lore.addAll(lore);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public void saveDenomination(final File directory, Currency currency, Denominati

if(!itemDenomination.getLore().isEmpty()) {
MISCUtils.setComment(denom, "Options.Lore", "The lore string this item must have in order to be considered currency.(Optional)");
denom.set("Options.Lore", itemDenomination.getLore());
denom.set("Options.Lore", itemDenomination.getLoreAsString());
}

if(itemDenomination.getCustomModel() > -1) {
Expand Down
22 changes: 21 additions & 1 deletion Core/src/net/tnemc/core/menu/MyEcoMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,24 @@ public MyEcoMenu() {
}), new PageSwitchWithClose(this.name, -1))
.withSlot(6)
.build());

open.getPage().addIcon(new IconBuilder(PluginCore.server().stackBuilder().of("BLACK_WOOL", 1)
.display(MessageHandler.grab(new MessageData("Messages.Menu.Shared.Reset"), id))
.lore(Collections.singletonList(MessageHandler.grab(new MessageData("Messages.Menu.MyEco.Currency.ResetLore"), id))))
.withActions(new RunnableAction((click)->{

final File directory = new File(PluginCore.directory(), "currency");

try {

TNECore.eco().currency().getCurrencies().clear();
TNECore.eco().currency().getCurIDMap().clear();

TNECore.eco().currency().getLoader().loadCurrencies(directory);
} catch(NoValidCurrenciesException ignore) {}
}), new PageSwitchWithClose(this.name, -1))
.withSlot(8)
.build());

//add currency
final SwitchPageIcon addCurrencyIcon = new SwitchPageIcon(2, PluginCore.server().stackBuilder().of("ARROW", 1)
Expand All @@ -175,7 +193,9 @@ public MyEcoMenu() {
return false;
}

message.getPlayer().viewer().get().addData(ACTIVE_CURRENCY, new Currency(message.getMessage()));
Currency newCurObj = new Currency(message.getMessage());
message.getPlayer().viewer().get().addData(ACTIVE_CURRENCY, newCurObj);
TNECore.eco().currency().addCurrency(newCurObj);
return true;
}
message.getPlayer().message("Enter an identifier for the currency:");
Expand Down

0 comments on commit 0a7382e

Please sign in to comment.