Skip to content

Commit c45445e

Browse files
author
Valandur
committed
Merge branch 'release/v5.3.0'
2 parents 7648b48 + d6fb6ef commit c45445e

49 files changed

Lines changed: 905 additions & 121 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,4 @@ supported routes. You can also find the same documentation [here](https://valand
7070
- [kawahara](https://github.com/kawahara)
7171
- [Lantcoder](https://github.com/Lantcoder)
7272
- [crymates](https://github.com/crymates)
73+
- [DosMike](https://github.com/DosMike)

Web-API.iml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module external.linked.project.id="Web-API" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="valandur.webapi" external.system.module.version="5.2.2-S7.1" type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
7+
<excludeFolder url="file://$MODULE_DIR$/build" />
8+
<excludeFolder url="file://$MODULE_DIR$/out" />
9+
</content>
10+
<orderEntry type="inheritedJdk" />
11+
<orderEntry type="sourceFolder" forTests="false" />
12+
</component>
13+
</module>

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ dependencies {
9494
compileOnly name: "Nucleus-1.3.3-S7.0-api"
9595
compileOnly name: "RedProtect-7.3.0-b68-Universal"
9696
compileOnly name: "UniversalMarket-1.12.2-v1.1"
97+
compileOnly name: "VillagerShops"
9798
compileOnly name: "WebBooks"
9899
}
99100

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version=5.2.2
1+
version=5.3.0
22
minecraftVersion=1.12.2
33
spongeVersion=7.1
44
jacksonVersion=2.9.4

lib/VillagerShops.jar

101 KB
Binary file not shown.

src/main/java/valandur/webapi/config/ServletsConfig.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ public static class ServletsIntegrationConfig {
9494
@Setting
9595
public boolean UniversalMarket = true;
9696

97+
@Setting
98+
public boolean VillagerShops = true;
99+
97100
@Setting
98101
public boolean WebBooks = true;
99102
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package valandur.webapi.integration.villagershops;
2+
3+
import com.flowpowered.math.vector.Vector3d;
4+
import de.dosmike.sponge.vshop.*;
5+
import org.spongepowered.api.entity.Entity;
6+
import org.spongepowered.api.entity.EntityType;
7+
import org.spongepowered.api.text.serializer.TextSerializers;
8+
import org.spongepowered.api.world.Location;
9+
import valandur.webapi.integration.villagershops.wrapper.CachedStockItem;
10+
import valandur.webapi.integration.villagershops.wrapper.CachedVShop;
11+
12+
import javax.ws.rs.BadRequestException;
13+
import javax.ws.rs.NotFoundException;
14+
import java.util.Optional;
15+
16+
class VShopCompareUtils {
17+
18+
@SuppressWarnings({"rawtypes", "unchecked"})
19+
static void applyDiv(CachedVShop update, NPCguard shop) {
20+
Entity rep = shop.getLe();
21+
boolean respawnShop = false; //if the entity changed a new entity / mob has to be spawned
22+
if (update.getEntityType() != null && !update.getEntityType().getId().equalsIgnoreCase(shop.getNpcType().toString())) {
23+
EntityType et = update.getEntityType().getLive(EntityType.class).orElse(null);
24+
if (et == null)
25+
throw new BadRequestException("EntityType " + update.getEntityType() + " is unknown");
26+
respawnShop = true;
27+
shop.setNpcType(et);
28+
}
29+
if (update.getEntityVariant() != null && !update.getEntityVariant().equalsIgnoreCase(shop.getVariantName())) {
30+
respawnShop = true;
31+
shop.setVariant(update.getEntityVariant());
32+
}
33+
if (update.getLocation() != null) {
34+
Optional<Location> ol = update.getLocation().getLive();
35+
if (!ol.isPresent())
36+
throw new BadRequestException("Could not get Live version of Location");
37+
shop.move(ol.get());
38+
}
39+
if (update.getName() != null && !update.getName().equals(TextSerializers.FORMATTING_CODE.serialize(shop.getDisplayName()))) {
40+
shop.setDisplayName(TextSerializers.FORMATTING_CODE.deserialize(update.getName()));
41+
}
42+
if (update.getOwner() != null && !update.getOwner().equals(shop.getShopOwner().orElse(null))) {
43+
// if (update.isPlayerShop() == null)
44+
// throw new BadRequestException("Missing flag playershop");
45+
// if (!update.isPlayerShop()) {
46+
// throw new BadRequestException("Can't set owner of non player-shops");
47+
// } else {
48+
shop.setPlayerShop(update.getOwner());
49+
// }
50+
// } else if (!update.isPlayerShop()) {
51+
} else if (update.getOwner() == null && shop.getShopOwner().isPresent()) {
52+
shop.setPlayerShop(null);
53+
// } else {
54+
// throw new BadRequestException("Missing owner UUID for player-shop");
55+
}
56+
if (update.getRotation() != null && update.getRotation() != shop.getRot().getY()) {
57+
shop.setRot(new Vector3d(0.0, update.getRotation(), 0.0));
58+
}
59+
if (update.getStockContainer() == null && shop.getStockContainer().isPresent()) {
60+
API.playershop(shop, null, null);
61+
} else if (update.getStockContainer() != null) {
62+
Optional<Location> ol = update.getLocation().getLive();
63+
if (!ol.isPresent())
64+
throw new BadRequestException("Could not get Live version of Stock Location");
65+
if (!ol.get().equals(shop.getStockContainer().orElse(null))) {
66+
API.playershop(shop, shop.getShopOwner().get(), ol.get());
67+
}
68+
}
69+
70+
if (update.getStockItems() != null) {
71+
VillagerShops.closeShopInventories(shop.getIdentifier());
72+
Optional<NPCguard> npc = VillagerShops.getNPCfromShopUUID(shop.getIdentifier());
73+
if (!npc.isPresent()) {
74+
throw new NotFoundException("Shop with id " + shop.getIdentifier() + " not found");
75+
}
76+
InvPrep inv = npc.get().getPreparator();
77+
int s = inv.size();
78+
int newS = update.getStockItems().size();
79+
for (int i = 0; i < Math.max(s, newS); i++) {
80+
if (i >= s) {
81+
CachedStockItem item = update.getStockItems().get(i);
82+
inv.addItem(new StockItem(
83+
item.getItem().createStack(),
84+
item.getSellPrice(),
85+
item.getBuyPrice(),
86+
VillagerShops.getInstance().CurrencyByName(item.getCurrency().getId()),
87+
item.getMaxStock()));
88+
} else if (i >= newS) {
89+
inv.removeIndex(i);
90+
} else {
91+
CachedStockItem item = update.getStockItems().get(i);
92+
inv.setItem(i, new StockItem(
93+
item.getItem().createStack(),
94+
item.getSellPrice(),
95+
item.getBuyPrice(),
96+
VillagerShops.getInstance().CurrencyByName(item.getCurrency().getId()),
97+
item.getMaxStock()));
98+
}
99+
}
100+
}
101+
102+
if (respawnShop && rep != null && !rep.isRemoved()) {
103+
rep.remove();
104+
//tick will respawn the new entity
105+
}
106+
}
107+
108+
}

0 commit comments

Comments
 (0)