Sign shop almost works, woo!

This commit is contained in:
AppleDash 2016-10-23 13:41:14 -04:00
parent 7dc66d143e
commit 56a9fa8797
4 changed files with 19 additions and 9 deletions

View File

@ -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<SignShop> 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)));

View File

@ -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();
}

View File

@ -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?
}
/**

View File

@ -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;