mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-08-06 04:23:02 +00:00
Speed improvements for Move and Interact Event.
This commit is contained in:
parent
c860b1c668
commit
359ea194b8
5 changed files with 128 additions and 104 deletions
|
@ -282,22 +282,22 @@ public class EssentialsPlayerListener extends PlayerListener
|
||||||
{
|
{
|
||||||
final User user = ess.getUser(event.getPlayer());
|
final User user = ess.getUser(event.getPlayer());
|
||||||
user.updateActivity(true);
|
user.updateActivity(true);
|
||||||
usePowertools(event);
|
if (event.getAnimationType() == PlayerAnimationType.ARM_SWING
|
||||||
|
&& user.hasPowerTools() && user.arePowerToolsEnabled())
|
||||||
|
{
|
||||||
|
usePowertools(user);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void usePowertools(final PlayerAnimationEvent event)
|
private void usePowertools(final User user)
|
||||||
{
|
{
|
||||||
if (event.getAnimationType() != PlayerAnimationType.ARM_SWING)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final User user = ess.getUser(event.getPlayer());
|
|
||||||
final ItemStack is = user.getItemInHand();
|
final ItemStack is = user.getItemInHand();
|
||||||
if (is == null || is.getType() == Material.AIR || !user.arePowerToolsEnabled())
|
int id;
|
||||||
|
if (is == null || (id = is.getTypeId()) == 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final List<String> commandList = user.getPowertool(is);
|
final List<String> commandList = user.getPowertool(id);
|
||||||
if (commandList == null || commandList.isEmpty())
|
if (commandList == null || commandList.isEmpty())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -317,7 +317,7 @@ public class EssentialsPlayerListener extends PlayerListener
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
user.getServer().dispatchCommand(event.getPlayer(), command);
|
user.getServer().dispatchCommand(user.getBase(), command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,15 +23,18 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||||
private transient long lastOnlineActivity;
|
private transient long lastOnlineActivity;
|
||||||
private transient long lastActivity = System.currentTimeMillis();
|
private transient long lastActivity = System.currentTimeMillis();
|
||||||
private boolean hidden = false;
|
private boolean hidden = false;
|
||||||
private transient Location afkPosition;
|
private transient Location afkPosition = null;
|
||||||
private static final Logger logger = Logger.getLogger("Minecraft");
|
private static final Logger logger = Logger.getLogger("Minecraft");
|
||||||
|
|
||||||
User(final Player base, final IEssentials ess)
|
User(final Player base, final IEssentials ess)
|
||||||
{
|
{
|
||||||
super(base, ess);
|
super(base, ess);
|
||||||
teleport = new Teleport(this, ess);
|
teleport = new Teleport(this, ess);
|
||||||
|
if (isAfk())
|
||||||
|
{
|
||||||
afkPosition = getLocation();
|
afkPosition = getLocation();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
User update(final Player base)
|
User update(final Player base)
|
||||||
{
|
{
|
||||||
|
@ -386,6 +389,10 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||||
{
|
{
|
||||||
afkPosition = getLocation();
|
afkPosition = getLocation();
|
||||||
}
|
}
|
||||||
|
else if (!set && isAfk())
|
||||||
|
{
|
||||||
|
afkPosition = null;
|
||||||
|
}
|
||||||
super.setAfk(set);
|
super.setAfk(set);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -265,6 +265,11 @@ public abstract class UserData extends PlayerExtension implements IConf
|
||||||
return (List<String>)powertools.get(stack.getTypeId());
|
return (List<String>)powertools.get(stack.getTypeId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getPowertool(int id)
|
||||||
|
{
|
||||||
|
return (List<String>)powertools.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
public void setPowertool(ItemStack stack, List<String> commandList)
|
public void setPowertool(ItemStack stack, List<String> commandList)
|
||||||
{
|
{
|
||||||
if (commandList == null || commandList.isEmpty())
|
if (commandList == null || commandList.isEmpty())
|
||||||
|
|
|
@ -1,23 +1,20 @@
|
||||||
package com.earth2me.essentials;
|
package com.earth2me.essentials;
|
||||||
|
|
||||||
import com.google.common.cache.Cache;
|
|
||||||
import com.google.common.cache.CacheBuilder;
|
|
||||||
import com.google.common.cache.CacheLoader;
|
|
||||||
import com.google.common.util.concurrent.UncheckedExecutionException;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Collections;
|
import java.lang.ref.SoftReference;
|
||||||
import java.util.Locale;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentSkipListSet;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
|
||||||
public class UserMap extends CacheLoader<String, User> implements IConf
|
public class UserMap implements IConf
|
||||||
{
|
{
|
||||||
private final transient IEssentials ess;
|
private final transient IEssentials ess;
|
||||||
private final transient Cache<String, User> users = CacheBuilder.newBuilder().softValues().build(this);
|
private final transient Map<String, SoftReference<User>> users = new HashMap<String, SoftReference<User>>();
|
||||||
private final transient ConcurrentSkipListSet<String> keys = new ConcurrentSkipListSet<String>();
|
//CacheBuilder.newBuilder().softValues().build(this);
|
||||||
|
//private final transient ConcurrentSkipListSet<String> keys = new ConcurrentSkipListSet<String>();
|
||||||
|
|
||||||
public UserMap(final IEssentials ess)
|
public UserMap(final IEssentials ess)
|
||||||
{
|
{
|
||||||
|
@ -38,8 +35,10 @@ public class UserMap extends CacheLoader<String, User> implements IConf
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
keys.clear();
|
synchronized (users)
|
||||||
users.invalidateAll();
|
{
|
||||||
|
users.clear();
|
||||||
|
|
||||||
for (String string : userdir.list())
|
for (String string : userdir.list())
|
||||||
{
|
{
|
||||||
if (!string.endsWith(".yml"))
|
if (!string.endsWith(".yml"))
|
||||||
|
@ -47,7 +46,8 @@ public class UserMap extends CacheLoader<String, User> implements IConf
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final String name = string.substring(0, string.length() - 4);
|
final String name = string.substring(0, string.length() - 4);
|
||||||
keys.add(Util.sanitizeFileName(name));
|
users.put(Util.sanitizeFileName(name), null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -55,40 +55,43 @@ public class UserMap extends CacheLoader<String, User> implements IConf
|
||||||
|
|
||||||
public boolean userExists(final String name)
|
public boolean userExists(final String name)
|
||||||
{
|
{
|
||||||
return keys.contains(Util.sanitizeFileName(name));
|
return users.containsKey(Util.sanitizeFileName(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
public User getUser(final String name)
|
public User getUser(final String name)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return users.get(Util.sanitizeFileName(name));
|
synchronized (users)
|
||||||
}
|
|
||||||
catch (ExecutionException ex)
|
|
||||||
{
|
{
|
||||||
return null;
|
final SoftReference<User> softRef = users.get(Util.sanitizeFileName(name));
|
||||||
|
User user = softRef == null ? null : softRef.get();
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
user = load(name);
|
||||||
|
users.put(name, new SoftReference<User>(user));
|
||||||
}
|
}
|
||||||
catch (UncheckedExecutionException ex)
|
return user;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public User load(final String name) throws Exception
|
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(Util.sanitizeFileName(name));
|
|
||||||
return new User(player, ess);
|
return new User(player, ess);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final File userFile = getUserFile(name);
|
final File userFile = getUserFile(name);
|
||||||
if (userFile.exists())
|
if (userFile.exists())
|
||||||
{
|
{
|
||||||
keys.add(Util.sanitizeFileName(name));
|
|
||||||
return new User(new OfflinePlayer(name, ess), ess);
|
return new User(new OfflinePlayer(name, ess), ess);
|
||||||
}
|
}
|
||||||
throw new Exception("User not found!");
|
throw new Exception("User not found!");
|
||||||
|
@ -102,18 +105,26 @@ public class UserMap extends CacheLoader<String, User> implements IConf
|
||||||
|
|
||||||
public void removeUser(final String name)
|
public void removeUser(final String name)
|
||||||
{
|
{
|
||||||
keys.remove(Util.sanitizeFileName(name));
|
synchronized (users)
|
||||||
users.invalidate(Util.sanitizeFileName(name));
|
{
|
||||||
|
users.remove(Util.sanitizeFileName(name));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<String> getAllUniqueUsers()
|
public Set<String> getAllUniqueUsers()
|
||||||
{
|
{
|
||||||
return Collections.unmodifiableSet(keys);
|
synchronized (users)
|
||||||
|
{
|
||||||
|
return new HashSet<String>(users.keySet());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getUniqueUsers()
|
public int getUniqueUsers()
|
||||||
{
|
{
|
||||||
return keys.size();
|
synchronized (users)
|
||||||
|
{
|
||||||
|
return users.size();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getUserFile(final String name)
|
public File getUserFile(final String name)
|
||||||
|
|
|
@ -21,10 +21,11 @@ public class Util
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
private final static Logger logger = Logger.getLogger("Minecraft");
|
private final static Logger logger = Logger.getLogger("Minecraft");
|
||||||
|
private final static Pattern INVALIDCHARS = Pattern.compile("[^a-z0-9]");
|
||||||
|
|
||||||
public static String sanitizeFileName(String name)
|
public static String sanitizeFileName(final String name)
|
||||||
{
|
{
|
||||||
return name.toLowerCase(Locale.ENGLISH).replaceAll("[^a-z0-9]", "_");
|
return INVALIDCHARS.matcher(name.toLowerCase(Locale.ENGLISH)).replaceAll("_");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String formatDateDiff(long date)
|
public static String formatDateDiff(long date)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue