diff --git a/common/src/main/java/net/impactdev/gts/common/discord/DiscordNotifier.java b/common/src/main/java/net/impactdev/gts/common/discord/DiscordNotifier.java index df3c492c..bb8d0bf6 100644 --- a/common/src/main/java/net/impactdev/gts/common/discord/DiscordNotifier.java +++ b/common/src/main/java/net/impactdev/gts/common/discord/DiscordNotifier.java @@ -171,7 +171,7 @@ public String parse(@NonNull String message, @NonNull List> sou Optional.ofNullable(this.placeholders.get(placeholder.toLowerCase())).ifPresent(parser -> { String out = parser.parse(sources); if(out != null) { - result.set(result.get().replaceAll("[{][{]" + placeholder + "[}][}]", out)); + result.set(result.get().replace("[{][{]" + placeholder + "[}][}]", out)); } }); } diff --git a/common/src/main/java/net/impactdev/gts/common/storage/implementation/sql/SqlImplementation.java b/common/src/main/java/net/impactdev/gts/common/storage/implementation/sql/SqlImplementation.java index bd867e1e..9abe6629 100644 --- a/common/src/main/java/net/impactdev/gts/common/storage/implementation/sql/SqlImplementation.java +++ b/common/src/main/java/net/impactdev/gts/common/storage/implementation/sql/SqlImplementation.java @@ -416,15 +416,34 @@ public BuyItNowMessage.Purchase.Response processPurchase(BuyItNowMessage.Purchas ps.setString(1, request.getListingID().toString()); return this.results(ps, results -> { boolean successful = results.next(); + BuyItNow listing = null; - UUID seller = this.getListing(request.getListingID()).map(Listing::getLister).orElse(Listing.SERVER_ID); + JsonObject json = GTSPlugin.getInstance().getGson().fromJson(results.getString("listing"), JsonObject.class); + if(!json.has("type")) { + throw new JsonParseException("Invalid Listing: Missing type"); + } + + String type = json.get("type").getAsString(); + if(type.equals("bin")) { + listing = GTSService.getInstance().getGTSComponentManager() + .getListingResourceManager(BuyItNow.class) + .get() + .getDeserializer() + .deserialize(json); + } else { + throw new IllegalArgumentException("Can't purchase an Auction"); + } + + if(successful) { + successful = !listing.isPurchased(); + } return new BINPurchaseMessage.Response( GTSPlugin.getInstance().getMessagingService().generatePingID(), request.getID(), request.getListingID(), request.getActor(), - seller, + listing != null ? listing.getLister() : Listing.SERVER_ID, successful, successful ? null : ErrorCodes.ALREADY_PURCHASED ); diff --git a/plugin/plugin-sponge/build.gradle b/plugin/plugin-sponge/build.gradle index 10fb3077..645eb628 100644 --- a/plugin/plugin-sponge/build.gradle +++ b/plugin/plugin-sponge/build.gradle @@ -18,7 +18,7 @@ plugins { apply plugin: 'net.minecraftforge.gradle.forge' minecraft { - version = "1.12.2-14.23.5.2768" + version = "1.12.2-14.23.5.2838" runDir = "run" mappings = "snapshot_20180324" useDepAts = true diff --git a/plugin/plugin-sponge/src/main/java/net/impactdev/gts/GTSSpongePlugin.java b/plugin/plugin-sponge/src/main/java/net/impactdev/gts/GTSSpongePlugin.java index 9a9d584a..2f8a9374 100644 --- a/plugin/plugin-sponge/src/main/java/net/impactdev/gts/GTSSpongePlugin.java +++ b/plugin/plugin-sponge/src/main/java/net/impactdev/gts/GTSSpongePlugin.java @@ -102,15 +102,15 @@ public GTSSpongePlugin(GTSSpongeBootstrap bootstrap, org.slf4j.Logger fallback) } public void preInit() { + Utilities.setContainer(this.bootstrap.getContainer()); + Impactor.getInstance().getRegistry().register(GTSPlugin.class, this); + ApiRegistrationUtil.register(new GTSAPIProvider()); + String sponge = Sponge.getGame().getPlatform().getContainer(Platform.Component.API).getVersion().orElse(""); if(!sponge.startsWith("7.3")) { throw new IllegalStateException("Invalid Sponge version"); } - Utilities.setContainer(this.bootstrap.getContainer()); - Impactor.getInstance().getRegistry().register(GTSPlugin.class, this); - ApiRegistrationUtil.register(new GTSAPIProvider()); - this.displayBanner(); this.getPluginLogger().info("Initializing API Components..."); diff --git a/plugin/plugin-sponge/src/main/java/net/impactdev/gts/manager/SpongeListingManager.java b/plugin/plugin-sponge/src/main/java/net/impactdev/gts/manager/SpongeListingManager.java index 071501e7..40c4bd78 100644 --- a/plugin/plugin-sponge/src/main/java/net/impactdev/gts/manager/SpongeListingManager.java +++ b/plugin/plugin-sponge/src/main/java/net/impactdev/gts/manager/SpongeListingManager.java @@ -425,7 +425,7 @@ public CompletableFuture purchase(UUID buyer, SpongeBuyItNow listing, O Sponge.getServer().getPlayer(buyer).ifPresent(player -> { player.sendMessage(parser.parse( Utilities.readMessageConfigOption(MsgConfigKeys.REQUEST_FAILED), - Lists.newArrayList(() -> ErrorCodes.THIRD_PARTY_CANCELLED) + Lists.newArrayList(() -> response.getErrorCode().orElse(ErrorCodes.UNKNOWN)) )); player.sendMessage(parser.parse(