summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsnowleo <snowleo@e251c2fe-e539-e718-e476-b85c1f46cddb>2011-04-16 06:28:56 +0000
committersnowleo <snowleo@e251c2fe-e539-e718-e476-b85c1f46cddb>2011-04-16 06:28:56 +0000
commitc849bf7fe90576d9aa44252e9e7bf2649d23d531 (patch)
tree7407f87a5802169925f3e04f109e2249abe624d2
parentcf144b1a646cdcc17bef79b3c5e8df64e7629b10 (diff)
downloadEssentials-c849bf7fe90576d9aa44252e9e7bf2649d23d531.tar
Essentials-c849bf7fe90576d9aa44252e9e7bf2649d23d531.tar.gz
Essentials-c849bf7fe90576d9aa44252e9e7bf2649d23d531.tar.lz
Essentials-c849bf7fe90576d9aa44252e9e7bf2649d23d531.tar.xz
Essentials-c849bf7fe90576d9aa44252e9e7bf2649d23d531.zip
[trunk] Worth/Sell: Support for double values as prices and more important: support for data items.
the yaml structure has changed, there is a fallback to the old structure. This code is untested. git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1211 e251c2fe-e539-e718-e476-b85c1f46cddb
-rw-r--r--Essentials/src/com/earth2me/essentials/Worth.java21
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandsell.java7
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandworth.java2
4 files changed, 24 insertions, 8 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Worth.java b/Essentials/src/com/earth2me/essentials/Worth.java
index cec56408b..ce3e83980 100644
--- a/Essentials/src/com/earth2me/essentials/Worth.java
+++ b/Essentials/src/com/earth2me/essentials/Worth.java
@@ -2,6 +2,7 @@ package com.earth2me.essentials;
import java.io.File;
import java.util.logging.Logger;
+import org.bukkit.inventory.ItemStack;
public class Worth implements IConf
@@ -16,14 +17,26 @@ public class Worth implements IConf
config.load();
}
- public int getPrice(String id)
+ public double getPrice(ItemStack itemStack)
{
- return config.getInt("worth-" + id, 0);
+ double result = config.getDouble("worth."+itemStack.getType().toString().toLowerCase()+"."+itemStack.getData().getData(), Double.NaN);
+ if (Double.isNaN(result)) {
+ result = config.getDouble("worth."+itemStack.getType().toString().toLowerCase(), Double.NaN);
+ }
+ if (Double.isNaN(result)) {
+ result = config.getDouble("worth-"+itemStack.getTypeId(), 0.0);
+ }
+ return result;
}
- public void setPrice(String id, int price)
+ public void setPrice(ItemStack itemStack, double price)
{
- config.setProperty("worth-" + id, price);
+ if (itemStack.getType().getData() == null) {
+ config.setProperty("worth." + itemStack.getType().toString().toLowerCase(), price);
+ } else {
+ config.setProperty("worth." + itemStack.getType().toString().toLowerCase()+"."+itemStack.getData().getData(), price);
+ }
+ config.removeProperty("worth-"+itemStack.getTypeId());
config.save();
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsell.java b/Essentials/src/com/earth2me/essentials/commands/Commandsell.java
index d81b23c6c..97cee37b6 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandsell.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandsell.java
@@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
import org.bukkit.Server;
import com.earth2me.essentials.Essentials;
+import com.earth2me.essentials.InventoryWorkaround;
import com.earth2me.essentials.User;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
@@ -24,7 +25,7 @@ public class Commandsell extends EssentialsCommand
int id = is.getTypeId();
int amount = 0;
if (args.length > 0) amount = Integer.parseInt(args[0].replaceAll("[^0-9]", ""));
- int worth = Essentials.getWorth().getPrice(String.valueOf(id));
+ double worth = Essentials.getWorth().getPrice(is);
boolean stack = args.length > 0 && args[0].endsWith("s");
boolean requireStack = parent.getConfiguration().getBoolean("trade-in-stacks-" + id, false);
@@ -34,6 +35,8 @@ public class Commandsell extends EssentialsCommand
int max = 0;
for (ItemStack s : user.getInventory().all(is).values())
{
+ if (s.getDurability() != is.getDurability())
+ continue;
max += s.getAmount();
}
@@ -54,7 +57,7 @@ public class Commandsell extends EssentialsCommand
}
user.charge(this);
- user.getInventory().removeItem(new ItemStack(id, amount));
+ InventoryWorkaround.removeItem(user.getInventory(), true, new ItemStack(is.getType(), amount, is.getDurability()));
user.updateInventory();
user.giveMoney(worth * amount);
user.sendMessage("§7Sold for §c$" + (worth * amount) + "§7 (" + amount + " items at $" + worth + " each)");
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java b/Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java
index bfe228f8f..2b27b6045 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java
@@ -23,7 +23,7 @@ public class Commandsetworth extends EssentialsCommand
return;
}
ItemStack stack = ItemDb.get(args[0]);
- Essentials.getWorth().setPrice(Integer.toString(stack.getTypeId()), Integer.parseInt(args[1]));
+ Essentials.getWorth().setPrice(stack, Integer.parseInt(args[1]));
user.charge(this);
user.sendMessage("§7Worth value set");
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandworth.java b/Essentials/src/com/earth2me/essentials/commands/Commandworth.java
index 0f80a99b0..66e1be715 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandworth.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandworth.java
@@ -39,7 +39,7 @@ public class Commandworth extends EssentialsCommand
amount = 64;
}
- int worth = Essentials.getWorth().getPrice(String.valueOf(id));
+ double worth = Essentials.getWorth().getPrice(is);
user.charge(this);
user.sendMessage("§7Stack of " + id + " worth §c$" + (worth * amount) + "§7 (" + amount + " item(s) at $" + worth + " each)");