Skip to content

Commit

Permalink
fixed meta data not working on buy shops
Browse files Browse the repository at this point in the history
  • Loading branch information
hsyyid committed Nov 1, 2015
1 parent b80a94f commit 8ca6740
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
45 changes: 24 additions & 21 deletions src/main/java/io/github/hsyyid/adminshop/AdminShop.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.spongepowered.api.block.BlockSnapshot;
import org.spongepowered.api.block.BlockTypes;
import org.spongepowered.api.block.tileentity.Sign;
import org.spongepowered.api.data.DataQuery;
import org.spongepowered.api.data.Transaction;
import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.data.manipulator.mutable.tileentity.SignData;
Expand All @@ -41,7 +42,7 @@
import java.math.BigDecimal;
import java.util.ArrayList;

@Plugin(id = "AdminShop", name = "AdminShop", version = "0.7", dependencies = "required-after:TotalEconomy")
@Plugin(id = "AdminShop", name = "AdminShop", version = "0.8", dependencies = "required-after:TotalEconomy")
public class AdminShop
{
public static Game game = null;
Expand Down Expand Up @@ -71,7 +72,7 @@ public Logger getLogger()
@Listener
public void onServerInit(GameInitializationEvent event)
{
getLogger().info("AdminShop loading...");
getLogger().info("AdminShop loading..");

game = event.getGame();
helper = game.getTeleportHelper();
Expand All @@ -94,7 +95,7 @@ public void onServerInit(GameInitializationEvent event)
}

CommandSpec setItemShopCommandSpec = CommandSpec.builder()
.description(Texts.of("Sets Item for an AdminShop"))
.description(Texts.of("Sets Item for a AdminShop"))
.permission("adminshop.setitem")
.arguments(GenericArguments.seq(
GenericArguments.onlyOne(GenericArguments.string(Texts.of("item ID"))),
Expand All @@ -116,13 +117,13 @@ public void onServerInit(GameInitializationEvent event)
public void onServerStart(GameStartedServerEvent event)
{
getLogger().info("Reading AdminShops from JSON");

ConfigManager.readAdminShops();
ConfigManager.readBuyAdminShops();

getLogger().info("AdminShops read from JSON.");
}

@Listener
public void onServerStopping(GameStoppingServerEvent event)
{
Expand Down Expand Up @@ -159,7 +160,7 @@ public void onSignChange(ChangeSignEvent event)
}
else if (player != null)
{
player.sendMessage(Texts.of(TextColors.DARK_RED, "[AdminShop]: ", TextColors.DARK_RED, "Error! ", TextColors.RED, "You don't have permission to create an AdminShop!"));
player.sendMessage(Texts.of(TextColors.DARK_RED, "[AdminShop]: ", TextColors.DARK_RED, "Error! ", TextColors.RED, "You do not have permission to create an AdminShop!"));
}
}
else if (line0.equals("[AdminShopSell]"))
Expand All @@ -177,7 +178,7 @@ else if (line0.equals("[AdminShopSell]"))
}
else if (player != null)
{
player.sendMessage(Texts.of(TextColors.DARK_RED, "[AdminShop]: ", TextColors.DARK_RED, "Error! ", TextColors.RED, "You don't have permission to create an AdminShop!"));
player.sendMessage(Texts.of(TextColors.DARK_RED, "[AdminShop]: ", TextColors.DARK_RED, "Error! ", TextColors.RED, "You do not have permission to create an AdminShop!"));
}
}
}
Expand Down Expand Up @@ -205,13 +206,13 @@ public void onPlayerBreakBlock(ChangeBlockEvent.Break event)

if (thisShop != null && player.hasPermission("adminshop.remove"))
{
player.sendMessage(Texts.of(TextColors.DARK_RED, "[AdminShop]: ", TextColors.GREEN, "AdminShop successfully removed!"));
player.sendMessage(Texts.of(TextColors.DARK_RED, "[AdminShop]:", TextColors.GREEN, " AdminShop successfully removed!"));
adminShops.remove(thisShop);
ConfigManager.writeAdminShops();
}
else if (thisShop != null)
{
player.sendMessage(Texts.of(TextColors.DARK_RED, "[AdminShop]: Error! ", TextColors.RED, "You don't have permission to destroy AdminShops!"));
player.sendMessage(Texts.of(TextColors.DARK_RED, "[AdminShop]: Error!", TextColors.RED, " you do not have permission to destroy AdminShops!"));
event.setCancelled(true);
}
else
Expand All @@ -227,13 +228,13 @@ else if (thisShop != null)

