2011-03-30 04:03:21 +00:00
|
|
|
package com.earth2me.essentials;
|
|
|
|
|
2011-11-21 01:55:26 +00:00
|
|
|
import static com.earth2me.essentials.I18n._;
|
2011-11-18 17:42:26 +00:00
|
|
|
import java.io.*;
|
2011-03-30 04:03:21 +00:00
|
|
|
import java.util.HashMap;
|
2011-11-27 05:00:58 +00:00
|
|
|
import java.util.List;
|
2011-11-27 05:23:07 +00:00
|
|
|
import java.util.Locale;
|
2011-04-07 02:21:10 +00:00
|
|
|
import java.util.Map;
|
2011-03-30 04:03:21 +00:00
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
2011-04-07 02:21:10 +00:00
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.Server;
|
|
|
|
import org.bukkit.World;
|
2011-11-27 05:00:58 +00:00
|
|
|
import org.bukkit.enchantments.Enchantment;
|
2011-04-07 02:21:10 +00:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
2011-03-30 04:03:21 +00:00
|
|
|
import org.bukkit.util.config.Configuration;
|
|
|
|
|
|
|
|
|
|
|
|
public class EssentialsConf extends Configuration
|
|
|
|
{
|
2011-08-27 13:30:30 +00:00
|
|
|
private static final Logger LOGGER = Logger.getLogger("Minecraft");
|
|
|
|
private transient File configFile;
|
|
|
|
private transient String templateName = null;
|
|
|
|
private transient Class<?> resourceClass = EssentialsConf.class;
|
2011-03-30 04:03:21 +00:00
|
|
|
|
2011-08-27 13:30:30 +00:00
|
|
|
public EssentialsConf(final File configFile)
|
2011-03-30 04:03:21 +00:00
|
|
|
{
|
|
|
|
super(configFile);
|
|
|
|
this.configFile = configFile;
|
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 (this.root == null)
|
|
|
|
{
|
2011-03-30 04:03:21 +00:00
|
|
|
this.root = new HashMap<String, Object>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void load()
|
|
|
|
{
|
|
|
|
configFile = configFile.getAbsoluteFile();
|
|
|
|
if (!configFile.getParentFile().exists())
|
|
|
|
{
|
2011-06-01 10:40:12 +00:00
|
|
|
if (!configFile.getParentFile().mkdirs())
|
|
|
|
{
|
2011-11-21 01:55:26 +00:00
|
|
|
LOGGER.log(Level.SEVERE, _("failedToCreateConfig", configFile.toString()));
|
2011-06-01 10:40:12 +00:00
|
|
|
}
|
2011-03-30 04:03:21 +00:00
|
|
|
}
|
2011-08-27 13:30:30 +00:00
|
|
|
// This will delete files where the first character is 0. In most cases they are broken.
|
|
|
|
if (configFile.exists() && configFile.length() != 0)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
final InputStream input = new FileInputStream(configFile);
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (input.read() == 0)
|
|
|
|
{
|
|
|
|
input.close();
|
|
|
|
configFile.delete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (IOException ex)
|
|
|
|
{
|
|
|
|
LOGGER.log(Level.SEVERE, null, ex);
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
input.close();
|
|
|
|
}
|
|
|
|
catch (IOException ex)
|
|
|
|
{
|
|
|
|
LOGGER.log(Level.SEVERE, null, ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (FileNotFoundException ex)
|
|
|
|
{
|
|
|
|
LOGGER.log(Level.SEVERE, null, ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-30 04:03:21 +00:00
|
|
|
if (!configFile.exists())
|
|
|
|
{
|
|
|
|
if (templateName != null)
|
|
|
|
{
|
2011-11-21 01:55:26 +00:00
|
|
|
LOGGER.log(Level.INFO, _("creatingConfigFromTemplate", configFile.toString()));
|
2011-03-30 04:03:21 +00:00
|
|
|
createFromTemplate();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2011-11-21 01:55:26 +00:00
|
|
|
LOGGER.log(Level.INFO, _("creatingEmptyConfig", configFile.toString()));
|
2011-06-01 10:40:12 +00:00
|
|
|
if (!configFile.createNewFile())
|
|
|
|
{
|
2011-11-21 01:55:26 +00:00
|
|
|
LOGGER.log(Level.SEVERE, _("failedToCreateConfig", configFile.toString()));
|
2011-06-01 10:40:12 +00:00
|
|
|
}
|
2011-03-30 04:03:21 +00:00
|
|
|
}
|
|
|
|
catch (IOException ex)
|
|
|
|
{
|
2011-11-21 01:55:26 +00:00
|
|
|
LOGGER.log(Level.SEVERE, _("failedToCreateConfig", configFile.toString()), ex);
|
2011-03-30 04:03:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-08-27 13:30:30 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2011-08-22 23:28:01 +00:00
|
|
|
super.load();
|
2011-08-27 13:30:30 +00:00
|
|
|
}
|
|
|
|
catch (RuntimeException e)
|
|
|
|
{
|
2011-11-30 19:48:42 +00:00
|
|
|
LOGGER.log(Level.SEVERE, "File broken: " + configFile.toString());
|
2011-08-22 23:28:01 +00:00
|
|
|
throw e;
|
|
|
|
}
|
2011-08-27 13:30:30 +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
|
|
|
if (this.root == null)
|
|
|
|
{
|
2011-03-30 04:03:21 +00:00
|
|
|
this.root = new HashMap<String, Object>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void createFromTemplate()
|
|
|
|
{
|
2011-06-01 10:40:12 +00:00
|
|
|
InputStream istr = null;
|
2011-03-30 04:03:21 +00:00
|
|
|
OutputStream ostr = null;
|
|
|
|
try
|
|
|
|
{
|
2011-06-01 10:40:12 +00:00
|
|
|
istr = resourceClass.getResourceAsStream(templateName);
|
2011-03-30 04:03:21 +00:00
|
|
|
if (istr == null)
|
|
|
|
{
|
2011-11-21 01:55:26 +00:00
|
|
|
LOGGER.log(Level.SEVERE, _("couldNotFindTemplate", templateName));
|
2011-03-30 04:03:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
ostr = new FileOutputStream(configFile);
|
|
|
|
byte[] buffer = new byte[1024];
|
|
|
|
int length = 0;
|
|
|
|
length = istr.read(buffer);
|
|
|
|
while (length > 0)
|
|
|
|
{
|
|
|
|
ostr.write(buffer, 0, length);
|
|
|
|
length = istr.read(buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (IOException ex)
|
|
|
|
{
|
2011-11-21 01:55:26 +00:00
|
|
|
LOGGER.log(Level.SEVERE, _("failedToWriteConfig", configFile.toString()), ex);
|
2011-03-30 04:03:21 +00:00
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
2011-06-01 10:40:12 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
if (istr != null)
|
|
|
|
{
|
|
|
|
istr.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (IOException ex)
|
|
|
|
{
|
|
|
|
Logger.getLogger(EssentialsConf.class.getName()).log(Level.SEVERE, null, ex);
|
|
|
|
}
|
2011-03-30 04:03:21 +00:00
|
|
|
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
|
|
|
if (ostr != null)
|
|
|
|
{
|
2011-03-30 12:56:34 +00:00
|
|
|
ostr.close();
|
|
|
|
}
|
2011-03-30 04:03:21 +00:00
|
|
|
}
|
|
|
|
catch (IOException ex)
|
|
|
|
{
|
2011-11-21 01:55:26 +00:00
|
|
|
LOGGER.log(Level.SEVERE, _("failedToCloseConfig", configFile.toString()), ex);
|
2011-03-30 04:03:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-27 13:30:30 +00:00
|
|
|
public void setTemplateName(final String templateName)
|
2011-03-30 04:03:21 +00:00
|
|
|
{
|
|
|
|
this.templateName = templateName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public File getFile()
|
|
|
|
{
|
|
|
|
return configFile;
|
|
|
|
}
|
|
|
|
|
2011-08-27 13:30:30 +00:00
|
|
|
public void setTemplateName(final String templateName, final Class<?> resClass)
|
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
|
|
|
{
|
2011-03-30 04:03:21 +00:00
|
|
|
this.templateName = templateName;
|
|
|
|
this.resourceClass = resClass;
|
|
|
|
}
|
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
|
|
|
|
2011-08-27 13:30:30 +00:00
|
|
|
public boolean hasProperty(final String path)
|
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
|
|
|
{
|
2011-04-07 02:21:10 +00:00
|
|
|
return getProperty(path) != null;
|
|
|
|
}
|
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
|
|
|
|
2011-08-27 13:30:30 +00:00
|
|
|
public Location getLocation(final String path, final Server server) throws Exception
|
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
|
|
|
{
|
2011-08-27 13:30:30 +00:00
|
|
|
final String worldName = getString((path == null ? "" : path + ".") + "world");
|
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 (worldName == null || worldName.isEmpty())
|
|
|
|
{
|
2011-04-07 02:21:10 +00:00
|
|
|
return null;
|
|
|
|
}
|
2011-08-27 13:30:30 +00:00
|
|
|
final World world = server.getWorld(worldName);
|
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 (world == null)
|
|
|
|
{
|
2011-11-21 01:55:26 +00:00
|
|
|
throw new Exception(_("invalidWorld"));
|
2011-04-07 02:21:10 +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
|
|
|
return new Location(world,
|
2011-08-27 13:30:30 +00:00
|
|
|
getDouble((path == null ? "" : path + ".") + "x", 0),
|
|
|
|
getDouble((path == null ? "" : path + ".") + "y", 0),
|
|
|
|
getDouble((path == null ? "" : path + ".") + "z", 0),
|
|
|
|
(float)getDouble((path == null ? "" : path + ".") + "yaw", 0),
|
|
|
|
(float)getDouble((path == null ? "" : path + ".") + "pitch", 0));
|
2011-04-07 02:21:10 +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
|
|
|
|
2011-08-27 13:30:30 +00:00
|
|
|
public void setProperty(final String path, final Location loc)
|
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
|
|
|
{
|
2011-08-27 13:30:30 +00:00
|
|
|
setProperty((path == null ? "" : path + ".") + "world", loc.getWorld().getName());
|
|
|
|
setProperty((path == null ? "" : path + ".") + "x", loc.getX());
|
|
|
|
setProperty((path == null ? "" : path + ".") + "y", loc.getY());
|
|
|
|
setProperty((path == null ? "" : path + ".") + "z", loc.getZ());
|
|
|
|
setProperty((path == null ? "" : path + ".") + "yaw", loc.getYaw());
|
|
|
|
setProperty((path == null ? "" : path + ".") + "pitch", loc.getPitch());
|
2011-04-07 02:21:10 +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
|
|
|
|
2011-08-27 13:30:30 +00:00
|
|
|
public ItemStack getItemStack(final String path)
|
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
|
|
|
{
|
2011-11-27 05:00:58 +00:00
|
|
|
final ItemStack stack = new ItemStack(
|
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
|
|
|
Material.valueOf(getString(path + ".type", "AIR")),
|
|
|
|
getInt(path + ".amount", 1),
|
2011-11-27 05:00:58 +00:00
|
|
|
(short)getInt(path + ".damage", 0));
|
2011-11-28 23:30:06 +00:00
|
|
|
final List<String> enchants = getKeys(path + ".enchant");
|
|
|
|
if (enchants != null)
|
2011-11-27 05:00:58 +00:00
|
|
|
{
|
2011-11-28 23:30:06 +00:00
|
|
|
for (String enchant : enchants)
|
|
|
|
{
|
|
|
|
final Enchantment enchantment = Enchantment.getByName(enchant.toUpperCase(Locale.ENGLISH));
|
|
|
|
if (enchantment == null)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
final int level = getInt(path + ".enchant." + enchant, enchantment.getStartLevel());
|
|
|
|
stack.addUnsafeEnchantment(enchantment, level);
|
2011-11-27 05:00:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return stack;
|
|
|
|
/*
|
2011-11-28 23:30:06 +00:00
|
|
|
* ,
|
|
|
|
* (byte)getInt(path + ".data", 0)
|
|
|
|
*/
|
2011-04-07 02:21:10 +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
|
|
|
|
2011-08-27 13:30:30 +00:00
|
|
|
public void setProperty(final String path, final ItemStack stack)
|
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
|
|
|
{
|
2011-08-27 13:30:30 +00:00
|
|
|
final Map<String, Object> map = new HashMap<String, Object>();
|
2011-04-07 02:21:10 +00:00
|
|
|
map.put("type", stack.getType().toString());
|
|
|
|
map.put("amount", stack.getAmount());
|
|
|
|
map.put("damage", stack.getDurability());
|
2011-11-27 05:00:58 +00:00
|
|
|
Map<Enchantment, Integer> enchantments = stack.getEnchantments();
|
|
|
|
if (!enchantments.isEmpty())
|
|
|
|
{
|
|
|
|
Map<String, Integer> enchant = new HashMap<String, Integer>();
|
|
|
|
for (Map.Entry<Enchantment, Integer> entry : enchantments.entrySet())
|
|
|
|
{
|
2011-11-27 05:23:07 +00:00
|
|
|
enchant.put(entry.getKey().getName().toLowerCase(Locale.ENGLISH), entry.getValue());
|
2011-11-27 05:00:58 +00:00
|
|
|
}
|
|
|
|
map.put("enchant", enchant);
|
|
|
|
}
|
2011-04-16 14:39:31 +00:00
|
|
|
// getData().getData() is broken
|
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.put("data", stack.getDurability());
|
2011-04-07 02:21:10 +00:00
|
|
|
setProperty(path, map);
|
|
|
|
}
|
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
|
|
|
|
2011-08-27 13:30:30 +00:00
|
|
|
public long getLong(final String path, final long def)
|
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
|
|
|
{
|
2011-05-15 16:26:34 +00:00
|
|
|
try
|
|
|
|
{
|
2011-08-27 13:30:30 +00:00
|
|
|
final Number num = (Number)getProperty(path);
|
|
|
|
return num == null ? def : num.longValue();
|
2011-05-15 16:26:34 +00:00
|
|
|
}
|
2011-08-27 13:30:30 +00:00
|
|
|
catch (ClassCastException ex)
|
2011-05-15 16:26:34 +00:00
|
|
|
{
|
|
|
|
return def;
|
|
|
|
}
|
2011-04-07 02:21:10 +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
|
|
|
|
2011-04-16 17:26:32 +00:00
|
|
|
@Override
|
2011-08-27 13:30:30 +00:00
|
|
|
public double getDouble(final String path, final double def)
|
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
|
|
|
{
|
2011-05-15 16:26:34 +00:00
|
|
|
try
|
|
|
|
{
|
2011-08-27 13:30:30 +00:00
|
|
|
Number num = (Number)getProperty(path);
|
|
|
|
return num == null ? def : num.doubleValue();
|
2011-05-15 16:26:34 +00:00
|
|
|
}
|
2011-08-27 13:30:30 +00:00
|
|
|
catch (ClassCastException ex)
|
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
|
|
|
{
|
2011-04-16 17:26:32 +00:00
|
|
|
return def;
|
|
|
|
}
|
|
|
|
}
|
2011-03-30 04:03:21 +00:00
|
|
|
}
|