Use multimap in scheduler
This commit is contained in:
parent
b91564f77a
commit
779582d441
@ -1,6 +1,10 @@
|
||||
package net.md_5.bungee.scheduler;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Multimaps;
|
||||
import gnu.trove.TCollections;
|
||||
import gnu.trove.map.TIntObjectMap;
|
||||
import gnu.trove.map.hash.TIntObjectHashMap;
|
||||
@ -18,11 +22,13 @@ public class BungeeScheduler implements TaskScheduler
|
||||
|
||||
private final AtomicInteger taskCounter = new AtomicInteger();
|
||||
private final TIntObjectMap<BungeeTask> tasks = TCollections.synchronizedMap( new TIntObjectHashMap<BungeeTask>() );
|
||||
private final Multimap<Plugin, BungeeTask> tasksByPlugin = Multimaps.synchronizedMultimap( HashMultimap.<Plugin, BungeeTask>create() );
|
||||
|
||||
@Override
|
||||
public void cancel(int id)
|
||||
{
|
||||
BungeeTask task = tasks.remove( id );
|
||||
tasksByPlugin.values().remove( task );
|
||||
task.getFuture().cancel( false );
|
||||
}
|
||||
|
||||
@ -36,14 +42,10 @@ public class BungeeScheduler implements TaskScheduler
|
||||
public int cancel(Plugin plugin)
|
||||
{
|
||||
Set<ScheduledTask> toRemove = new HashSet<>();
|
||||
for ( ScheduledTask task : tasks.valueCollection() )
|
||||
{
|
||||
// TODO: proper checking?
|
||||
if ( task.getOwner() == plugin )
|
||||
for ( ScheduledTask task : tasksByPlugin.get( plugin ) )
|
||||
{
|
||||
toRemove.add( task );
|
||||
}
|
||||
}
|
||||
for ( ScheduledTask task : toRemove )
|
||||
{
|
||||
cancel( task );
|
||||
|
Loading…
Reference in New Issue
Block a user