Skip to content

Commit

Permalink
Add config to use Identifier as UUID for currencies.
Browse files Browse the repository at this point in the history
Signed-off-by: creatorfromhell <[email protected]>
  • Loading branch information
creatorfromhell committed Aug 23, 2023
1 parent 74950e1 commit bdc55d3
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Core/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ Core:
#restarts, but will not impact anything significant.
RandomUUID: false

#Whether to import exist item currencies into a player's balance when they join for the first time.
ImportItems: true

#Should TNE disable mob drops that are valid item currencies?
MobDrop: true

Expand Down
3 changes: 3 additions & 0 deletions Core/resources/currency/USD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Info:
#The identifier of this currency used for various commands.
Identifier: "USD"

#Whether to use the Identifier config as the currency's UUID. Not Recommended. Can lead to issues in the future
UUIDAsId: false

#The material name to use as the icon for this currency in
#the plugin menus.
Icon: "PAPER"
Expand Down
27 changes: 24 additions & 3 deletions Core/src/net/tnemc/core/TNECore.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,23 +256,44 @@ protected void onEnable() {

//Set our server UUID. This is used for proxy messaging.
boolean randomUUID = false;
//Added in build 28, needs removed by build 32.
if(!MainConfig.yaml().contains("Core.Server.RandomUUID")) {
MainConfig.yaml().set("Core.Server.RandomUUID", false);
MainConfig.yaml().setComment("Core.ServerID", "#Whether the ServerID config should be random on each startup. This could impact syncing on\n" +
MainConfig.yaml().setComment("Core.Server.RandomUUID", "#Whether the ServerID config should be random on each startup. This could impact syncing on\n" +
"#restarts, but will not impact anything significant.");

try {
MainConfig.yaml().save();
} catch(IOException e) {
logger.error("Issue while updating config.yml to config.yml", e, DebugLevel.OFF);
}
} else {
randomUUID = MainConfig.yaml().getBoolean("Core.Server.RandomUUID", false);
}

//Added in build 28, needs removed by build 32.
if(!MainConfig.yaml().contains("Core.Server.ImportItems")) {
MainConfig.yaml().set("Core.Server.ImportItems", true);
MainConfig.yaml().setComment("Core.Server.ImportItems", "#Whether to import exist item currencies into a player's balance when they join for the first time.");

try {
MainConfig.yaml().save();
} catch(IOException e) {
logger.error("Issue while updating config.yml to config.yml", e, DebugLevel.OFF);
}
}

if(!randomUUID) {
if(! MainConfig.yaml().contains("Core.ServerID")) {
if(!MainConfig.yaml().contains("Core.ServerID")) {

serverID = UUID.randomUUID();
MainConfig.yaml().set("Core.ServerID", serverID.toString());
MainConfig.yaml().setComment("Core.ServerID", "#Don't modify unless you know what you're doing.");

try {
MainConfig.yaml().save();
} catch(IOException e) {
logger.error("Issue while saving Server UUID to config.yml", e, DebugLevel.STANDARD);
logger.error("Issue while saving Server UUID to config.yml", e, DebugLevel.OFF);
}
} else {
serverID = UUID.fromString(MainConfig.yaml().getString("Core.ServerID"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import net.tnemc.core.api.callback.currency.CurrencyLoadCallback;
import net.tnemc.core.api.callback.currency.DenominationLoadCallback;
import net.tnemc.core.compatibility.helper.CraftingRecipe;
import net.tnemc.core.compatibility.log.DebugLevel;
import net.tnemc.core.config.MainConfig;
import net.tnemc.core.currency.Currency;
import net.tnemc.core.currency.CurrencyLoader;
import net.tnemc.core.currency.CurrencyRegion;
Expand Down Expand Up @@ -147,12 +149,28 @@ public boolean loadCurrency(final File directory, File curDirectory) {
final BigDecimal minBalance = (type.get().supportsItems())? BigDecimal.ZERO : new BigDecimal(cur.getString("Options.MinBalance", "0.00"));
final BigDecimal balance = new BigDecimal(cur.getString("Options.Balance", "200.00"));

//Added in build 28, needs removed by build 32.
boolean uuidAsId = false;
if(!cur.contains("Info.UUIDAsId")) {
cur.set("Info.UUIDAsId", false);
cur.setComment("Info.UUIDAsId", "#Whether to use the Identifier config as the currency's UUID. Not Recommended. Can lead to issues in the future");
} else {
uuidAsId = cur.getBoolean("Info.UUIDAsId");
}

if(cur.contains("Info.UUID")) {
final UUID id = UUID.fromString(cur.getString("Info.UUID"));

final UUID check = UUID.fromString(identifier);

final UUID id = (uuidAsId && !cur.getString("Info.UUID").equalsIgnoreCase(check.toString()))? check : UUID.fromString(cur.getString("Info.UUID"));


final Optional<Currency> curOption = TNECore.eco().currency().findCurrency(id);
if(curOption.isEmpty()) {
currency.setUid(UUID.fromString(cur.getString("Info.UUID")));
}
} else {
currency.setUid(UUID.fromString(identifier));
}

currency.setIdentifier(identifier);
Expand Down Expand Up @@ -234,6 +252,12 @@ public boolean loadCurrency(final File directory, File curDirectory) {
}

TNECore.eco().currency().addCurrency(currency);

try {
cur.save();
} catch(IOException e) {
TNECore.log().error("Failed to save currency YAML!", e, DebugLevel.OFF);
}
return true;
}

Expand Down

0 comments on commit bdc55d3

Please sign in to comment.