diff --git a/build.gradle b/build.gradle index 4020012..ba06ea7 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'eclipse' sourceCompatibility = 1.8 targetCompatibility = 1.8 -version = '1.4' +version = '1.5' group = "io.github.hsyyid" archivesBaseName = "AdminShop" @@ -23,7 +23,7 @@ repositories { } dependencies { - compile "org.spongepowered:spongeapi:3.0.0" + compile "org.spongepowered:spongeapi:4.0.0" } test { diff --git a/src/main/java/io/github/hsyyid/adminshop/AdminShop.java b/src/main/java/io/github/hsyyid/adminshop/AdminShop.java index 38aabd5..9fdb160 100644 --- a/src/main/java/io/github/hsyyid/adminshop/AdminShop.java +++ b/src/main/java/io/github/hsyyid/adminshop/AdminShop.java @@ -31,7 +31,7 @@ import java.util.ArrayList; import java.util.Optional; -@Plugin(id = "AdminShop", name = "AdminShop", version = "1.4") +@Plugin(id = "io.github.hsyyid.adminshop", name = "AdminShop", description = "This plugin adds sign shops for users to buy items.", version = "1.5") public class AdminShop { protected AdminShop() diff --git a/src/main/java/io/github/hsyyid/adminshop/listeners/PlayerInteractBlockListener.java b/src/main/java/io/github/hsyyid/adminshop/listeners/PlayerInteractBlockListener.java index 15c78a8..650621d 100644 --- a/src/main/java/io/github/hsyyid/adminshop/listeners/PlayerInteractBlockListener.java +++ b/src/main/java/io/github/hsyyid/adminshop/listeners/PlayerInteractBlockListener.java @@ -11,6 +11,7 @@ import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.block.InteractBlockEvent; import org.spongepowered.api.event.cause.Cause; +import org.spongepowered.api.event.cause.NamedCause; import org.spongepowered.api.event.filter.cause.First; import org.spongepowered.api.item.inventory.ItemStack; import org.spongepowered.api.service.economy.account.UniqueAccount; @@ -72,13 +73,8 @@ public void onPlayerInteractBlock(InteractBlockEvent event, @First Player player BigDecimal amount = new BigDecimal(price); - if (!AdminShop.economyService.getAccount(player.getUniqueId()).isPresent()) - { - AdminShop.economyService.createAccount(player.getUniqueId()); - } - - UniqueAccount playerAccount = AdminShop.economyService.getAccount(player.getUniqueId()).get(); - ResultType result = playerAccount.withdraw(AdminShop.economyService.getDefaultCurrency(), amount, Cause.of(this)).getResult(); + UniqueAccount playerAccount = AdminShop.economyService.getOrCreateAccount(player.getUniqueId()).get(); + ResultType result = playerAccount.withdraw(AdminShop.economyService.getDefaultCurrency(), amount, Cause.of(NamedCause.source(player))).getResult(); if (result == ResultType.SUCCESS) { @@ -118,7 +114,7 @@ else if (result == ResultType.FAILED) if (thisBuyShop != null) { AdminShopModifierObject shopModifier = null; - + for (AdminShopModifierObject i : AdminShop.adminShopModifiers) { if (i.getPlayer().getUniqueId() == player.getUniqueId()) @@ -145,12 +141,7 @@ else if (result == ResultType.FAILED) double price = thisBuyShop.getPrice(); String itemName = thisBuyShop.getItemName(); - if (!AdminShop.economyService.getAccount(player.getUniqueId()).isPresent()) - { - AdminShop.economyService.createAccount(player.getUniqueId()); - } - - UniqueAccount playerAccount = AdminShop.economyService.getAccount(player.getUniqueId()).get(); + UniqueAccount playerAccount = AdminShop.economyService.getOrCreateAccount(player.getUniqueId()).get(); BigDecimal amount = new BigDecimal(price); int quantityInHand = 0; @@ -160,7 +151,7 @@ else if (result == ResultType.FAILED) if (player.getItemInHand().isPresent() && player.getItemInHand().get().getItem().getName().equals(itemName) && player.getItemInHand().get().getQuantity() == itemAmount && player.getItemInHand().get().toContainer().get(DataQuery.of("UnsafeDamage")).isPresent() && (Integer) player.getItemInHand().get().toContainer().get(DataQuery.of("UnsafeDamage")).get() == meta) { - ResultType result = playerAccount.deposit(AdminShop.economyService.getDefaultCurrency(), amount, Cause.of(this)).getResult(); + ResultType result = playerAccount.deposit(AdminShop.economyService.getDefaultCurrency(), amount, Cause.of(NamedCause.source(player))).getResult(); if (result == ResultType.SUCCESS) { @@ -178,7 +169,7 @@ else if (result == ResultType.FAILED) } else if (player.getItemInHand().isPresent() && player.getItemInHand().get().getItem().getName().equals(itemName) && player.getItemInHand().get().getQuantity() > itemAmount && player.getItemInHand().get().toContainer().get(DataQuery.of("UnsafeDamage")).isPresent() && (Integer) player.getItemInHand().get().toContainer().get(DataQuery.of("UnsafeDamage")).get() == meta) { - ResultType result = playerAccount.deposit(AdminShop.economyService.getDefaultCurrency(), amount, Cause.of(this)).getResult(); + ResultType result = playerAccount.deposit(AdminShop.economyService.getDefaultCurrency(), amount, Cause.of(NamedCause.source(player))).getResult(); if (result == ResultType.SUCCESS) { @@ -206,7 +197,7 @@ else if (result == ResultType.FAILED) { if (player.getItemInHand().isPresent() && player.getItemInHand().get().getItem().getName().equals(itemName) && player.getItemInHand().get().getQuantity() == itemAmount) { - ResultType result = playerAccount.deposit(AdminShop.economyService.getDefaultCurrency(), amount, Cause.of(this)).getResult(); + ResultType result = playerAccount.deposit(AdminShop.economyService.getDefaultCurrency(), amount, Cause.of(NamedCause.source(player))).getResult(); if (result == ResultType.SUCCESS) { @@ -224,7 +215,7 @@ else if (result == ResultType.FAILED) } else if (player.getItemInHand().isPresent() && player.getItemInHand().get().getItem().getName().equals(itemName) && player.getItemInHand().get().getQuantity() > itemAmount) { - ResultType result = playerAccount.deposit(AdminShop.economyService.getDefaultCurrency(), amount, Cause.of(this)).getResult(); + ResultType result = playerAccount.deposit(AdminShop.economyService.getDefaultCurrency(), amount, Cause.of(NamedCause.source(player))).getResult(); if (result == ResultType.SUCCESS) {