if (thisBuyShop != null && player.hasPermission("adminshop.remove"))
{
player.sendMessage(Texts.of(TextColors.DARK_RED, "[AdminShop]: ", TextColors.GREEN, "AdminShop successfully removed!"));
player.sendMessage(Texts.of(TextColors.DARK_RED, "[AdminShop]:", TextColors.GREEN, " AdminShop successfully removed!"));
buyAdminShops.remove(thisBuyShop);
ConfigManager.writeBuyAdminShops();
}
else if (thisBuyShop != null)
{
player.sendMessage(Texts.of(TextColors.DARK_RED, "[AdminShop]: Error! ", TextColors.RED, "You don't have permission to destroy AdminShops!"));
player.sendMessage(Texts.of(TextColors.DARK_RED, "[AdminShop]: Error!", TextColors.RED, " you do not have permission to destroy AdminShops!"));
event.setCancelled(true);
}
}
Expand Down Expand Up @@ -328,22 +329,24 @@ public void onPlayerInteractBlock(InteractBlockEvent event)

if (thisBuyShop != null)
{
AdminShopModifierObject item = null;
AdminShopModifierObject shopModifier = null;
for (AdminShopModifierObject i : adminShopModifiers)
{
if (i.getPlayer().getUniqueId() == player.getUniqueId())
{
item = i;
shopModifier = i;
break;
}
}

if (item != null)
if (shopModifier != null)
{
buyAdminShops.remove(thisBuyShop);
thisBuyShop.setItemName(item.getItemID());
thisBuyShop.setItemName(shopModifier.getItemID());
if (shopModifier.getMeta() != null)
thisBuyShop.setMeta(shopModifier.getMeta());
buyAdminShops.add(thisBuyShop);
adminShopModifiers.remove(item);
adminShopModifiers.remove(shopModifier);
ConfigManager.writeBuyAdminShops();
player.sendMessage(Texts.of(TextColors.DARK_RED, "[AdminShop]: ", TextColors.GREEN, "Successfully set new item ID."));
}
Expand All @@ -357,18 +360,18 @@ public void onPlayerInteractBlock(InteractBlockEvent event)
AccountManager accountManager = totalEconomy.getAccountManager();
BigDecimal amount = new BigDecimal(price);
int quantityInHand = 0;

if (thisBuyShop.getMeta() != -1)
{
itemName = (itemName + " " + thisBuyShop.getMeta());

if (player.getItemInHand().isPresent() && player.getItemInHand().get().getItem().getName().equals(itemName) && player.getItemInHand().get().getQuantity() == itemAmount)
int meta = thisBuyShop.getMeta();
if (player.getItemInHand().isPresent() && player.getItemInHand().get().getItem().getName().equals(itemName) && player.getItemInHand().get().getQuantity() == itemAmount && player.getItemInHand().get().toContainer().get(new DataQuery("UnsafeDamage")).isPresent() && (Integer) player.getItemInHand().get().toContainer().get(new DataQuery("UnsafeDamage")).get() == meta)
{
player.setItemInHand(null);
accountManager.addToBalance(player.getUniqueId(), amount, true);
player.sendMessage(Texts.of(TextColors.DARK_RED, "[AdminShop]: ", TextColors.GOLD, "You have just sold " + itemAmount + " " + itemName + " for " + price + " dollars."));
}
else if (player.getItemInHand().isPresent() && player.getItemInHand().get().getItem().getName().equals(itemName) && player.getItemInHand().get().getQuantity() > itemAmount)
else if (player.getItemInHand().isPresent() && player.getItemInHand().get().getItem().getName().equals(itemName) && player.getItemInHand().get().getQuantity() > itemAmount && player.getItemInHand().get().toContainer().get(new DataQuery("UnsafeDamage")).isPresent() && (Integer) player.getItemInHand().get().toContainer().get(new DataQuery("UnsafeDamage")).get() == meta)
{
quantityInHand = player.getItemInHand().get().getQuantity() - itemAmount;
player.setItemInHand(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static void readBuyAdminShops()
}
else
{
System.out.println("Could not read JSON file!");
System.out.println("Could not read GSON from JSON file!");
}
}

Expand Down

0 comments on commit 8ca6740

Please sign in to comment.