2011-03-19 22:39:51 +00:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
2011-12-06 16:42:55 +00:00
|
|
|
import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
|
2011-11-21 01:55:26 +00:00
|
|
|
import static com.earth2me.essentials.I18n._;
|
2011-06-13 13:05:11 +00:00
|
|
|
import com.earth2me.essentials.Trade;
|
2011-03-19 22:39:51 +00:00
|
|
|
import com.earth2me.essentials.User;
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
import com.earth2me.essentials.Util;
|
2011-11-18 17:42:26 +00:00
|
|
|
import java.util.*;
|
2011-08-27 15:01:01 +00:00
|
|
|
import org.bukkit.Material;
|
2011-11-18 17:42:26 +00:00
|
|
|
import org.bukkit.Server;
|
2011-03-19 22:39:51 +00:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
|
|
|
|
|
|
|
public class Commandkit extends EssentialsCommand
|
|
|
|
{
|
|
|
|
public Commandkit()
|
|
|
|
{
|
|
|
|
super("kit");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-09-29 22:53:25 +00:00
|
|
|
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
2011-03-19 22:39:51 +00:00
|
|
|
{
|
|
|
|
if (args.length < 1)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2011-09-29 22:53:25 +00:00
|
|
|
final Map<String, Object> kits = ess.getSettings().getKits();
|
|
|
|
final StringBuilder list = new StringBuilder();
|
2011-11-18 13:48:31 +00:00
|
|
|
for (String kiteItem : kits.keySet())
|
2011-03-19 22:39:51 +00:00
|
|
|
{
|
2011-11-21 01:55:26 +00:00
|
|
|
if (user.isAuthorized("essentials.kit." + kiteItem.toLowerCase(Locale.ENGLISH)))
|
2011-03-19 22:39:51 +00:00
|
|
|
{
|
2011-11-18 13:48:31 +00:00
|
|
|
list.append(" ").append(kiteItem);
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (list.length() > 0)
|
|
|
|
{
|
2011-11-21 01:55:26 +00:00
|
|
|
user.sendMessage(_("kits", list.toString()));
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-11-21 01:55:26 +00:00
|
|
|
user.sendMessage(_("noKits"));
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2011-11-21 01:55:26 +00:00
|
|
|
user.sendMessage(_("kitError"));
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2011-11-21 01:55:26 +00:00
|
|
|
final String kitName = args[0].toLowerCase(Locale.ENGLISH);
|
2011-09-29 22:53:25 +00:00
|
|
|
final Object kit = ess.getSettings().getKit(kitName);
|
2011-03-19 22:39:51 +00:00
|
|
|
List<String> items;
|
|
|
|
|
|
|
|
if (!user.isAuthorized("essentials.kit." + kitName))
|
|
|
|
{
|
2011-11-21 01:55:26 +00:00
|
|
|
user.sendMessage(_("noKitPermission", "essentials.kit." + kitName));
|
2011-03-19 22:39:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
|
2011-04-03 14:53:22 +00:00
|
|
|
//System.out.println("Kit is timed");
|
2011-09-29 22:53:25 +00:00
|
|
|
final Map<String, Object> els = (Map<String, Object>)kit;
|
2011-03-19 22:39:51 +00:00
|
|
|
items = (List<String>)els.get("items");
|
2011-09-29 22:53:25 +00:00
|
|
|
final double delay = els.containsKey("delay") ? ((Number)els.get("delay")).doubleValue() : 0L;
|
|
|
|
final Calendar c = new GregorianCalendar();
|
|
|
|
c.add(Calendar.SECOND, -(int)delay);
|
2011-11-21 01:55:26 +00:00
|
|
|
c.add(Calendar.MILLISECOND, -(int)((delay * 1000.0) % 1000.0));
|
2011-11-18 13:48:31 +00:00
|
|
|
|
2011-09-29 22:53:25 +00:00
|
|
|
final long mintime = c.getTimeInMillis();
|
2011-11-18 13:48:31 +00:00
|
|
|
|
2011-09-29 22:53:25 +00:00
|
|
|
final Long lastTime = user.getKitTimestamp(kitName);
|
2011-11-21 01:55:26 +00:00
|
|
|
if (lastTime == null || lastTime < mintime)
|
|
|
|
{
|
2011-09-29 22:53:25 +00:00
|
|
|
final Calendar now = new GregorianCalendar();
|
|
|
|
user.setKitTimestamp(kitName, now.getTimeInMillis());
|
2011-11-21 01:55:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-29 22:53:25 +00:00
|
|
|
final Calendar future = new GregorianCalendar();
|
|
|
|
future.setTimeInMillis(lastTime);
|
|
|
|
future.add(Calendar.SECOND, (int)delay);
|
2011-11-21 01:55:26 +00:00
|
|
|
future.add(Calendar.MILLISECOND, (int)((delay * 1000.0) % 1000.0));
|
|
|
|
user.sendMessage(_("kitTimed", Util.formatDateDiff(future.getTimeInMillis())));
|
2011-09-29 22:53:25 +00:00
|
|
|
return;
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
items = (List<String>)kit;
|
|
|
|
}
|
|
|
|
|
2011-09-29 22:53:25 +00:00
|
|
|
final Trade charge = new Trade("kit-" + kitName, ess);
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
try
|
|
|
|
{
|
2011-05-22 18:53:23 +00:00
|
|
|
charge.isAffordableFor(user);
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2011-03-19 22:39:51 +00:00
|
|
|
user.sendMessage(ex.getMessage());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean spew = false;
|
|
|
|
for (String d : items)
|
|
|
|
{
|
2011-09-29 22:53:25 +00:00
|
|
|
final String[] parts = d.split("[^0-9]+", 3);
|
|
|
|
final int id = Material.getMaterial(Integer.parseInt(parts[0])).getId();
|
|
|
|
final int amount = parts.length > 1 ? Integer.parseInt(parts[parts.length > 2 ? 2 : 1]) : 1;
|
|
|
|
final short data = parts.length > 2 ? Short.parseShort(parts[1]) : 0;
|
2011-12-04 21:33:49 +00:00
|
|
|
final Map<Integer, ItemStack> overfilled;
|
|
|
|
if (user.isAuthorized("essentials.oversizedstacks"))
|
|
|
|
{
|
|
|
|
overfilled = InventoryWorkaround.addItem(user.getInventory(), true, ess.getSettings().getOversizedStackSize(), new ItemStack(id, amount, data));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
overfilled = InventoryWorkaround.addItem(user.getInventory(), true, new ItemStack(id, amount, data));
|
|
|
|
}
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
for (ItemStack itemStack : overfilled.values())
|
2011-03-19 22:39:51 +00:00
|
|
|
{
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
user.getWorld().dropItemNaturally(user.getLocation(), itemStack);
|
2011-03-19 22:39:51 +00:00
|
|
|
spew = true;
|
|
|
|
}
|
|
|
|
}
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
if (spew)
|
2011-03-19 22:39:51 +00:00
|
|
|
{
|
2011-11-21 01:55:26 +00:00
|
|
|
user.sendMessage(_("kitInvFull"));
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
try
|
|
|
|
{
|
2011-05-22 18:53:23 +00:00
|
|
|
charge.charge(user);
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2011-03-19 22:39:51 +00:00
|
|
|
user.sendMessage(ex.getMessage());
|
|
|
|
}
|
2011-11-21 01:55:26 +00:00
|
|
|
user.sendMessage(_("kitGive", kitName));
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2011-11-21 01:55:26 +00:00
|
|
|
user.sendMessage(_("kitError2"));
|
|
|
|
user.sendMessage(_("kitErrorHelp"));
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|