mirror of
https://github.com/AppleDash/SaneEconomy.git
synced 2024-10-01 07:57:46 +02:00
Sign shop almost works, woo!
This commit is contained in:
parent
7dc66d143e
commit
56a9fa8797
@ -8,6 +8,7 @@ import org.appledash.saneeconomy.economy.transaction.TransactionResult;
|
|||||||
import org.appledash.saneeconomy.utils.MessageUtils;
|
import org.appledash.saneeconomy.utils.MessageUtils;
|
||||||
import org.appledash.saneeconomysignshop.SaneEconomySignShop;
|
import org.appledash.saneeconomysignshop.SaneEconomySignShop;
|
||||||
import org.appledash.saneeconomysignshop.signshop.SignShop;
|
import org.appledash.saneeconomysignshop.signshop.SignShop;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@ -39,6 +40,10 @@ public class InteractListener implements Listener {
|
|||||||
return;
|
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());
|
Optional<SignShop> shopOptional = plugin.getSignShopManager().getSignShop(evt.getClickedBlock().getLocation());
|
||||||
|
|
||||||
if (!shopOptional.isPresent()) {
|
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)));
|
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();
|
EconomyManager ecoMan = plugin.getSaneEconomy().getEconomyManager();
|
||||||
int quantity = player.isSneaking() ? 1 : shop.getQuantity();
|
int quantity = player.isSneaking() ? 1 : shop.getQuantity();
|
||||||
double price = shop.getSellPrice(quantity);
|
double price = shop.getSellPrice(quantity);
|
||||||
@ -101,6 +106,8 @@ public class InteractListener implements Listener {
|
|||||||
return;
|
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()
|
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));
|
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)));
|
MessageUtils.sendMessage(player, String.format("You have sold %d %s for %s.", quantity, shop.getItem(), ecoMan.getCurrency().formatAmount(price)));
|
||||||
|
@ -67,7 +67,7 @@ public class SignChangeListener implements Listener {
|
|||||||
Player player = evt.getPlayer();
|
Player player = evt.getPlayer();
|
||||||
Location location = evt.getBlock().getLocation();
|
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();
|
return new ParsedSignShop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,17 +1,19 @@
|
|||||||
package org.appledash.saneeconomysignshop.signshop;
|
package org.appledash.saneeconomysignshop.signshop;
|
||||||
|
|
||||||
|
import org.appledash.saneeconomysignshop.util.SerializableLocation;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by appledash on 10/2/16.
|
* Created by appledash on 10/2/16.
|
||||||
* Blackjack is still best pony.
|
* Blackjack is still best pony.
|
||||||
*/
|
*/
|
||||||
public class SignShop {
|
public class SignShop implements Serializable {
|
||||||
private final UUID ownerUuid;
|
private final UUID ownerUuid;
|
||||||
private final Location location;
|
private final SerializableLocation location;
|
||||||
private final Material item;
|
private final Material item;
|
||||||
private final int quantity;
|
private final int quantity;
|
||||||
private final double buyPrice;
|
private final double buyPrice;
|
||||||
@ -27,7 +29,7 @@ public class SignShop {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.ownerUuid = ownerUuid;
|
this.ownerUuid = ownerUuid;
|
||||||
this.location = location;
|
this.location = new SerializableLocation(location);
|
||||||
this.item = item;
|
this.item = item;
|
||||||
this.quantity = quantity;
|
this.quantity = quantity;
|
||||||
this.buyPrice = buyPrice;
|
this.buyPrice = buyPrice;
|
||||||
@ -39,7 +41,7 @@ public class SignShop {
|
|||||||
* @return Location
|
* @return Location
|
||||||
*/
|
*/
|
||||||
public Location getLocation() {
|
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
|
* @return Price to buy that number of items at this shop
|
||||||
*/
|
*/
|
||||||
public double getBuyPrice(int quantity) {
|
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
|
* @return Price to sell that number of items at this shop
|
||||||
*/
|
*/
|
||||||
public double getSellPrice(int quantity) {
|
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?
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3,13 +3,14 @@ package org.appledash.saneeconomysignshop.util;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by appledash on 10/17/16.
|
* Created by appledash on 10/17/16.
|
||||||
* Blackjack is best pony.
|
* Blackjack is best pony.
|
||||||
*/
|
*/
|
||||||
public class SerializableLocation {
|
public class SerializableLocation implements Serializable {
|
||||||
private double x, y, z;
|
private double x, y, z;
|
||||||
private float yaw, pitch;
|
private float yaw, pitch;
|
||||||
private UUID worldUuid;
|
private UUID worldUuid;
|
||||||
|
Loading…
Reference in New Issue
Block a user