From fe3907748655a47c55aba27c01ec9c7d91955480 Mon Sep 17 00:00:00 2001 From: DosMike Date: Wed, 14 Aug 2019 19:44:52 +0200 Subject: [PATCH 1/2] Update webapi-sponge to vshop 2.2.1 --- webapi-sponge/build.gradle | 7 ++-- .../villagershops/VShopCompareUtils.java | 11 +++++-- .../villagershops/VShopServlet.java | 12 +++++-- .../wrapper/CachedStockItem.java | 33 +++++++++++++++++-- .../villagershops/wrapper/CachedVShop.java | 4 +-- 5 files changed, 54 insertions(+), 13 deletions(-) diff --git a/webapi-sponge/build.gradle b/webapi-sponge/build.gradle index 2d8b4243..94a33e20 100644 --- a/webapi-sponge/build.gradle +++ b/webapi-sponge/build.gradle @@ -36,7 +36,10 @@ repositories { url "http://repo.bstats.org/content/repositories/releases/" } maven { - url = "http://repo.aikar.co/nexus/content/groups/aikar/" + url "http://repo.aikar.co/nexus/content/groups/aikar/" + } + maven { + url 'https://jitpack.io' } flatDir { dirs "lib" @@ -87,7 +90,7 @@ dependencies { compileOnly name: "Nucleus-1.12.1-S7.1-api" compileOnly name: "RedProtect-7.5.5-b130-Universal" compileOnly name: "UniversalMarket-1.12.2-v1.3" - compileOnly name: "VillagerShops-2.0.1" + compileOnly "com.github.DosMike:VillagerShops:development-SNAPSHOT" compileOnly name: "WebBooks" } diff --git a/webapi-sponge/src/main/java/valandur/webapi/integration/villagershops/VShopCompareUtils.java b/webapi-sponge/src/main/java/valandur/webapi/integration/villagershops/VShopCompareUtils.java index 63a7437d..ac087a08 100644 --- a/webapi-sponge/src/main/java/valandur/webapi/integration/villagershops/VShopCompareUtils.java +++ b/webapi-sponge/src/main/java/valandur/webapi/integration/villagershops/VShopCompareUtils.java @@ -1,7 +1,12 @@ package valandur.webapi.integration.villagershops; import com.flowpowered.math.vector.Vector3d; -import de.dosmike.sponge.vshop.*; +import de.dosmike.sponge.vshop.menus.InvPrep; +import de.dosmike.sponge.vshop.shops.NPCguard; +import de.dosmike.sponge.vshop.shops.StockItem; +import de.dosmike.sponge.vshop.VillagerShops; +import de.dosmike.sponge.vshop.Utilities; +import de.dosmike.sponge.vshop.API; import org.spongepowered.api.entity.Entity; import org.spongepowered.api.entity.EntityType; import org.spongepowered.api.text.serializer.TextSerializers; @@ -83,7 +88,7 @@ static void applyDiv(CachedVShop update, NPCguard shop) { item.getItem().createStack(), item.getSellPrice(), item.getBuyPrice(), - VillagerShops.getInstance().CurrencyByName(item.getCurrency().getId()), + Utilities.CurrencyByName(item.getCurrency().getId()), item.getMaxStock())); } else if (i >= newS) { inv.removeIndex(i); @@ -93,7 +98,7 @@ static void applyDiv(CachedVShop update, NPCguard shop) { item.getItem().createStack(), item.getSellPrice(), item.getBuyPrice(), - VillagerShops.getInstance().CurrencyByName(item.getCurrency().getId()), + Utilities.CurrencyByName(item.getCurrency().getId()), item.getMaxStock())); } } diff --git a/webapi-sponge/src/main/java/valandur/webapi/integration/villagershops/VShopServlet.java b/webapi-sponge/src/main/java/valandur/webapi/integration/villagershops/VShopServlet.java index 413cc51a..0744cb47 100644 --- a/webapi-sponge/src/main/java/valandur/webapi/integration/villagershops/VShopServlet.java +++ b/webapi-sponge/src/main/java/valandur/webapi/integration/villagershops/VShopServlet.java @@ -1,6 +1,11 @@ package valandur.webapi.integration.villagershops; -import de.dosmike.sponge.vshop.*; +import de.dosmike.sponge.vshop.menus.InvPrep; +import de.dosmike.sponge.vshop.shops.NPCguard; +import de.dosmike.sponge.vshop.shops.StockItem; +import de.dosmike.sponge.vshop.Utilities; +import de.dosmike.sponge.vshop.VillagerShops; +import de.dosmike.sponge.vshop.API; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.spongepowered.api.entity.EntityType; @@ -35,6 +40,7 @@ public class VShopServlet extends BaseServlet { value = "List Shops", notes = "Return a list of all shops") public Collection listShops() { + return WebAPI.runOnMain(() -> API.list().stream().map(CachedVShop::new).collect(Collectors.toList())); } @@ -232,7 +238,7 @@ public Response addShopItem(@PathParam("id") UUID id, CachedStockItem req) req.getItem().createStack(), req.getSellPrice(), req.getBuyPrice(), - VillagerShops.getInstance().CurrencyByName(req.getCurrency().getId()), + Utilities.CurrencyByName(req.getCurrency().getId()), req.getMaxStock())); return new CachedStockItem(inv.getItem(s), s, npc.get().getIdentifier()); @@ -272,7 +278,7 @@ public CachedStockItem updateShopItem(@PathParam("id") UUID id, @PathParam("item req.getItem().createStack(), req.getSellPrice(), req.getBuyPrice(), - VillagerShops.getInstance().CurrencyByName(req.getCurrency().getId()), + Utilities.CurrencyByName(req.getCurrency().getId()), req.getMaxStock())); return new CachedStockItem(inv.getItem(item), item, npc.get().getIdentifier()); diff --git a/webapi-sponge/src/main/java/valandur/webapi/integration/villagershops/wrapper/CachedStockItem.java b/webapi-sponge/src/main/java/valandur/webapi/integration/villagershops/wrapper/CachedStockItem.java index 42fae0a2..b45d25fc 100644 --- a/webapi-sponge/src/main/java/valandur/webapi/integration/villagershops/wrapper/CachedStockItem.java +++ b/webapi-sponge/src/main/java/valandur/webapi/integration/villagershops/wrapper/CachedStockItem.java @@ -1,9 +1,9 @@ package valandur.webapi.integration.villagershops.wrapper; import com.fasterxml.jackson.annotation.JsonProperty; -import de.dosmike.sponge.vshop.InvPrep; -import de.dosmike.sponge.vshop.NPCguard; -import de.dosmike.sponge.vshop.StockItem; +import de.dosmike.sponge.vshop.menus.InvPrep; +import de.dosmike.sponge.vshop.shops.NPCguard; +import de.dosmike.sponge.vshop.shops.StockItem; import de.dosmike.sponge.vshop.VillagerShops; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -14,6 +14,7 @@ import valandur.webapi.util.Constants; import javax.ws.rs.BadRequestException; +import java.util.NoSuchElementException; import java.util.Optional; import java.util.UUID; @@ -90,6 +91,26 @@ public ItemStackSnapshot getItem() { return item; } + String oreDictEntry; + + @JsonProperty + @ApiModelProperty(value = "If the filter is set to use the OreDictionary, this field will hold the OreDict entry accepted by the shop") + public String getOreDictEntry() { + return oreDictEntry; + } + + String filter; + + @JsonProperty + @ApiModelProperty(value = "This allowes some values of items being ignored when selling", required = true) + public StockItem.FilterOptions getFilter() { + try { + return StockItem.FilterOptions.of(filter); + } catch (NoSuchElementException e) { + return StockItem.FilterOptions.NORMAL; + } + } + public CachedStockItem() { super(null); @@ -107,6 +128,10 @@ public CachedStockItem(StockItem item, int id, UUID shopID) { this.maxStock = item.getMaxStock(); this.hasStock = this.maxStock > 0; this.item = item.getItem().createSnapshot(); + this.filter = item.getNbtFilter().toString(); + if (item.getNbtFilter().equals(StockItem.FilterOptions.OREDICT)) { + this.oreDictEntry = item.getOreDictEntry().get(); + } } @Override @@ -141,5 +166,7 @@ public void validate() throws BadRequestException { throw new BadRequestException("Buy price can't be negative"); if (item == null) throw new BadRequestException("Missing item snapshot"); + if ("OreDict".equalsIgnoreCase(filter) != (oreDictEntry == null)) + throw new BadRequestException("The oreDictEntry value is tied to the filter type being OreDict"); } } diff --git a/webapi-sponge/src/main/java/valandur/webapi/integration/villagershops/wrapper/CachedVShop.java b/webapi-sponge/src/main/java/valandur/webapi/integration/villagershops/wrapper/CachedVShop.java index 2cf783b1..905c4915 100644 --- a/webapi-sponge/src/main/java/valandur/webapi/integration/villagershops/wrapper/CachedVShop.java +++ b/webapi-sponge/src/main/java/valandur/webapi/integration/villagershops/wrapper/CachedVShop.java @@ -1,7 +1,7 @@ package valandur.webapi.integration.villagershops.wrapper; -import de.dosmike.sponge.vshop.InvPrep; -import de.dosmike.sponge.vshop.NPCguard; +import de.dosmike.sponge.vshop.menus.InvPrep; +import de.dosmike.sponge.vshop.shops.NPCguard; import de.dosmike.sponge.vshop.VillagerShops; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; From 00886ce1a85229325673bf55a77628e5e608c7f5 Mon Sep 17 00:00:00 2001 From: DosMike Date: Thu, 15 Aug 2019 16:21:22 +0200 Subject: [PATCH 2/2] Static version to prevent everything from spontaneously breaking --- webapi-sponge/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapi-sponge/build.gradle b/webapi-sponge/build.gradle index 94a33e20..3fe2b619 100644 --- a/webapi-sponge/build.gradle +++ b/webapi-sponge/build.gradle @@ -90,7 +90,7 @@ dependencies { compileOnly name: "Nucleus-1.12.1-S7.1-api" compileOnly name: "RedProtect-7.5.5-b130-Universal" compileOnly name: "UniversalMarket-1.12.2-v1.3" - compileOnly "com.github.DosMike:VillagerShops:development-SNAPSHOT" + compileOnly "com.github.DosMike:VillagerShops:2.2.1" compileOnly name: "WebBooks" }