mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-02-28 10:12:18 +01:00
Merge branch 'master' of github.com:essentials/Essentials into essmaster
This commit is contained in:
commit
37bd9bc9b5
@ -1,12 +1,17 @@
|
|||||||
package com.earth2me.essentials;
|
package com.earth2me.essentials;
|
||||||
|
|
||||||
|
import java.text.DecimalFormat;
|
||||||
|
import java.text.DecimalFormatSymbols;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
|
||||||
public class ExecuteTimer
|
public class ExecuteTimer
|
||||||
{
|
{
|
||||||
private final List<ExecuteRecord> times;
|
private final transient List<ExecuteRecord> times;
|
||||||
|
private final transient DecimalFormat decimalFormat = new DecimalFormat("#0.000", DecimalFormatSymbols.getInstance(Locale.US));
|
||||||
|
|
||||||
|
|
||||||
public ExecuteTimer()
|
public ExecuteTimer()
|
||||||
{
|
{
|
||||||
@ -24,7 +29,7 @@ public class ExecuteTimer
|
|||||||
{
|
{
|
||||||
if (!times.isEmpty() || "start".equals(label))
|
if (!times.isEmpty() || "start".equals(label))
|
||||||
{
|
{
|
||||||
times.add(new ExecuteRecord(label, System.currentTimeMillis()));
|
times.add(new ExecuteRecord(label, System.nanoTime()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,7 +41,7 @@ public class ExecuteTimer
|
|||||||
long time0 = 0;
|
long time0 = 0;
|
||||||
long time1 = 0;
|
long time1 = 0;
|
||||||
long time2 = 0;
|
long time2 = 0;
|
||||||
long duration;
|
double duration;
|
||||||
|
|
||||||
for (ExecuteRecord pair : times)
|
for (ExecuteRecord pair : times)
|
||||||
{
|
{
|
||||||
@ -44,8 +49,8 @@ public class ExecuteTimer
|
|||||||
time2 = (Long)pair.getTime();
|
time2 = (Long)pair.getTime();
|
||||||
if (time1 > 0)
|
if (time1 > 0)
|
||||||
{
|
{
|
||||||
duration = time2 - time1;
|
duration = (time2 - time1)/1000000.0;
|
||||||
output.append(mark).append(": ").append(duration).append("ms - ");
|
output.append(mark).append(": ").append(decimalFormat.format(duration)).append("ms - ");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -53,8 +58,8 @@ public class ExecuteTimer
|
|||||||
}
|
}
|
||||||
time1 = time2;
|
time1 = time2;
|
||||||
}
|
}
|
||||||
duration = time1 - time0;
|
duration = (time1 - time0)/1000000.0;
|
||||||
output.append("Total: ").append(duration).append("ms");
|
output.append("Total: ").append(decimalFormat.format(duration)).append("ms");
|
||||||
times.clear();
|
times.clear();
|
||||||
return output.toString();
|
return output.toString();
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,27 @@
|
|||||||
package com.earth2me.essentials;
|
package com.earth2me.essentials;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.cache.Cache;
|
||||||
import com.google.common.collect.ComputationException;
|
import com.google.common.cache.CacheBuilder;
|
||||||
import com.google.common.collect.MapMaker;
|
import com.google.common.cache.CacheLoader;
|
||||||
|
import com.google.common.collect.ConcurrentHashMultiset;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
|
||||||
public class UserMap implements Function<String, User>, IConf
|
public class UserMap extends CacheLoader<String, User> implements IConf
|
||||||
{
|
{
|
||||||
private final transient IEssentials ess;
|
private final transient IEssentials ess;
|
||||||
private final transient ConcurrentMap<String, User> users = new MapMaker().softValues().makeComputingMap(this);
|
private final transient Cache<String, User> users = CacheBuilder.newBuilder().softValues().build(this);
|
||||||
|
private final transient ConcurrentHashMultiset<String> keys = ConcurrentHashMultiset.create();
|
||||||
|
|
||||||
public UserMap(final IEssentials ess)
|
public UserMap(final IEssentials ess)
|
||||||
{
|
{
|
||||||
|
super();
|
||||||
this.ess = ess;
|
this.ess = ess;
|
||||||
loadAllUsersAsync(ess);
|
loadAllUsersAsync(ess);
|
||||||
}
|
}
|
||||||
@ -35,6 +38,8 @@ public class UserMap implements Function<String, User>, IConf
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
keys.clear();
|
||||||
|
users.invalidateAll();
|
||||||
for (String string : userdir.list())
|
for (String string : userdir.list())
|
||||||
{
|
{
|
||||||
if (!string.endsWith(".yml"))
|
if (!string.endsWith(".yml"))
|
||||||
@ -42,18 +47,7 @@ public class UserMap implements Function<String, User>, IConf
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final String name = string.substring(0, string.length() - 4);
|
final String name = string.substring(0, string.length() - 4);
|
||||||
try
|
keys.add(name.toLowerCase());
|
||||||
{
|
|
||||||
users.get(name.toLowerCase());
|
|
||||||
}
|
|
||||||
catch (NullPointerException ex)
|
|
||||||
{
|
|
||||||
// Ignore these
|
|
||||||
}
|
|
||||||
catch (ComputationException ex)
|
|
||||||
{
|
|
||||||
Bukkit.getLogger().log(Level.INFO, "Failed to preload user " + name, ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -61,21 +55,29 @@ public class UserMap implements Function<String, User>, IConf
|
|||||||
|
|
||||||
public boolean userExists(final String name)
|
public boolean userExists(final String name)
|
||||||
{
|
{
|
||||||
return users.containsKey(name.toLowerCase());
|
return keys.contains(name.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
public User getUser(final String name) throws NullPointerException
|
public User getUser(final String name) throws NullPointerException
|
||||||
{
|
{
|
||||||
return users.get(name.toLowerCase());
|
try
|
||||||
|
{
|
||||||
|
return users.get(name.toLowerCase());
|
||||||
|
}
|
||||||
|
catch (ExecutionException ex)
|
||||||
|
{
|
||||||
|
throw new NullPointerException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public User apply(final String name)
|
public User load(final String name) throws Exception
|
||||||
{
|
{
|
||||||
for (Player player : ess.getServer().getOnlinePlayers())
|
for (Player player : ess.getServer().getOnlinePlayers())
|
||||||
{
|
{
|
||||||
if (player.getName().equalsIgnoreCase(name))
|
if (player.getName().equalsIgnoreCase(name))
|
||||||
{
|
{
|
||||||
|
keys.add(name.toLowerCase());
|
||||||
return new User(player, ess);
|
return new User(player, ess);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -83,37 +85,43 @@ public class UserMap implements Function<String, User>, IConf
|
|||||||
final File userFile = new File(userFolder, Util.sanitizeFileName(name) + ".yml");
|
final File userFile = new File(userFolder, Util.sanitizeFileName(name) + ".yml");
|
||||||
if (userFile.exists())
|
if (userFile.exists())
|
||||||
{
|
{
|
||||||
|
keys.add(name.toLowerCase());
|
||||||
return new User(new OfflinePlayer(name, ess), ess);
|
return new User(new OfflinePlayer(name, ess), ess);
|
||||||
}
|
}
|
||||||
return null;
|
throw new Exception("User not found!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reloadConfig()
|
public void reloadConfig()
|
||||||
{
|
{
|
||||||
for (User user : users.values())
|
loadAllUsersAsync(ess);
|
||||||
{
|
|
||||||
user.reloadConfig();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeUser(final String name)
|
public void removeUser(final String name)
|
||||||
{
|
{
|
||||||
users.remove(name.toLowerCase());
|
keys.remove(name.toLowerCase());
|
||||||
|
users.invalidate(name.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<User> getAllUsers()
|
public Set<User> getAllUsers()
|
||||||
{
|
{
|
||||||
final Set<User> userSet = new HashSet<User>();
|
final Set<User> userSet = new HashSet<User>();
|
||||||
for (String name : users.keySet())
|
for (String name : keys)
|
||||||
{
|
{
|
||||||
userSet.add(users.get(name));
|
try
|
||||||
|
{
|
||||||
|
userSet.add(users.get(name));
|
||||||
|
}
|
||||||
|
catch (ExecutionException ex)
|
||||||
|
{
|
||||||
|
Bukkit.getLogger().log(Level.INFO, "Failed to load user " + name, ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return userSet;
|
return userSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getUniqueUsers()
|
public int getUniqueUsers()
|
||||||
{
|
{
|
||||||
return users.size();
|
return keys.size();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import quicktime.streaming.Stream;
|
|
||||||
|
|
||||||
|
|
||||||
public class TextInput implements IText
|
public class TextInput implements IText
|
||||||
|
Loading…
Reference in New Issue
Block a user