mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-14 13:13:24 +00:00
Utilize write transactions for delaylogin task.
This commit is contained in:
parent
cf29a0ba6a
commit
ada2fe01a2
4 changed files with 64 additions and 29 deletions
|
@ -312,6 +312,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials
|
|||
user.setVanished(false);
|
||||
user.sendMessage(tl("unvanishedReload"));
|
||||
}
|
||||
user.stopTransaction();
|
||||
}
|
||||
cleanupOpenInventories();
|
||||
if (i18n != null)
|
||||
|
|
|
@ -15,6 +15,7 @@ import java.util.concurrent.ExecutionException;
|
|||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
@ -35,9 +36,10 @@ public class EssentialsConf extends YamlConfiguration
|
|||
protected final File configFile;
|
||||
protected String templateName = null;
|
||||
protected static final Charset UTF8 = Charset.forName("UTF-8");
|
||||
private Class<?> resourceClass = EssentialsConf.class;
|
||||
private Class<?> resourceClass = EssentialsConf.class;
|
||||
private static final ExecutorService EXECUTOR_SERVICE = Executors.newSingleThreadExecutor();
|
||||
private final AtomicInteger pendingDiskWrites = new AtomicInteger(0);
|
||||
private final AtomicBoolean transaction = new AtomicBoolean(false);
|
||||
|
||||
public EssentialsConf(final File configFile)
|
||||
{
|
||||
|
@ -95,7 +97,7 @@ public class EssentialsConf extends YamlConfiguration
|
|||
LOGGER.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!configFile.exists())
|
||||
{
|
||||
if (legacyFileExists())
|
||||
|
@ -187,22 +189,22 @@ public class EssentialsConf extends YamlConfiguration
|
|||
LOGGER.log(Level.SEVERE, "The file " + configFile.toString() + " is broken, it has been renamed to " + broken.toString(), ex.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean legacyFileExists()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public void convertLegacyFile()
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, "Unable to import legacy config file.");
|
||||
}
|
||||
|
||||
|
||||
public boolean altFileExists()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public void convertAltFile()
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, "Unable to import alt config file.");
|
||||
|
@ -277,6 +279,17 @@ public class EssentialsConf extends YamlConfiguration
|
|||
this.resourceClass = resClass;
|
||||
}
|
||||
|
||||
public void startTransaction()
|
||||
{
|
||||
transaction.set(true);
|
||||
}
|
||||
|
||||
public void stopTransaction()
|
||||
{
|
||||
transaction.set(false);
|
||||
save();
|
||||
}
|
||||
|
||||
public void save()
|
||||
{
|
||||
try
|
||||
|
@ -297,7 +310,10 @@ public class EssentialsConf extends YamlConfiguration
|
|||
@Override
|
||||
public synchronized void save(final File file) throws IOException
|
||||
{
|
||||
delayedSave(file);
|
||||
if (!transaction.get())
|
||||
{
|
||||
delayedSave(file);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void forceSave()
|
||||
|
@ -322,7 +338,6 @@ public class EssentialsConf extends YamlConfiguration
|
|||
|
||||
private Future<?> delayedSave(final File file)
|
||||
{
|
||||
//long startTime = System.nanoTime();
|
||||
if (file == null)
|
||||
{
|
||||
throw new IllegalArgumentException("File cannot be null");
|
||||
|
@ -339,8 +354,6 @@ public class EssentialsConf extends YamlConfiguration
|
|||
|
||||
Future<?> future = EXECUTOR_SERVICE.submit(new WriteRunner(configFile, data, pendingDiskWrites));
|
||||
|
||||
//LOGGER.log(Level.INFO, configFile + " prepared for writing in " + (System.nanoTime() - startTime) + " nsec.");
|
||||
|
||||
return future;
|
||||
}
|
||||
|
||||
|
|
|
@ -220,6 +220,29 @@ public class EssentialsPlayerListener implements Listener
|
|||
dUser.checkMuteTimeout(currentTime);
|
||||
dUser.updateActivity(false);
|
||||
|
||||
IText tempInput = null;
|
||||
|
||||
if (!ess.getSettings().isCommandDisabled("motd"))
|
||||
{
|
||||
try
|
||||
{
|
||||
tempInput = new TextInput(dUser.getSource(), "motd", true, ess);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
if (ess.getSettings().isDebug())
|
||||
{
|
||||
LOGGER.log(Level.WARNING, ex.getMessage(), ex);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGGER.log(Level.WARNING, ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final IText input = tempInput;
|
||||
|
||||
class DelayJoinTask implements Runnable
|
||||
{
|
||||
@Override
|
||||
|
@ -232,6 +255,8 @@ public class EssentialsPlayerListener implements Listener
|
|||
return;
|
||||
}
|
||||
|
||||
user.startTransaction();
|
||||
|
||||
user.setLastAccountName(user.getBase().getName());
|
||||
user.setLastLogin(currentTime);
|
||||
user.setDisplayNick();
|
||||
|
@ -270,26 +295,11 @@ public class EssentialsPlayerListener implements Listener
|
|||
ess.getServer().broadcastMessage(message);
|
||||
}
|
||||
|
||||
if (!ess.getSettings().isCommandDisabled("motd") && user.isAuthorized("essentials.motd"))
|
||||
if (input != null && user.isAuthorized("essentials.motd"))
|
||||
{
|
||||
try
|
||||
{
|
||||
final IText input = new TextInput(user.getSource(), "motd", true, ess);
|
||||
final IText output = new KeywordReplacer(input, user.getSource(), ess);
|
||||
final TextPager pager = new TextPager(output, true);
|
||||
pager.showPage("1", null, "motd", user.getSource());
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
if (ess.getSettings().isDebug())
|
||||
{
|
||||
LOGGER.log(Level.WARNING, ex.getMessage(), ex);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGGER.log(Level.WARNING, ex.getMessage());
|
||||
}
|
||||
}
|
||||
final IText output = new KeywordReplacer(input, user.getSource(), ess);
|
||||
final TextPager pager = new TextPager(output, true);
|
||||
pager.showPage("1", null, "motd", user.getSource());
|
||||
}
|
||||
|
||||
if (!ess.getSettings().isCommandDisabled("mail") && user.isAuthorized("essentials.mail"))
|
||||
|
@ -318,6 +328,7 @@ public class EssentialsPlayerListener implements Listener
|
|||
user.getBase().setFlySpeed(0.1f);
|
||||
user.getBase().setWalkSpeed(0.2f);
|
||||
|
||||
user.stopTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -964,4 +964,14 @@ public abstract class UserData extends PlayerExtension implements IConf
|
|||
{
|
||||
config.save();
|
||||
}
|
||||
|
||||
public void startTransaction()
|
||||
{
|
||||
config.startTransaction();
|
||||
}
|
||||
|
||||
public void stopTransaction()
|
||||
{
|
||||
config.stopTransaction();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue