From 56a9fa87976b566651035a76aec815bd34ca20e5 Mon Sep 17 00:00:00 2001 From: AppleDash Date: Sun, 23 Oct 2016 13:41:14 -0400 Subject: [PATCH] Sign shop almost works, woo! --- .../listeners/InteractListener.java | 9 ++++++++- .../listeners/SignChangeListener.java | 2 +- .../saneeconomysignshop/signshop/SignShop.java | 14 ++++++++------ .../util/SerializableLocation.java | 3 ++- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/SaneEconomySignShop/src/main/java/org/appledash/saneeconomysignshop/listeners/InteractListener.java b/SaneEconomySignShop/src/main/java/org/appledash/saneeconomysignshop/listeners/InteractListener.java index ad99c4e..d093520 100644 --- a/SaneEconomySignShop/src/main/java/org/appledash/saneeconomysignshop/listeners/InteractListener.java +++ b/SaneEconomySignShop/src/main/java/org/appledash/saneeconomysignshop/listeners/InteractListener.java @@ -8,6 +8,7 @@ import org.appledash.saneeconomy.economy.transaction.TransactionResult; import org.appledash.saneeconomy.utils.MessageUtils; import org.appledash.saneeconomysignshop.SaneEconomySignShop; import org.appledash.saneeconomysignshop.signshop.SignShop; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -39,6 +40,10 @@ public class InteractListener implements Listener { return; } + if (evt.getPlayer().getInventory().getItemInMainHand() != null && evt.getPlayer().getInventory().getItemInMainHand().getType() == Material.DIAMOND_AXE) { + return; + } + Optional shopOptional = plugin.getSignShopManager().getSignShop(evt.getClickedBlock().getLocation()); if (!shopOptional.isPresent()) { @@ -91,7 +96,7 @@ public class InteractListener implements Listener { MessageUtils.sendMessage(player, String.format("You have bought %d %s for %s.", quantity, shop.getItem(), ecoMan.getCurrency().formatAmount(price))); } - private void doSell(SignShop shop, Player player) { + private void doSell(SignShop shop, Player player) { // TODO: Selling enchanted items EconomyManager ecoMan = plugin.getSaneEconomy().getEconomyManager(); int quantity = player.isSneaking() ? 1 : shop.getQuantity(); double price = shop.getSellPrice(quantity); @@ -101,6 +106,8 @@ public class InteractListener implements Listener { return; } + System.out.printf("The amount is: %f\n", price); + player.getInventory().removeItem(new ItemStack(shop.getItem(), quantity)); // FIXME: This does not remove items with damage values that were detected by contains() ecoMan.transact(new Transaction(Economable.PLUGIN, Economable.wrap(player), price, TransactionReason.PLUGIN_GIVE)); MessageUtils.sendMessage(player, String.format("You have sold %d %s for %s.", quantity, shop.getItem(), ecoMan.getCurrency().formatAmount(price))); diff --git a/SaneEconomySignShop/src/main/java/org/appledash/saneeconomysignshop/listeners/SignChangeListener.java b/SaneEconomySignShop/src/main/java/org/appledash/saneeconomysignshop/listeners/SignChangeListener.java index 2b88b85..50ec377 100644 --- a/SaneEconomySignShop/src/main/java/org/appledash/saneeconomysignshop/listeners/SignChangeListener.java +++ b/SaneEconomySignShop/src/main/java/org/appledash/saneeconomysignshop/listeners/SignChangeListener.java @@ -67,7 +67,7 @@ public class SignChangeListener implements Listener { Player player = evt.getPlayer(); Location location = evt.getBlock().getLocation(); - if ((lines[0] == null) || !lines[0].equalsIgnoreCase("Admin Shop")) { // First line must say "Admin Shop" + if ((lines[0] == null) || !lines[0].equalsIgnoreCase(plugin.getConfig().getString("admin-shop-trigger"))) { // First line must contain the trigger return new ParsedSignShop(); } diff --git a/SaneEconomySignShop/src/main/java/org/appledash/saneeconomysignshop/signshop/SignShop.java b/SaneEconomySignShop/src/main/java/org/appledash/saneeconomysignshop/signshop/SignShop.java index ed8b3b0..53199a0 100644 --- a/SaneEconomySignShop/src/main/java/org/appledash/saneeconomysignshop/signshop/SignShop.java +++ b/SaneEconomySignShop/src/main/java/org/appledash/saneeconomysignshop/signshop/SignShop.java @@ -1,17 +1,19 @@ package org.appledash.saneeconomysignshop.signshop; +import org.appledash.saneeconomysignshop.util.SerializableLocation; import org.bukkit.Location; import org.bukkit.Material; +import java.io.Serializable; import java.util.UUID; /** * Created by appledash on 10/2/16. * Blackjack is still best pony. */ -public class SignShop { +public class SignShop implements Serializable { private final UUID ownerUuid; - private final Location location; + private final SerializableLocation location; private final Material item; private final int quantity; private final double buyPrice; @@ -27,7 +29,7 @@ public class SignShop { } this.ownerUuid = ownerUuid; - this.location = location; + this.location = new SerializableLocation(location); this.item = item; this.quantity = quantity; this.buyPrice = buyPrice; @@ -39,7 +41,7 @@ public class SignShop { * @return Location */ public Location getLocation() { - return location; + return location.getBukkitLocation(); } /** @@ -73,7 +75,7 @@ public class SignShop { * @return Price to buy that number of items at this shop */ public double getBuyPrice(int quantity) { - return Math.ceil(this.buyPrice * (quantity / this.quantity)); // TODO: Is this okay? + return this.buyPrice * ((float)quantity / (float)this.quantity); // TODO: Is this okay? } /** @@ -83,7 +85,7 @@ public class SignShop { * @return Price to sell that number of items at this shop */ public double getSellPrice(int quantity) { - return Math.floor(this.sellPrice * (quantity / this.quantity)); // TODO: Is this okay? + return this.sellPrice * ((float)quantity / (float)this.quantity); // TODO: Is this okay? } /** diff --git a/SaneEconomySignShop/src/main/java/org/appledash/saneeconomysignshop/util/SerializableLocation.java b/SaneEconomySignShop/src/main/java/org/appledash/saneeconomysignshop/util/SerializableLocation.java index a97f6b1..fd014e8 100644 --- a/SaneEconomySignShop/src/main/java/org/appledash/saneeconomysignshop/util/SerializableLocation.java +++ b/SaneEconomySignShop/src/main/java/org/appledash/saneeconomysignshop/util/SerializableLocation.java @@ -3,13 +3,14 @@ package org.appledash.saneeconomysignshop.util; import org.bukkit.Bukkit; import org.bukkit.Location; +import java.io.Serializable; import java.util.UUID; /** * Created by appledash on 10/17/16. * Blackjack is best pony. */ -public class SerializableLocation { +public class SerializableLocation implements Serializable { private double x, y, z; private float yaw, pitch; private UUID worldUuid;