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
|
|
|
package com.earth2me.essentials;
|
|
|
|
|
2013-07-13 15:14:39 +00:00
|
|
|
import net.ess3.api.IEssentials;
|
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 java.util.HashSet;
|
2011-08-08 12:40:30 +00:00
|
|
|
import java.util.Iterator;
|
2012-05-17 10:33:40 +00:00
|
|
|
import java.util.LinkedList;
|
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 java.util.Set;
|
2012-02-02 09:26:36 +00:00
|
|
|
import java.util.logging.Level;
|
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 org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
|
2011-08-08 12:40:30 +00:00
|
|
|
public class EssentialsTimer implements Runnable
|
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-08 12:40:30 +00:00
|
|
|
private final transient IEssentials ess;
|
2013-05-02 23:15:02 +00:00
|
|
|
private final transient Set<String> onlineUsers = new HashSet<String>();
|
2013-04-23 05:51:25 +00:00
|
|
|
private transient long lastPoll = System.nanoTime();
|
|
|
|
private final LinkedList<Double> history = new LinkedList<Double>();
|
2013-04-21 22:39:50 +00:00
|
|
|
private int skip1 = 0;
|
|
|
|
private int skip2 = 0;
|
2013-04-21 22:23:21 +00:00
|
|
|
private final long maxTime = 10 * 1000000;
|
2013-04-23 05:51:25 +00:00
|
|
|
private final long tickInterval = 50;
|
2013-05-18 20:42:02 +00:00
|
|
|
|
2011-08-08 12:40:30 +00:00
|
|
|
EssentialsTimer(final IEssentials 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
|
|
|
{
|
2011-06-01 10:40:12 +00:00
|
|
|
this.ess = ess;
|
2013-05-18 20:42:02 +00:00
|
|
|
history.add(20d);
|
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
|
|
|
}
|
2013-05-18 20:42:02 +00:00
|
|
|
|
2011-08-08 12:40:30 +00:00
|
|
|
@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
|
|
|
public void run()
|
|
|
|
{
|
2013-04-21 22:23:21 +00:00
|
|
|
final long startTime = System.nanoTime();
|
2013-04-23 05:55:02 +00:00
|
|
|
final long currentTime = System.currentTimeMillis();
|
2013-04-23 05:51:25 +00:00
|
|
|
long timeSpent = (startTime - lastPoll) / 1000;
|
2012-05-17 10:33:40 +00:00
|
|
|
if (timeSpent == 0)
|
|
|
|
{
|
|
|
|
timeSpent = 1;
|
|
|
|
}
|
|
|
|
if (history.size() > 10)
|
|
|
|
{
|
|
|
|
history.remove();
|
|
|
|
}
|
2013-04-23 05:51:25 +00:00
|
|
|
double tps = tickInterval * 1000000.0 / timeSpent;
|
2013-05-18 20:42:02 +00:00
|
|
|
if (tps <= 21)
|
2012-05-17 10:33:40 +00:00
|
|
|
{
|
|
|
|
history.add(tps);
|
|
|
|
}
|
2013-04-23 05:55:02 +00:00
|
|
|
lastPoll = startTime;
|
2013-04-21 22:23:21 +00:00
|
|
|
int count = 0;
|
2011-06-01 10:40:12 +00:00
|
|
|
for (Player player : ess.getServer().getOnlinePlayers())
|
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
|
|
|
{
|
2013-04-21 22:23:21 +00:00
|
|
|
count++;
|
|
|
|
if (skip1 > 0)
|
|
|
|
{
|
|
|
|
skip1--;
|
|
|
|
continue;
|
|
|
|
}
|
2013-04-21 23:11:13 +00:00
|
|
|
if (count % 10 == 0)
|
|
|
|
{
|
|
|
|
if (System.nanoTime() - startTime > maxTime / 2)
|
|
|
|
{
|
2013-04-21 22:23:21 +00:00
|
|
|
skip1 = count - 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-02-02 09:26:36 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
final User user = ess.getUser(player);
|
2013-05-02 23:15:02 +00:00
|
|
|
onlineUsers.add(user.getName());
|
2012-02-02 09:26:36 +00:00
|
|
|
user.setLastOnlineActivity(currentTime);
|
|
|
|
user.checkActivity();
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
ess.getLogger().log(Level.WARNING, "EssentialsTimer Error:", e);
|
|
|
|
}
|
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
|
|
|
}
|
2013-05-18 20:42:02 +00:00
|
|
|
|
2013-04-21 22:23:21 +00:00
|
|
|
count = 0;
|
2013-05-02 23:15:02 +00:00
|
|
|
final Iterator<String> iterator = onlineUsers.iterator();
|
2011-08-08 12:40:30 +00:00
|
|
|
while (iterator.hasNext())
|
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
|
|
|
{
|
2013-04-21 22:23:21 +00:00
|
|
|
count++;
|
|
|
|
if (skip2 > 0)
|
|
|
|
{
|
|
|
|
skip2--;
|
|
|
|
continue;
|
|
|
|
}
|
2013-04-21 23:11:13 +00:00
|
|
|
if (count % 10 == 0)
|
|
|
|
{
|
|
|
|
if (System.nanoTime() - startTime > maxTime)
|
|
|
|
{
|
2013-04-21 22:23:21 +00:00
|
|
|
skip2 = count - 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-05-02 23:15:02 +00:00
|
|
|
final User user = ess.getUser(iterator.next());
|
2011-08-27 11:59:39 +00:00
|
|
|
if (user.getLastOnlineActivity() < currentTime && user.getLastOnlineActivity() > user.getLastLogout())
|
2011-08-08 12:40:30 +00:00
|
|
|
{
|
2013-06-02 16:45:56 +00:00
|
|
|
if (!user.isHidden()) {
|
|
|
|
user.setLastLogout(user.getLastOnlineActivity());
|
|
|
|
}
|
2011-08-08 12:40:30 +00:00
|
|
|
iterator.remove();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
user.checkMuteTimeout(currentTime);
|
|
|
|
user.checkJailTimeout(currentTime);
|
2012-03-27 19:14:38 +00:00
|
|
|
user.resetInvulnerabilityAfterTeleport();
|
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
|
|
|
}
|
|
|
|
}
|
2013-05-18 20:42:02 +00:00
|
|
|
|
2013-04-23 05:51:25 +00:00
|
|
|
public double getAverageTPS()
|
2012-05-17 10:33:40 +00:00
|
|
|
{
|
2013-04-23 05:51:25 +00:00
|
|
|
double avg = 0;
|
|
|
|
for (Double f : history)
|
2012-05-17 10:33:40 +00:00
|
|
|
{
|
|
|
|
if (f != null)
|
|
|
|
{
|
|
|
|
avg += f;
|
|
|
|
}
|
2013-05-18 20:42:02 +00:00
|
|
|
}
|
2012-05-17 10:33:40 +00:00
|
|
|
return avg / history.size();
|
|
|
|
}
|
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
|
|
|
}
|