Dropping some spout usage. Adding date argument reader

This commit is contained in:
Olof Larsson 2012-03-19 12:03:52 +01:00
parent 157b7b002e
commit cb5f71f2c8
5 changed files with 57 additions and 3 deletions

View File

@ -1,6 +1,6 @@
name: mcore2
version: 1.0.0
main: com.massivecraft.mcore2dev.MCore
main: com.massivecraft.mcore2.MCore
authors: [Olof Larsson, Brett Flannigan]
commands:
mcoresilenteater:

View File

@ -1,5 +1,6 @@
package com.massivecraft.mcore2.cmd;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@ -12,6 +13,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.massivecraft.mcore2.cmd.arg.AHBoolean;
import com.massivecraft.mcore2.cmd.arg.AHDate;
import com.massivecraft.mcore2.cmd.arg.AHDouble;
import com.massivecraft.mcore2.cmd.arg.AHFloat;
import com.massivecraft.mcore2.cmd.arg.AHInteger;
@ -53,6 +55,7 @@ public class Cmd
{
this.setArgHandler(Boolean.class, new AHBoolean());
this.setArgHandler(Double.class, new AHDouble());
this.setArgHandler(Date.class, new AHDate());
this.setArgHandler(Float.class, new AHFloat());
this.setArgHandler(Integer.class, new AHInteger());
this.setArgHandler(Material.class, new AHMaterial());

View File

@ -0,0 +1,21 @@
package com.massivecraft.mcore2.cmd.arg;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class AHDate extends AHPrimitive<Date>
{
protected static DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
@Override
protected String getPrimitiveName()
{
return "YYYY-MM-DD date";
}
@Override
protected Date unsafeConvert(String str) throws Exception
{
return df.parse(str);
}
}

View File

@ -6,10 +6,10 @@ import java.util.Collection;
import java.util.Map.Entry;
import java.util.logging.Logger;
import org.bukkit.craftbukkit.inventory.CraftInventoryCustom;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.getspout.spoutapi.SpoutManager;
import com.massivecraft.mcore2.lib.gson.JsonDeserializationContext;
import com.massivecraft.mcore2.lib.gson.JsonDeserializer;
@ -82,7 +82,10 @@ public class InventoryTypeAdapter implements JsonDeserializer<Inventory>, JsonSe
itemStacks.add(stack);
}
return SpoutManager.getInventoryBuilder().construct(itemStacks, "");
Inventory ret = new CraftInventoryCustom(null, itemStacks.size(), "items");
ret.setContents(itemStacks.toArray(new ItemStack[0]));
return ret;
}
catch (Exception ex)
{

View File

@ -14,7 +14,9 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.SortedSet;
import java.util.Timer;
import java.util.TreeSet;
import com.massivecraft.mcore2.Predictate;
@ -209,4 +211,29 @@ public class Persist
}
return ret;
}
// http://stackoverflow.com/questions/2864840/treemap-sort-by-value
public static <K,V extends Comparable<? super V>> SortedSet<Map.Entry<K,V>> entriesSortedByValues(Map<K,V> map, final boolean ascending)
{
SortedSet<Map.Entry<K,V>> sortedEntries = new TreeSet<Map.Entry<K,V>>(
new Comparator<Map.Entry<K,V>>()
{
@Override public int compare(Map.Entry<K,V> e1, Map.Entry<K,V> e2)
{
int res;
if (ascending)
{
res = e1.getValue().compareTo(e2.getValue());
}
else
{
res = e2.getValue().compareTo(e1.getValue());
}
return res != 0 ? res : 1;
}
}
);
sortedEntries.addAll(map.entrySet());
return sortedEntries;
}
}