2011-03-19 22:39:51 +00:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import org.bukkit.Server;
|
|
|
|
import com.earth2me.essentials.Essentials;
|
|
|
|
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;
|
|
|
|
import java.util.GregorianCalendar;
|
2011-03-19 22:39:51 +00:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
|
|
|
|
|
|
|
public class Commandkit extends EssentialsCommand
|
|
|
|
{
|
|
|
|
static private final Map<User, Map<String, Long>> kitPlayers = new HashMap<User, Map<String, Long>>();
|
|
|
|
|
|
|
|
public Commandkit()
|
|
|
|
{
|
|
|
|
super("kit");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
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
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
public void run(Server server, User user, String commandLabel, String[] args) throws Exception
|
2011-03-19 22:39:51 +00:00
|
|
|
{
|
|
|
|
if (args.length < 1)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
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
|
|
|
Map<String, Object> kits = (Map<String, Object>)ess.getConfiguration().getProperty("kits");
|
2011-03-19 22:39:51 +00:00
|
|
|
StringBuilder list = new StringBuilder();
|
|
|
|
for (String k : kits.keySet())
|
|
|
|
{
|
|
|
|
if (user.isAuthorized("essentials.kit." + k))
|
|
|
|
{
|
|
|
|
list.append(" ").append(k);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (list.length() > 0)
|
|
|
|
{
|
|
|
|
user.sendMessage("§7Kits:" + list.toString());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
user.sendMessage("§7There are no kits available yet");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
user.sendMessage("§cThere are no valid kits.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
String kitName = args[0].toLowerCase();
|
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
|
|
|
Object kit = ess.getSettings().getKit(kitName);
|
2011-03-19 22:39:51 +00:00
|
|
|
List<String> items;
|
|
|
|
|
|
|
|
if (!user.isAuthorized("essentials.kit." + kitName))
|
|
|
|
{
|
|
|
|
user.sendMessage("§cYou need the §fessentials.kit." + kitName + "§c permission to use that kit.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
|
2011-04-03 14:53:22 +00:00
|
|
|
//System.out.println("Kit is timed");
|
2011-03-19 22:39:51 +00:00
|
|
|
Map<String, Object> els = (Map<String, Object>)kit;
|
|
|
|
items = (List<String>)els.get("items");
|
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
|
|
|
double delay = els.containsKey("delay") ? ((Number)els.get("delay")).doubleValue() : 0L;
|
|
|
|
Calendar c = new GregorianCalendar();
|
|
|
|
c.add(Calendar.SECOND, (int)delay);
|
|
|
|
c.add(Calendar.MILLISECOND, (int)((delay*1000.0)%1000.0));
|
|
|
|
|
|
|
|
long time = c.getTimeInMillis();
|
|
|
|
Calendar now = new GregorianCalendar();
|
2011-03-19 22:39:51 +00:00
|
|
|
|
|
|
|
Map<String, Long> kitTimes;
|
|
|
|
if (!kitPlayers.containsKey(user))
|
|
|
|
{
|
|
|
|
kitTimes = new HashMap<String, Long>();
|
|
|
|
kitTimes.put(kitName, time);
|
|
|
|
kitPlayers.put(user, kitTimes);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
kitTimes = kitPlayers.get(user);
|
|
|
|
if (!kitTimes.containsKey(kitName))
|
|
|
|
{
|
|
|
|
kitTimes.put(kitName, time);
|
|
|
|
}
|
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
|
|
|
else if (kitTimes.get(kitName) < now.getTimeInMillis())
|
2011-03-19 22:39:51 +00:00
|
|
|
{
|
|
|
|
kitTimes.put(kitName, time);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
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.sendMessage("§cYou can't use that kit again for another " + Util.formatDateDiff(kitTimes.get(kitName)) + ".");
|
2011-03-19 22:39:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
items = (List<String>)kit;
|
|
|
|
}
|
|
|
|
|
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-03-19 22:39:51 +00:00
|
|
|
user.canAfford("kit-" + kitName);
|
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)
|
|
|
|
{
|
|
|
|
String[] parts = d.split("[^0-9]+", 3);
|
|
|
|
int id = Integer.parseInt(parts[0]);
|
|
|
|
int amount = parts.length > 1 ? Integer.parseInt(parts[parts.length > 2 ? 2 : 1]) : 1;
|
|
|
|
short data = parts.length > 2 ? Short.parseShort(parts[1]) : 0;
|
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
|
|
|
HashMap<Integer,ItemStack> overfilled = user.getInventory().addItem(new ItemStack(id, amount, data));
|
|
|
|
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
|
|
|
{
|
|
|
|
user.sendMessage("§7Your inventory was full, placing kit on the floor");
|
|
|
|
}
|
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-03-19 22:39:51 +00:00
|
|
|
user.charge(this);
|
|
|
|
user.charge("kit-" + kitName);
|
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());
|
|
|
|
}
|
|
|
|
user.sendMessage("§7Giving kit " + args[0].toLowerCase() + ".");
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
user.sendMessage("§cThat kit does not exist or is improperly defined.");
|
|
|
|
user.sendMessage("§cPerhaps an item is missing a quantity in the configuration?");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|