Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update webapi-sponge to vshop 2.2.1 #131

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions webapi-sponge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:2.2.1"
compileOnly name: "WebBooks"
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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()));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -35,6 +40,7 @@ public class VShopServlet extends BaseServlet {
value = "List Shops",
notes = "Return a list of all shops")
public Collection<CachedVShop> listShops() {

return WebAPI.runOnMain(() -> API.list().stream().map(CachedVShop::new).collect(Collectors.toList()));
}

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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");
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down