mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2024-08-17 00:47:36 +00:00
Kits timeout are now saved in user data
This commit is contained in:
parent
6224b07215
commit
4edf1ad3f5
|
@ -58,6 +58,7 @@ public abstract class UserData extends PlayerExtension implements IConf
|
||||||
isSocialSpyEnabled = _isSocialSpyEnabled();
|
isSocialSpyEnabled = _isSocialSpyEnabled();
|
||||||
isNPC = _isNPC();
|
isNPC = _isNPC();
|
||||||
arePowerToolsEnabled = _arePowerToolsEnabled();
|
arePowerToolsEnabled = _arePowerToolsEnabled();
|
||||||
|
kitTimestamps = _getKitTimestamps();
|
||||||
}
|
}
|
||||||
private double money;
|
private double money;
|
||||||
|
|
||||||
|
@ -813,4 +814,33 @@ public abstract class UserData extends PlayerExtension implements IConf
|
||||||
return config.getBoolean("powertoolsenabled", true);
|
return config.getBoolean("powertoolsenabled", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Map<String, Object> kitTimestamps;
|
||||||
|
|
||||||
|
private Map<String, Object> _getKitTimestamps()
|
||||||
|
{
|
||||||
|
final Object map = config.getProperty("timestamps.kits");
|
||||||
|
|
||||||
|
if (map instanceof Map)
|
||||||
|
{
|
||||||
|
return (Map<String, Object>)map;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new HashMap<String, Object>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getKitTimestamp(final String name)
|
||||||
|
{
|
||||||
|
final Number num = (Number)kitTimestamps.get(name.toLowerCase());
|
||||||
|
return num == null ? null : num.longValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setKitTimestamp(final String name, final long time)
|
||||||
|
{
|
||||||
|
kitTimestamps.put(name.toLowerCase(), time);
|
||||||
|
config.setProperty("timestamps.kits", kitTimestamps);
|
||||||
|
config.save();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,22 +15,20 @@ import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public class Commandkit extends EssentialsCommand
|
public class Commandkit extends EssentialsCommand
|
||||||
{
|
{
|
||||||
static private final Map<User, Map<String, Long>> kitPlayers = new HashMap<User, Map<String, Long>>();
|
|
||||||
|
|
||||||
public Commandkit()
|
public Commandkit()
|
||||||
{
|
{
|
||||||
super("kit");
|
super("kit");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(Server server, User user, String commandLabel, String[] args) throws Exception
|
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
||||||
{
|
{
|
||||||
if (args.length < 1)
|
if (args.length < 1)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Map<String, Object> kits = ess.getSettings().getKits();
|
final Map<String, Object> kits = ess.getSettings().getKits();
|
||||||
StringBuilder list = new StringBuilder();
|
final StringBuilder list = new StringBuilder();
|
||||||
for (String k : kits.keySet())
|
for (String k : kits.keySet())
|
||||||
{
|
{
|
||||||
if (user.isAuthorized("essentials.kit." + k.toLowerCase()))
|
if (user.isAuthorized("essentials.kit." + k.toLowerCase()))
|
||||||
|
@ -56,8 +54,8 @@ public class Commandkit extends EssentialsCommand
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
String kitName = args[0].toLowerCase();
|
final String kitName = args[0].toLowerCase();
|
||||||
Object kit = ess.getSettings().getKit(kitName);
|
final Object kit = ess.getSettings().getKit(kitName);
|
||||||
List<String> items;
|
List<String> items;
|
||||||
|
|
||||||
if (!user.isAuthorized("essentials.kit." + kitName))
|
if (!user.isAuthorized("essentials.kit." + kitName))
|
||||||
|
@ -70,39 +68,26 @@ public class Commandkit extends EssentialsCommand
|
||||||
{
|
{
|
||||||
|
|
||||||
//System.out.println("Kit is timed");
|
//System.out.println("Kit is timed");
|
||||||
Map<String, Object> els = (Map<String, Object>)kit;
|
final Map<String, Object> els = (Map<String, Object>)kit;
|
||||||
items = (List<String>)els.get("items");
|
items = (List<String>)els.get("items");
|
||||||
double delay = els.containsKey("delay") ? ((Number)els.get("delay")).doubleValue() : 0L;
|
final double delay = els.containsKey("delay") ? ((Number)els.get("delay")).doubleValue() : 0L;
|
||||||
Calendar c = new GregorianCalendar();
|
final Calendar c = new GregorianCalendar();
|
||||||
c.add(Calendar.SECOND, (int)delay);
|
c.add(Calendar.SECOND, -(int)delay);
|
||||||
c.add(Calendar.MILLISECOND, (int)((delay*1000.0)%1000.0));
|
c.add(Calendar.MILLISECOND, -(int)((delay*1000.0)%1000.0));
|
||||||
|
|
||||||
long time = c.getTimeInMillis();
|
final long mintime = c.getTimeInMillis();
|
||||||
Calendar now = new GregorianCalendar();
|
|
||||||
|
|
||||||
Map<String, Long> kitTimes;
|
final Long lastTime = user.getKitTimestamp(kitName);
|
||||||
if (!kitPlayers.containsKey(user))
|
if (lastTime == null || lastTime < mintime) {
|
||||||
{
|
final Calendar now = new GregorianCalendar();
|
||||||
kitTimes = new HashMap<String, Long>();
|
user.setKitTimestamp(kitName, now.getTimeInMillis());
|
||||||
kitTimes.put(kitName, time);
|
} else {
|
||||||
kitPlayers.put(user, kitTimes);
|
final Calendar future = new GregorianCalendar();
|
||||||
}
|
future.setTimeInMillis(lastTime);
|
||||||
else
|
future.add(Calendar.SECOND, (int)delay);
|
||||||
{
|
future.add(Calendar.MILLISECOND, (int)((delay*1000.0)%1000.0));
|
||||||
kitTimes = kitPlayers.get(user);
|
user.sendMessage(Util.format("kitTimed", Util.formatDateDiff(future.getTimeInMillis())));
|
||||||
if (!kitTimes.containsKey(kitName))
|
return;
|
||||||
{
|
|
||||||
kitTimes.put(kitName, time);
|
|
||||||
}
|
|
||||||
else if (kitTimes.get(kitName) < now.getTimeInMillis())
|
|
||||||
{
|
|
||||||
kitTimes.put(kitName, time);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
user.sendMessage(Util.format("kitTimed", Util.formatDateDiff(kitTimes.get(kitName))));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -110,7 +95,7 @@ public class Commandkit extends EssentialsCommand
|
||||||
items = (List<String>)kit;
|
items = (List<String>)kit;
|
||||||
}
|
}
|
||||||
|
|
||||||
Trade charge = new Trade("kit-" + kitName, ess);
|
final Trade charge = new Trade("kit-" + kitName, ess);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
charge.isAffordableFor(user);
|
charge.isAffordableFor(user);
|
||||||
|
@ -124,11 +109,11 @@ public class Commandkit extends EssentialsCommand
|
||||||
boolean spew = false;
|
boolean spew = false;
|
||||||
for (String d : items)
|
for (String d : items)
|
||||||
{
|
{
|
||||||
String[] parts = d.split("[^0-9]+", 3);
|
final String[] parts = d.split("[^0-9]+", 3);
|
||||||
int id = Material.getMaterial(Integer.parseInt(parts[0])).getId();
|
final int id = Material.getMaterial(Integer.parseInt(parts[0])).getId();
|
||||||
int amount = parts.length > 1 ? Integer.parseInt(parts[parts.length > 2 ? 2 : 1]) : 1;
|
final int amount = parts.length > 1 ? Integer.parseInt(parts[parts.length > 2 ? 2 : 1]) : 1;
|
||||||
short data = parts.length > 2 ? Short.parseShort(parts[1]) : 0;
|
final short data = parts.length > 2 ? Short.parseShort(parts[1]) : 0;
|
||||||
HashMap<Integer,ItemStack> overfilled = user.getInventory().addItem(new ItemStack(id, amount, data));
|
final HashMap<Integer,ItemStack> overfilled = user.getInventory().addItem(new ItemStack(id, amount, data));
|
||||||
for (ItemStack itemStack : overfilled.values())
|
for (ItemStack itemStack : overfilled.values())
|
||||||
{
|
{
|
||||||
user.getWorld().dropItemNaturally(user.getLocation(), itemStack);
|
user.getWorld().dropItemNaturally(user.getLocation(), itemStack);
|
||||||
|
|
Loading…
Reference in a new issue