From 503957ab09a64f86fa55a2a43f663c9c6097307f Mon Sep 17 00:00:00 2001 From: skycatminepokie <52087591+skycatminepokie@users.noreply.github.com> Date: Fri, 8 Mar 2024 10:41:31 -0800 Subject: [PATCH 1/3] Add icon --- src/main/resources/assets/wbshop/icon.png | Bin 0 -> 8219 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/main/resources/assets/wbshop/icon.png diff --git a/src/main/resources/assets/wbshop/icon.png b/src/main/resources/assets/wbshop/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ab87bc45a54a3ed0ed4498aa5c25cd771e39422f GIT binary patch literal 8219 zcmb_hRa6{2(_UPKkxm2 z`CTM)lAJk{lT2owJQJ&?B8P=ZiU|M!upsg>8m}__zlM(Z+BaG5wY&-hPYpRKKvC5*Y^Yfum}HZ2&1m$RsaB1Jw!%Q%g^LA7wTlR@#>4q>Ni&7l(?K%qJO2Z5Qei zgTJc(sSo=|YyI6yqh))mQ5+t`c~R;Uh$xBNWpJgeH|yH#ns1NL86_7gHCQZBxT#(+djVFn z^ZVZ{=X+pUHt12~Uiyb8!OGyOa=;f`ZZ1C2t^90kWhG?BF3B1J1W*-Qo3x2<_dw(-*itT0mHa#}lbNHv zxwfTz*}Y#~fS}1iiczzLd70}yAsodyZJ4o&frp>yGEy`=yye?$`m{o;rKY93bA0i) zU-}vrHI>bVTM?v*>U8Rvg3Coj4`n8gYq7PONI}x^M2@8F!>!K-GhUNL80^TZR<#~G z9&C6u=TznBDC27aiKE(Qt!-@t(I+X=3AK%t2fD4lO%E&Qg?Ge&(uKZ0@Y}==aZv%c zlR(q9^9!R(Gw-L~zk=@^rsCwLEOo8`F0&~*5CayXj*WHSS+5VhqFX3ojXeOz=6 zzMC-??;saZtv&G4E861{!g?GIH&lO8GYeVDr_3rokhDotp?{lrilw!HW}plR1G^|%55j%KUb$m zeLA8_M6Q$(RBT>00bj52`q z$+|!7bxGxE2nuaqPeqc4W?Sg0Qy<~T+?i67#wCkie|BT!z-y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E-AANl6w{G92kxvfoC zM@NeOn`Gt$Ass;ZEL+Ngu8g{8I5vbPhTsXI4^a~k1S!^6Y#DTQ6Hh(L5qpfolmk&M9b zi8ueFFzMt!5H^OQK0apF0QD3YzsG%$ zIi7r{ssACvd;r2WNeXIrXVM`>cvxs4hOmG2WB|dqVJHi%F{TwofPw;MLn}hXb6VnSz21! z^|)^IXg{m&v11wenLu|5?w`@?Xw9}#zX~}2YO+ZkqM^CGy{~e87|7!lMY*qP zVPPcFXMNGt)-LT;-xa4$6y$tI3z@2A4>m(#208C?Cf@k-&@lrHQ!YHFZeKvJvutMG rW+l`*eO>>%3ibbA{&ve$dckoC(p-jrIeIPR0{{?N6`5Kov#|dIp&WGy literal 0 HcmV?d00001 From b0a0768f7976ce7d8217da3797df9e191492fce8 Mon Sep 17 00:00:00 2001 From: skycatminepokie <52087591+skycatminepokie@users.noreply.github.com> Date: Fri, 12 Apr 2024 14:45:06 -0700 Subject: [PATCH 2/3] Fixed Economy API compatibility --- CHANGELOG.md | 4 +- .../java/com/skycat/wbshop/econ/Account.java | 115 +++++++++--------- .../java/com/skycat/wbshop/econ/Economy.java | 85 ++++++------- .../java/com/skycat/wbshop/econ/Points.java | 4 +- .../com/skycat/wbshop/econ/package-info.java | 5 + 5 files changed, 112 insertions(+), 101 deletions(-) create mode 100644 src/main/java/com/skycat/wbshop/econ/package-info.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fb4ebd..d7e6ef7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,2 +1,2 @@ -- Fixed crash when loading multiple worlds in singleplayer (#18) -- Automatically generate points config file (#18) \ No newline at end of file +- Added the icon to the mod +- Fixed Economy API compatibility (thanks to @basiqueevangelist for open-sourcing their code) \ No newline at end of file diff --git a/src/main/java/com/skycat/wbshop/econ/Account.java b/src/main/java/com/skycat/wbshop/econ/Account.java index a456328..f444a90 100644 --- a/src/main/java/com/skycat/wbshop/econ/Account.java +++ b/src/main/java/com/skycat/wbshop/econ/Account.java @@ -25,14 +25,7 @@ import java.util.UUID; public class Account implements EconomyAccount { - private final UUID owner; - /** - * The balance of this account. Modify only via {@link Account#setBalance(long)}. - */ - private long balance; - private final HashMap donatedItemCounts; - private long totalItemsDonated; - + public static final String POINTS_ACCOUNT = "points_account"; public static final Codec CODEC = RecordCodecBuilder.create((account) -> account.group( Uuids.CODEC.fieldOf("owner").forGetter(Account::owner), Codec.LONG.fieldOf("balance").forGetter(Account::balance), @@ -43,13 +36,37 @@ public class Account implements EconomyAccount { "count" ).fieldOf("donatedItemCounts").forGetter(Account::getDonatedItemCounts) ).apply(account, Account::new)); + public static final Identifier ID = Identifier.of(WBShop.MOD_ID, POINTS_ACCOUNT); + private final UUID owner; + private final HashMap donatedItemCounts; + /** + * The balance of this account. Modify only via {@link Account#setBalance(long)}. + */ + private long balance; + private long totalItemsDonated; - public HashMap getDonatedItemCounts() { - return donatedItemCounts; + public Account(UUID owner) { + this(owner, 0); + } + + public Account(UUID owner, long balance) { + this(owner, balance, new HashMap<>()); + } + + public Account(UUID owner, long balance, HashMap donatedItemCounts) { + this.owner = owner; + this.balance = balance; + this.donatedItemCounts = donatedItemCounts; + totalItemsDonated = 0; + for (Long l : donatedItemCounts.values()) { + totalItemsDonated += l; + } } + /** * Record items as donated and award points. + * * @param items The stacks of items to donate. * @return The number of points awarded for donating. */ @@ -63,6 +80,7 @@ public long donateItems(Collection items) { /** * Record items as donated and award points. + * * @param stack The stack of items to donate. * @return The number of points awarded for donating. */ @@ -77,41 +95,23 @@ public long donateItems(ItemStack stack) { return value; } - public Account(UUID owner) { - this(owner, 0); - } - - public Account(UUID owner, long balance) { - this(owner, balance, new HashMap<>()); - } - - public Account(UUID owner, long balance, HashMap donatedItemCounts) { - this.owner = owner; - this.balance = balance; - this.donatedItemCounts = donatedItemCounts; - totalItemsDonated = 0; - for (Long l : donatedItemCounts.values()) { - totalItemsDonated += l; - } - } - public void addBalance(long value) { setBalance(balance + value); } - public long getTotalItemsDonated() { - return totalItemsDonated; + public HashMap getDonatedItemCounts() { + return donatedItemCounts; } - public void removeBalance(long value) { - addBalance(-value); + public long getTotalItemsDonated() { + return totalItemsDonated; } // @Override public Text name() { return Text.of("Worldborder Shop Account"); - } + } // TODO: add player's name @Override public UUID owner() { @@ -119,24 +119,8 @@ public UUID owner() { } @Override - public Identifier id() { // I believe this is the type of account this is - return defaultId(); - } - - /** - * Used for withdrawing points to a voucher. - * @param amount The amount to take from the player's account and grant as a voucher. - * @param player The player to grant the voucher to. This can be someone other than the account owner, but I don't see why you'd do that. - * @return {@code false} if the account does not have enough points, {@code true} on success. - */ - public boolean withdraw(long amount, ServerPlayerEntity player) { - if (amount <= 0) return false; - if (amount > balance) return false; - ItemStack voucher = Economy.makeVoucher(amount); - - player.getInventory().offerOrDrop(voucher); - removeBalance(amount); - return true; + public Identifier id() { + return ID; } @Override @@ -179,7 +163,7 @@ public EconomyCurrency currency() { } public EconomyTransaction tryTransaction(long value) { - if (balance + value >= 0){ + if (balance + value >= 0) { long old = balance; addBalance(value); return new EconomyTransaction.Simple(true, @@ -190,11 +174,30 @@ public EconomyTransaction tryTransaction(long value) { this ); } - return new EconomyTransaction.Simple(false, Text.of("Transaction failed"), balance, balance,value, this); - } - public static Identifier defaultId() { - return Identifier.of(WBShop.MOD_ID, "points_account"); + return new EconomyTransaction.Simple(false, Text.of("Transaction failed"), balance, balance, value, this); } // + + /** + * Used for withdrawing points to a voucher. + * + * @param amount The amount to take from the player's account and grant as a voucher. + * @param player The player to grant the voucher to. This can be someone other than the account owner, but I don't see why you'd do that. + * @return {@code false} if the account does not have enough points, {@code true} on success. + */ + public boolean withdraw(long amount, ServerPlayerEntity player) { + if (amount <= 0) return false; + if (amount > balance) return false; + ItemStack voucher = Economy.makeVoucher(amount); + + player.getInventory().offerOrDrop(voucher); + removeBalance(amount); + return true; + } + + public void removeBalance(long value) { + addBalance(-value); + } + } diff --git a/src/main/java/com/skycat/wbshop/econ/Economy.java b/src/main/java/com/skycat/wbshop/econ/Economy.java index 032377b..ed15329 100644 --- a/src/main/java/com/skycat/wbshop/econ/Economy.java +++ b/src/main/java/com/skycat/wbshop/econ/Economy.java @@ -63,15 +63,6 @@ private Economy(int configVersion, List accountList, String borderFunct .build(); } - public static Economy readFromNbt(NbtCompound nbt) { - var result = CODEC.decode(NbtOps.INSTANCE, nbt.get("economy")).result(); - if (result.isEmpty()) { - Utils.log("WBShop couldn't load the economy. This is normal when you start a new world."); - return null; - } - return result.get().getFirst(); - } - @NotNull public static ItemStack makeVoucher(long amount) { if (amount <= 0) { @@ -93,36 +84,13 @@ public static ItemStack makeVoucher(long amount) { return voucher; } - public String getBorderFunctionString() { - return borderFunctionString; - } - - /** - * Try to set the border function. - * - * @param newExpression The string expression to parse. - * @param server The server to set the border on - * @return True if the function is valid, false if the function is not valid. - */ - public boolean setBorderFunction(String newExpression, @NonNull MinecraftServer server) { - Expression newFunction = new ExpressionBuilder(newExpression).variable("points").build(); - newFunction.setVariable("points", getTotalPoints()); - if (newFunction.validate().isValid()) { - borderFunction = newFunction; - borderFunctionString = newExpression; - markDirty(); - WBShop.updateBorder(server); - return true; - } - return false; - } - - public long getTotalPoints() { - long total = 0; - for (Account account : accounts.values()) { - total += account.balance(); + public static Economy readFromNbt(NbtCompound nbt) { + var result = CODEC.decode(NbtOps.INSTANCE, nbt.get("economy")).result(); + if (result.isEmpty()) { + Utils.log("WBShop couldn't load the economy. This is normal when you start a new world."); + return null; } - return total; + return result.get().getFirst(); } /** @@ -150,6 +118,10 @@ public ArrayList getAccountList() { return new ArrayList<>(accounts.values()); } + public String getBorderFunctionString() { + return borderFunctionString; + } + public int getConfigVersion() { return this.configVersion; } @@ -178,7 +150,7 @@ public Text name() { @Override public @Nullable EconomyAccount getAccount(MinecraftServer server, GameProfile profile, String accountId) { - if (accountId.equals(Account.defaultId().toString())) { + if (accountId.equals(Account.POINTS_ACCOUNT)) { return accounts.get(profile.getId()); } return null; @@ -186,12 +158,13 @@ public Text name() { @Override public Collection getAccounts(MinecraftServer server, GameProfile profile) { - return List.of(accounts.get(profile.getId())); + EconomyAccount account = getAccount(server, profile, Account.POINTS_ACCOUNT); + return account == null ? Collections.emptySet() : Collections.singleton(account); } @Override public @Nullable EconomyCurrency getCurrency(MinecraftServer server, String currencyId) { - if (CURRENCY.id().toString().equals(currencyId)) { + if (Points.STRING_ID.equals(currencyId)) { return CURRENCY; } return null; @@ -205,7 +178,7 @@ public Collection getCurrencies(MinecraftServer server) { @Override public @Nullable String defaultAccount(MinecraftServer server, GameProfile profile, EconomyCurrency currency) { if (currency == CURRENCY) { - return Account.defaultId().toString(); + return Account.POINTS_ACCOUNT; } return null; } @@ -237,6 +210,34 @@ public long pointValueOf(Item itemType) { return WBShop.globalConfig.getItemValue(itemType); } + /** + * Try to set the border function. + * + * @param newExpression The string expression to parse. + * @param server The server to set the border on + * @return True if the function is valid, false if the function is not valid. + */ + public boolean setBorderFunction(String newExpression, @NonNull MinecraftServer server) { + Expression newFunction = new ExpressionBuilder(newExpression).variable("points").build(); + newFunction.setVariable("points", getTotalPoints()); + if (newFunction.validate().isValid()) { + borderFunction = newFunction; + borderFunctionString = newExpression; + markDirty(); + WBShop.updateBorder(server); + return true; + } + return false; + } + + public long getTotalPoints() { + long total = 0; + for (Account account : accounts.values()) { + total += account.balance(); + } + return total; + } + @Override public NbtCompound writeNbt(NbtCompound nbt) { var encodedResult = CODEC.encode(this, NbtOps.INSTANCE, NbtOps.INSTANCE.empty()).result(); diff --git a/src/main/java/com/skycat/wbshop/econ/Points.java b/src/main/java/com/skycat/wbshop/econ/Points.java index ed545b4..36cf18c 100644 --- a/src/main/java/com/skycat/wbshop/econ/Points.java +++ b/src/main/java/com/skycat/wbshop/econ/Points.java @@ -8,6 +8,8 @@ import net.minecraft.util.Identifier; public class Points implements EconomyCurrency { + public static final Identifier ID = Identifier.of(WBShop.MOD_ID, "points"); + public static final String STRING_ID = "points"; @Override public Text name() { return Text.of("Points"); @@ -15,7 +17,7 @@ public Text name() { @Override public Identifier id() { - return Identifier.of(WBShop.MOD_ID, "points"); + return ID; } @Override diff --git a/src/main/java/com/skycat/wbshop/econ/package-info.java b/src/main/java/com/skycat/wbshop/econ/package-info.java new file mode 100644 index 0000000..311abc9 --- /dev/null +++ b/src/main/java/com/skycat/wbshop/econ/package-info.java @@ -0,0 +1,5 @@ +/** + * Handling for the economy (how points are transferred and stored). + * Thanks to @basiqueevangelist, I used a lot from CommonBridge to fix problems with Patbox's Common Economy API compatibility + */ +package com.skycat.wbshop.econ; \ No newline at end of file From cc9deea448b4e610e57250ed46f4b4fef3b1fe56 Mon Sep 17 00:00:00 2001 From: skycatminepokie <52087591+skycatminepokie@users.noreply.github.com> Date: Fri, 12 Apr 2024 14:45:26 -0700 Subject: [PATCH 3/3] Bump version --- .github/workflows/publish.yml | 2 +- gradle.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 6362f0c..a073245 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -10,7 +10,7 @@ on: env: MINECRAFT_VERSION: 1.20.1 JAVA_VERSION: 17 - VERSION: 2.0.6+1.20.1 + VERSION: 2.0.7+1.20.1 VERSION_TYPE: beta permissions: diff --git a/gradle.properties b/gradle.properties index db69a92..457b975 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ yarn_mappings=1.20.1+build.10 loader_version=0.14.22 # Mod Properties -mod_version=2.0.6+1.20.1 +mod_version=2.0.7+1.20.1 maven_group=com.skycat archives_base_name=wbshop