Begin working on SaneEconomySignShop (100th commit!)
This commit is contained in:
parent
ee79c639bc
commit
3b3c24db27
|
@ -14,5 +14,4 @@ RemoteSystemsTempFiles/.project
|
||||||
out/
|
out/
|
||||||
target/
|
target/
|
||||||
dependency-reduced-pom.xml
|
dependency-reduced-pom.xml
|
||||||
SaneEconomySignShop/
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>SaneEconomy</artifactId>
|
||||||
|
<groupId>org.appledash</groupId>
|
||||||
|
<version>0.8.4-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>SaneEconomySignShop</artifactId>
|
||||||
|
<version>0.1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<finalName>${project.artifactId}-${project.version}</finalName>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.3</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>2.4</version>
|
||||||
|
<configuration>
|
||||||
|
<outputDirectory>../out/</outputDirectory>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
|
@ -0,0 +1,19 @@
|
||||||
|
package org.appledash.saneeconomysignshop;
|
||||||
|
|
||||||
|
import org.appledash.saneeconomysignshop.listeners.SignChangeListener;
|
||||||
|
import org.appledash.saneeconomysignshop.signshop.SignShopManager;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by appledash on 10/2/16.
|
||||||
|
* Blackjack is still best pony.
|
||||||
|
*/
|
||||||
|
public class SaneEconomySignShop extends JavaPlugin {
|
||||||
|
private final SignShopManager signShopManager = new SignShopManager();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
signShopManager.loadSignShops();
|
||||||
|
getServer().getPluginManager().registerEvents(new SignChangeListener(this), this);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,108 @@
|
||||||
|
package org.appledash.saneeconomysignshop.listeners;
|
||||||
|
|
||||||
|
import com.google.common.base.Strings;
|
||||||
|
import org.appledash.saneeconomysignshop.SaneEconomySignShop;
|
||||||
|
import org.appledash.saneeconomysignshop.signshop.SignShop;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.SignChangeEvent;
|
||||||
|
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by appledash on 10/2/16.
|
||||||
|
* Blackjack is still best pony.
|
||||||
|
*/
|
||||||
|
public class SignChangeListener implements Listener {
|
||||||
|
private SaneEconomySignShop plugin;
|
||||||
|
|
||||||
|
public SignChangeListener(SaneEconomySignShop plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onSignChange(SignChangeEvent evt) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private ParsedSignShop parseSignShop(SignChangeEvent evt) {
|
||||||
|
String[] lines = evt.getLines();
|
||||||
|
Player player = evt.getPlayer();
|
||||||
|
Location location = evt.getBlock().getLocation();
|
||||||
|
|
||||||
|
if ((lines[0] == null) || !lines[0].equalsIgnoreCase("Admin Shop")) { // First line must say "Admin Shop"
|
||||||
|
return new ParsedSignShop();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Strings.isNullOrEmpty(lines[1])) { // Second line must contain an item name
|
||||||
|
return new ParsedSignShop("No item name specified.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Strings.isNullOrEmpty(lines[2])) { // Second line must contain buy/sell prices
|
||||||
|
return new ParsedSignShop("No buy/sell price(s) specified.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Strings.isNullOrEmpty(lines[3])) { // Third line must contain item amount.
|
||||||
|
return new ParsedSignShop("No item amount specified.");
|
||||||
|
}
|
||||||
|
|
||||||
|
String itemName = lines[1];
|
||||||
|
String buySellRaw = lines[2];
|
||||||
|
String amountRaw = lines[3];
|
||||||
|
|
||||||
|
Material mat = Material.getMaterial(itemName.toUpperCase().replace(" ", "_"));
|
||||||
|
|
||||||
|
if (mat == null) {
|
||||||
|
// Invalid material.
|
||||||
|
return new ParsedSignShop("Invalid item name specified.");
|
||||||
|
}
|
||||||
|
|
||||||
|
Matcher m = Pattern.compile("(B:(?<buy>[0-9.]+))?[ ]*(S:(?<sell>[0-9.]+))?").matcher(buySellRaw);
|
||||||
|
|
||||||
|
if (!m.find()) {
|
||||||
|
return new ParsedSignShop("Invalid buy/sell prices specified.");
|
||||||
|
}
|
||||||
|
|
||||||
|
double buy = Strings.isNullOrEmpty(m.group("buy")) ? -1.0 : Double.valueOf(m.group("buy"));
|
||||||
|
double sell = Strings.isNullOrEmpty(m.group("sell")) ? -1.0 : Double.valueOf(m.group("sell"));
|
||||||
|
|
||||||
|
if ((buy == -1) && (sell == -1)) {
|
||||||
|
return new ParsedSignShop("Buy and sell amounts for this shop are both invalid.");
|
||||||
|
}
|
||||||
|
|
||||||
|
int itemAmount;
|
||||||
|
|
||||||
|
try {
|
||||||
|
itemAmount = Integer.valueOf(amountRaw);
|
||||||
|
|
||||||
|
if (itemAmount <= 0) {
|
||||||
|
throw new NumberFormatException();
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return new ParsedSignShop("Item amount is not a positive integer.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ParsedSignShop(new SignShop(player.getUniqueId(), location, mat, buy, sell));
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ParsedSignShop {
|
||||||
|
private SignShop shop;
|
||||||
|
private String error;
|
||||||
|
|
||||||
|
private ParsedSignShop(String error) {
|
||||||
|
this.error = error;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ParsedSignShop() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private ParsedSignShop(SignShop shop) {
|
||||||
|
this.shop = shop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
package org.appledash.saneeconomysignshop.signshop;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by appledash on 10/2/16.
|
||||||
|
* Blackjack is still best pony.
|
||||||
|
*/
|
||||||
|
public class SignShop {
|
||||||
|
private final UUID ownerUuid;
|
||||||
|
private final Location location;
|
||||||
|
private final Material item;
|
||||||
|
private final double buyAmount;
|
||||||
|
private final double sellAmount;
|
||||||
|
|
||||||
|
public SignShop(UUID ownerUuid, Location location, Material item, double buyAmount, double sellAmount) {
|
||||||
|
this.ownerUuid = ownerUuid;
|
||||||
|
this.location = location;
|
||||||
|
this.item = item;
|
||||||
|
this.buyAmount = buyAmount;
|
||||||
|
this.sellAmount = sellAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getLocation() {
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Material getItem() {
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getBuyAmount() {
|
||||||
|
return buyAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getSellAmount() {
|
||||||
|
return sellAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canBuy() {
|
||||||
|
return buyAmount >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canSell() {
|
||||||
|
return sellAmount >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getOwnerUuid() {
|
||||||
|
return ownerUuid;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
package org.appledash.saneeconomysignshop.signshop;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by appledash on 10/2/16.
|
||||||
|
* Blackjack is still best pony.
|
||||||
|
*/
|
||||||
|
public class SignShopManager {
|
||||||
|
private Map<Location, SignShop> signShops = new HashMap<Location, SignShop>();
|
||||||
|
|
||||||
|
public void loadSignShops() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addSignShop(SignShop signShop) {
|
||||||
|
signShops.put(signShop.getLocation(), signShop);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<SignShop> getSignShop(Location location) {
|
||||||
|
return Optional.ofNullable(signShops.get(location));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
name: SaneEconomySignShop
|
||||||
|
main: org.appledash.saneeconomysignshop.SaneEconomySignshop
|
||||||
|
author: AppleDash
|
||||||
|
version: 0.1.0
|
||||||
|
depend: [SaneEconomy]
|
Loading…
Reference in New Issue