mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +00:00
Wrapped rollback with a Callable to make sure that it executes on the Bukkit thread.
Saw this in a log: java.util.ConcurrentModificationException at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:819) at java.util.ArrayList$Itr.next(ArrayList.java:791) at me.StevenLawson.TotalFreedomMod.TFM_RollbackManager.rollback(TFM_RollbackManager.java:94) at me.StevenLawson.TotalFreedomMod.Commands.Command_gtfo.run(Command_gtfo.java:51)
This commit is contained in:
parent
81ee5f04dd
commit
65ba053aee
@ -6,6 +6,8 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Future;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -84,39 +86,55 @@ public class TFM_RollbackManager
|
||||
|
||||
public static int rollback(final String playerName)
|
||||
{
|
||||
final List<RollbackEntry> entries = getEntriesByPlayer(playerName);
|
||||
if (entries == null)
|
||||
final Future<Integer> future = Bukkit.getScheduler().callSyncMethod(TotalFreedomMod.plugin, new Callable<Integer>()
|
||||
{
|
||||
@Override
|
||||
public Integer call() throws Exception
|
||||
{
|
||||
final List<RollbackEntry> entries = getEntriesByPlayer(playerName);
|
||||
if (entries == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int count = entries.size();
|
||||
for (RollbackEntry entry : entries)
|
||||
{
|
||||
if (entry != null)
|
||||
{
|
||||
entry.restore();
|
||||
}
|
||||
}
|
||||
|
||||
if (!REMOVE_ROLLBACK_HISTORY.contains(playerName.toLowerCase()))
|
||||
{
|
||||
REMOVE_ROLLBACK_HISTORY.add(playerName.toLowerCase());
|
||||
}
|
||||
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (REMOVE_ROLLBACK_HISTORY.contains(playerName.toLowerCase()))
|
||||
{
|
||||
REMOVE_ROLLBACK_HISTORY.remove(playerName.toLowerCase());
|
||||
purgeEntries(playerName);
|
||||
}
|
||||
}
|
||||
}.runTaskLater(TotalFreedomMod.plugin, 20L * 20L);
|
||||
return count;
|
||||
}
|
||||
});
|
||||
|
||||
try
|
||||
{
|
||||
return future.get();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int count = entries.size();
|
||||
for (RollbackEntry entry : entries)
|
||||
{
|
||||
if (entry != null)
|
||||
{
|
||||
entry.restore();
|
||||
}
|
||||
}
|
||||
|
||||
if (!REMOVE_ROLLBACK_HISTORY.contains(playerName.toLowerCase()))
|
||||
{
|
||||
REMOVE_ROLLBACK_HISTORY.add(playerName.toLowerCase());
|
||||
}
|
||||
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (REMOVE_ROLLBACK_HISTORY.contains(playerName.toLowerCase()))
|
||||
{
|
||||
REMOVE_ROLLBACK_HISTORY.remove(playerName.toLowerCase());
|
||||
purgeEntries(playerName);
|
||||
}
|
||||
}
|
||||
}.runTaskLater(TotalFreedomMod.plugin, 20L * 20L);
|
||||
return count;
|
||||
}
|
||||
|
||||
public static int undoRollback(String playerName)
|
||||
|
Loading…
Reference in New Issue
Block a user