Skip to content

Commit

Permalink
Update to API 4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hsyyid committed Mar 8, 2016
1 parent 32626c9 commit 39fc11b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 21 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -23,7 +23,7 @@ repositories {
}

dependencies {
compile "org.spongepowered:spongeapi:3.0.0"
compile "org.spongepowered:spongeapi:4.0.0"
}

test {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/github/hsyyid/adminshop/AdminShop.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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())
Expand All @@ -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;

Expand All @@ -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)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down

0 comments on commit 39fc11b

Please sign in to comment.